Expression ReadString() { Token start = Consume(TokenKind.StringStart); StringExpression exp = new StringExpression(start.Line, start.Col); while (true) { Token tok = Current; if (tok.TokenKind == TokenKind.StringEnd) { Consume(); break; } else if (tok.TokenKind == TokenKind.EOF) { throw new ParseException("Unexpected end of file", tok.Line, tok.Col); } else if (tok.TokenKind == TokenKind.StringText) { Consume(); exp.Add(new StringLiteral(tok.Line, tok.Col, tok.Data)); } else if (tok.TokenKind == TokenKind.ExpStart) { exp.Add(ReadExpression()); } else { throw new ParseException("Unexpected token in string: " + tok.TokenKind, tok.Line, tok.Col); } } if (exp.ExpCount == 1) { return(exp[0]); } else { return(exp); } }
private Expression _ReadString() { Token start = _Consume(TokenKind.StringStart); StringExpression exp = new StringExpression(start.Line, start.Col); while (true) { Token tok = Current; if (tok.TokenKind == TokenKind.StringEnd) { _Consume(); break; } else if (tok.TokenKind == TokenKind.EOF) { throw new ParseException("文档意外终止。", tok.Line, tok.Col); } else if (tok.TokenKind == TokenKind.StringText) { _Consume(); exp.Add(new StringLiteral(tok.Line, tok.Col, tok.Data)); } else if (tok.TokenKind == TokenKind.ExpStart) { exp.Add(_ReadExpression()); } else { throw new ParseException("意外的 Token 字符串:" + tok.TokenKind, tok.Line, tok.Col); } } if (exp.ExpCount == 1) { return(exp[0]); } else { return(exp); } }
Expression ReadString() { Token start = Consume(TokenKind.StringStart); StringExpression exp = new StringExpression(start.Line, start.Col); while (true) { Token tok = Current; if (tok.TokenKind == TokenKind.StringEnd) { Consume(); break; } else if (tok.TokenKind == TokenKind.EOF) throw new ParseException("Unexpected end of file", tok.Line, tok.Col); else if (tok.TokenKind == TokenKind.StringText) { Consume(); exp.Add(new StringLiteral(tok.Line, tok.Col, tok.Data)); } else if (tok.TokenKind == TokenKind.ExpStart) exp.Add(ReadExpression()); else throw new ParseException("Unexpected token in string: " + tok.TokenKind, tok.Line, tok.Col); } if (exp.ExpCount == 1) return exp[0]; else return exp; }