Exemple #1
0
        private Expression ReadString()
        {
            Token start = Consume(TokenKind.StringStart);
            StringExpression exp = new StringExpression(start.Line, start.Column);

            while (true) {
                Token tok = Current;

                if (tok.Kind == TokenKind.StringEnd) {
                    Consume();
                    break;
                }
                if (tok.Kind == TokenKind.EOF)
                    throw new ParseException("Unexpected end of file", tok.Line, tok.Column);

                if (tok.Kind == TokenKind.StringText) {
                    Consume();
                    exp.AddExpression(new StringLiteralExpression(tok.Line, tok.Column, tok.Text));
                } else if (tok.Kind == TokenKind.ExpStart)
                    exp.AddExpression(ReadExpression());
                else
                    throw new ParseException("Unexpected token in string: " + tok.Kind, tok.Line, tok.Column);
            }

            return exp.Count == 1 ? exp[0] : exp;
        }