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.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 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 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 override LuaExpression Parse(INextAwareEnumerator<Token> reader, IParserContext context)
        {
            var name = reader.Current.Value;
            reader.MoveNext();
            reader.VerifyExpectedToken(LuaToken.LeftBracket);

            var parametersParser = new ExpressionListParser();

            var expression = new FunctionCallExpression(name, parametersParser.Parse(reader, context).ToList());
            reader.VerifyExpectedToken(LuaToken.RightBracket);
            return expression;
        }
 public override LuaExpression Parse(INextAwareEnumerator<Token> reader, IParserContext context)
 {
     reader.VerifyExpectedToken(LuaToken.LeftCurlyBrace);
     reader.MoveNext();
     var expressions = new List<LuaExpression>();
     while (reader.Current.Value != LuaToken.RightCurlyBrace)
     {
         expressions.Add(SyntaxParser.ReadExpression(reader, context));
         reader.VerifyExpectedToken(LuaToken.RightCurlyBrace, LuaToken.Comma);
     }
     reader.VerifyExpectedToken(LuaToken.RightCurlyBrace);
     reader.MoveNext();
     return new TableInitializerExpression(expressions);
 }
Ejemplo n.º 7
0
        public LuaExpression Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            reader.VerifyExpectedToken(LuaToken.LeftCurlyBrace);
            reader.MoveNext();
            var expressions = Enumerable.Empty <LuaExpression>();

            if (reader.Current.Value != LuaToken.RightCurlyBrace)
            {
                var parser = new ExpressionListParser();
                expressions = parser.Parse(reader, context);
                reader.VerifyExpectedToken(LuaToken.RightCurlyBrace);
                reader.MoveNext();
            }
            else
            {
                reader.VerifyExpectedTokenAndMoveNext(LuaToken.RightCurlyBrace);
            }
            return(new TableInitializerExpression(expressions));
        }
 public override LuaStatement Parse(INextAwareEnumerator<Token> reader, IParserContext context)
 {
     var scope = context.AcquireScope();
     reader.VerifyExpectedToken(Keywords.Do);
     reader.MoveNext();
     var statements = new List<LuaStatement>();
     while (reader.Current.Value != Keywords.End)
         statements.Add(SyntaxParser.ReadStatement(reader, context));
     reader.VerifyExpectedTokenAndMoveNext(Keywords.End);
     context.ReleaseScope(scope);
     return new DoEndBlock(new StatementBlock(statements));
 }
Ejemplo n.º 9
0
        public LuaExpression Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            var name = reader.Current.Value;

            reader.MoveNext();
            reader.VerifyExpectedTokenAndMoveNext(LuaToken.LeftBracket);

            var parametersParser = new ExpressionListParser();

            var expression = new FunctionCallExpression(name, parametersParser.Parse(reader, context).ToList());

            reader.VerifyExpectedToken(LuaToken.RightBracket);
            return(expression);
        }
 private IList<Variable> ReadDeclarations(INextAwareEnumerator<Token> reader)
 {
     var result = new List<Variable>();
     while (reader.HasNext && reader.Next.Value != null)
     {
         var variable = new Variable(reader.Current.Value);
         result.Add(variable);
         reader.MoveNext();
         reader.VerifyExpectedToken(LuaToken.Comma,LuaToken.EqualsSign);
         if (reader.Current.Value == LuaToken.EqualsSign)
             break;
         reader.MoveNext();
     }
     return result;
 }
Ejemplo n.º 11
0
        public LuaStatement Parse(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            var scope = context.AcquireScope();

            reader.VerifyExpectedToken(Keywords.Do);
            reader.MoveNext();
            var statements = new List <LuaStatement>();

            while (reader.Current.Value != Keywords.End)
            {
                statements.Add(SyntaxParser.ReadStatement(reader, context));
            }
            reader.VerifyExpectedTokenAndMoveNext(Keywords.End);
            context.ReleaseScope(scope);
            return(new DoEndBlock(new StatementBlock(statements)));
        }
        private IList <Variable> ReadDeclarations(INextAwareEnumerator <Token> reader)
        {
            var result = new List <Variable>();

            while (reader.HasNext && reader.Next.Value != null)
            {
                var variable = new Variable(reader.Current.Value);
                result.Add(variable);
                reader.MoveNext();
                reader.VerifyExpectedToken(LuaToken.Comma, LuaToken.EqualsSign);
                if (reader.Current.Value == LuaToken.EqualsSign)
                {
                    break;
                }
                reader.MoveNext();
            }
            return(result);
        }
Ejemplo n.º 13
0
 public static void VerifyExpectedTokenAndMoveNext(this INextAwareEnumerator <Token> enumerator,
                                                   params string[] expectedTokens)
 {
     enumerator.VerifyExpectedToken(expectedTokens);
     enumerator.MoveNext();
 }