Пример #1
0
        private ExpressionListNode ParseExpressionList()
        {
            ExpressionListNode expressions = new ExpressionListNode();

            bool inparentheses = TryParseToken(TokenType.Separator, "(");

            for (AstNode expression = ParseExpression();
                 expression != null;
                 expression = ParseExpression())
            {
                expressions.Push(expression);
                if (!TryParseToken(TokenType.Separator, ","))
                {
                    break;
                }
            }

            if (inparentheses)
            {
                ParseToken(TokenType.Separator, ")");
                if (TryParseName("do"))
                {
                    expressions.Push(ParseBlockExpression());
                }
                else if (TryParseToken(TokenType.Separator, "{"))
                {
                    expressions.Push(ParseBlockExpression(true));
                }
            }

            return(expressions);
        }
Пример #2
0
        public AstParserState Parse()
        {
            AstParserState state = new AstParserState();
            var            tree  = new ExpressionListNode();

            for (var command = ParseCommand(); command != null; command = ParseCommand())
            {
                tree.Push(command);
            }

            state.filename = filepath;
            state.tree     = tree;
            return(state);
        }
Пример #3
0
        private ExpressionListNode ParseCommandList(IList <string> names)
        {
            ExpressionListNode commands = new ExpressionListNode();

            for (t = lexer.NextToken();
                 t != null && (t.Type != TokenType.Identifier || !names.Contains(t.Value));
                 t = lexer.NextToken())
            {
                if (IsEndOfCommand(t))
                {
                    continue;
                }

                lexer.PushToken(t);
                commands.Push(ParseCommand());
            }

            lexer.PushToken(t);

            return(commands);
        }
Пример #4
0
        private ExpressionListNode ParseCommandList(bool usebraces = false)
        {
            ExpressionListNode commands = new ExpressionListNode();

            for (t = lexer.NextToken(); t != null; t = lexer.NextToken())
            {
                if (usebraces && t.Type == TokenType.Separator && t.Value == "}")
                {
                    break;
                }
                else if (!usebraces && t.Type == TokenType.Identifier && t.Value == "end")
                {
                    break;
                }

                if (IsEndOfCommand(t))
                {
                    continue;
                }

                lexer.PushToken(t);
                commands.Push(ParseCommand());
            }

            lexer.PushToken(t);

            if (usebraces)
            {
                ParseToken(TokenType.Separator, "}");
            }
            else
            {
                ParseName("end");
            }

            return(commands);
        }