Beispiel #1
0
        public LuaStatement Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            reader.VerifyExpectedTokenAndMoveNext(Keywords.Return);
            var returnedExpression = SyntaxParser.ReadExpression(reader, context);

            return(new ReturnStatement(returnedExpression));
        }
Beispiel #2
0
        internal static LuaExpression ParseExpression(string expressionString)
        {
            var tokensStream = Tokenizer.Parse(new StringReader(expressionString));

            tokensStream.MoveNext();
            var context = new ParserContext(new Scope());

            return(SyntaxParser.ReadExpression(tokensStream, context));
        }
        public virtual LuaExpression Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            var leftExpression = SyntaxParser.ReadExpression(reader, context);
            var operation      = reader.Current.Value;

            reader.VerifyExpectedTokenAndMoveNext(LuaToken.BinaryOperations);
            var rightExpression = SyntaxParser.ReadExpression(reader, context);

            return(new BinaryExpression(leftExpression, rightExpression, operation));
        }
        public LuaExpression Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            reader.VerifyExpectedToken(LuaToken.LeftBracket);
            reader.MoveNext();
            var expression = SyntaxParser.ReadExpression(reader, context);

            reader.VerifyExpectedToken(LuaToken.RightBracket);
            reader.MoveNext();
            return(new BracketedExpression(expression));
        }
        public LuaStatement Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            reader.VerifyExpectedTokenAndMoveNext(Keywords.While);
            var conditionExpression = SyntaxParser.ReadExpression(reader, context);

            reader.VerifyExpectedTokenAndMoveNext(Keywords.Do);
            var blockParser = new StatementBlockParser(Keywords.End);
            var bodyBlock   = blockParser.ParseBlock(reader, context);

            return(new WhileStatement(conditionExpression, bodyBlock));
        }
Beispiel #6
0
        public IEnumerable <LuaExpression> Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            var expressions = new List <LuaExpression>();

            do
            {
                if (reader.Current.Value == LuaToken.RightBracket)
                {
                    break;
                }
                expressions.Add(SyntaxParser.ReadExpression(reader, context));
            } while (reader.Current.Value == LuaToken.Comma && reader.MoveNext());
            return(expressions);
        }
        public LuaStatement Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            StatementBlock elseBlock = null;

            reader.VerifyExpectedTokenAndMoveNext(Keywords.If);
            var conditionExpression = SyntaxParser.ReadExpression(reader, context);

            reader.VerifyExpectedTokenAndMoveNext(Keywords.Then);

            var   ifBlockParser = new StatementBlockParser(Keywords.End, Keywords.Else);
            Token delimiterToken;
            var   ifBlock = ifBlockParser.ParseBlock(reader, context, out delimiterToken);

            if (delimiterToken.Value == Keywords.Else)
            {
                var elseBlockParser = new StatementBlockParser(Keywords.End);
                elseBlock = elseBlockParser.ParseBlock(reader, context);
            }
            return(new IfStatement(conditionExpression, ifBlock, elseBlock));
        }
Beispiel #8
0
        public LuaExpression Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            var           tableName = reader.Current.Value;
            LuaExpression indexerExpression;

            reader.MoveNext();
            if (reader.Current.Value == LuaToken.Dot)
            {
                reader.MoveNext();
                indexerExpression = new StringConstantExpression(reader.Current.Value);
            }
            else if (reader.Current.Value == LuaToken.LeftSquareBracket)
            {
                reader.MoveNext();
                indexerExpression = SyntaxParser.ReadExpression(reader, context);
                reader.VerifyExpectedTokenAndMoveNext(LuaToken.RightSquareBracket);
            }
            else
            {
                throw new UnexpectedTokenException(reader.Current, LuaToken.Dot, LuaToken.LeftSquareBracket);
            }
            return(new TableIndexExpression(new Variable(tableName), indexerExpression));
        }