public override LuaStatement Parse(INextAwareEnumerator<Token> reader, IParserContext context)
        {
            reader.VerifyExpectedTokenAndMoveNext(Keywords.Function);
            if (reader.Next.Value == LuaToken.Colon)
            {
                reader.MoveNext();
                reader.MoveNext();
            }
            var functionName = reader.GetAndMoveNext();
            reader.VerifyExpectedToken(LuaToken.LeftBracket);

            var argumentNames = new List<string>();
            reader.MoveNext();
            while (reader.Current.Value != LuaToken.RightBracket)
            {
                argumentNames.Add(reader.Current.Value);
                reader.MoveNext();
                reader.VerifyExpectedToken(LuaToken.Comma, LuaToken.RightBracket);
                if (reader.Current.Value == LuaToken.RightBracket)
                    break;
                reader.MoveNext();
            }
            reader.VerifyExpectedTokenAndMoveNext(LuaToken.RightBracket);
            var statementsParser = new StatementBlockParser(Keywords.End);
            var body = statementsParser.ParseBlock(reader, context);

            return new FunctionDeclarationStatement(functionName.Value,argumentNames,body);
        }
        public LuaStatement Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            reader.VerifyExpectedTokenAndMoveNext(Keywords.Function);
            if (reader.Next.Value == LuaToken.Colon)
            {
                reader.MoveNext();
                reader.MoveNext();
            }
            var functionName = reader.GetAndMoveNext();

            reader.VerifyExpectedToken(LuaToken.LeftBracket);

            var argumentNames = new List <string>();

            reader.MoveNext();
            while (reader.Current.Value != LuaToken.RightBracket)
            {
                argumentNames.Add(reader.Current.Value);
                reader.MoveNext();
                reader.VerifyExpectedToken(LuaToken.Comma, LuaToken.RightBracket);
                if (reader.Current.Value == LuaToken.RightBracket)
                {
                    break;
                }
                reader.MoveNext();
            }
            reader.VerifyExpectedTokenAndMoveNext(LuaToken.RightBracket);
            var statementsParser = new StatementBlockParser(Keywords.End);
            var body             = statementsParser.ParseBlock(reader, context);

            return(new FunctionDeclarationStatement(functionName.Value, argumentNames, body));
        }
 public override 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);
 }
        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));
        }
Esempio n. 5
0
        public override LuaStatement Parse(INextAwareEnumerator<Token> reader, IParserContext context)
        {
            reader.VerifyExpectedTokenAndMoveNext(Keywords.For);
            var scope = context.AcquireScope();
            reader.VerifyIsIdentifier();
            var forVariableName = reader.GetAndMoveNext();
            reader.VerifyExpectedTokenAndMoveNext(LuaToken.EqualsSign);
            var conditionsParser = new ExpressionListParser();
            var conditions = conditionsParser.Parse(reader, context).ToList();
            reader.VerifyExpectedTokenAndMoveNext(Keywords.Do);

            var statementsParser = new StatementBlockParser(Keywords.End);
            var bodyBlock = statementsParser.ParseBlock(reader, context);
            context.ReleaseScope(scope);
            return new ForStatement(conditions,bodyBlock);
        }
Esempio n. 6
0
        public override 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);
        }
Esempio n. 7
0
        public LuaStatement Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            reader.VerifyExpectedTokenAndMoveNext(Keywords.For);
            var scope = context.AcquireScope();

            reader.VerifyIsIdentifier();
            var forVariableName = reader.GetAndMoveNext();

            reader.VerifyExpectedTokenAndMoveNext(LuaToken.EqualsSign);
            var conditionsParser = new ExpressionListParser();
            var conditions       = conditionsParser.Parse(reader, context).ToList();

            reader.VerifyExpectedTokenAndMoveNext(Keywords.Do);

            var statementsParser = new StatementBlockParser(Keywords.End);
            var bodyBlock        = statementsParser.ParseBlock(reader, context);

            context.ReleaseScope(scope);
            return(new ForStatement(conditions, bodyBlock));
        }
Esempio n. 8
0
        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));
        }