public IList<Token> Parse(string lines)
{
line = 1;
List<Token> ts = new List<Token>();
int n = 0;
while (n >= 0)
{
Token t;
t.line = this.line;
int nstart = FindStart(lines, n);
t.line = this.line;
int nend = GetToken(lines, nstart, out t);
if (nend >= 0)
{
for (int i = nstart; i < nend; i++)
{
if (lines[i] == '\n')
line++;
}
}
n = nend;
if (n >= 0)
{
if (ts.Count >= 2 && t.type == TokenType.IDENTIFIER && ts[ts.Count - 1].text == "." && ts[ts.Count - 2].type == TokenType.TYPE)
{
string ntype = ts[ts.Count - 2].text + ts[ts.Count - 1].text + t.text;
if (types.Contains(ntype))
{//类中类,合并之
t.type = TokenType.TYPE;
t.text = ntype;
t.pos = ts[ts.Count - 2].pos;
t.line = ts[ts.Count - 2].line;
ts.RemoveAt(ts.Count - 1);
ts.RemoveAt(ts.Count - 1);
ts.Add(t);
continue;
}
}
if (ts.Count >= 3 && t.type == TokenType.PUNCTUATION && t.text == ">"
&& ts[ts.Count - 1].type == TokenType.TYPE
&& ts[ts.Count - 2].type == TokenType.PUNCTUATION && ts[ts.Count - 2].text == "<"
&& ts[ts.Count - 3].type == TokenType.IDENTIFIER)
{//模板函数调用,合并之
string ntype = ts[ts.Count - 3].text + ts[ts.Count - 2].text + ts[ts.Count - 1].text + t.text;
t.type = TokenType.IDENTIFIER;
t.text = ntype;
t.pos = ts[ts.Count - 2].pos;
t.line = ts[ts.Count - 2].line;
ts.RemoveAt(ts.Count - 1);
ts.RemoveAt(ts.Count - 1);
ts.RemoveAt(ts.Count - 1);
ts.Add(t);
continue;
}
if (ts.Count >= 2 && t.type == TokenType.TYPE && ts[ts.Count - 1].text == "." && (ts[ts.Count - 2].type == TokenType.TYPE || ts[ts.Count - 2].type == TokenType.IDENTIFIER))
{//Type.Type IDENTIFIER.Type 均不可能,为重名
t.type = TokenType.IDENTIFIER;
ts.Add(t);
continue;
}
if (ts.Count >= 1 && t.type == TokenType.TYPE && ts[ts.Count - 1].type == TokenType.TYPE)
{//Type Type 不可能,为重名
t.type = TokenType.IDENTIFIER;
ts.Add(t);
continue;
}
ts.Add(t);
}
}
return ts;
}