Exemple #1
0
        private Ast.Stmt ParseExecuteStmt(TokenQueue q)
        {
            var stmt = new Ast.ExecuteStmt {
                SourceToken = q.SourceToken
            };

            q.Take("exec", "execute");

            if (q.Peek(1) == "=")
            {
                stmt.ReturnVariableName = ParseVariableName(q);
                q.Take("=");
            }

            if (q.PeekToken().Type == TokenType.String || q.PeekToken().Type == TokenType.Id)
            {
                stmt.ScriptName = q.Take().GetUnescapedText();
            }
            else
            {
                throw new SyntaxException(new[] { "string", "identifier" }, q);
            }

            if (IsVariableName(q.PeekToken()?.GetUnescapedText() ?? "") && q.Peek(1) == "=")
            {
                while (true)
                {
                    var arg = new Ast.ArgumentPair();
                    arg.Name = ParseVariableName(q);
                    q.Take("=");
                    if (q.Peek() == "default")
                    {
                        q.Take();
                    }
                    else
                    {
                        arg.Value = ParseExpr(q);
                    }
                    stmt.Arguments.Add(arg);
                    if (!q.TakeMaybe(","))
                    {
                        break;
                    }
                }
            }

            ConsumeSemicolon(q);
            return(stmt);
        }
Exemple #2
0
        private string ParseIdentifier(TokenQueue q)   // or null
        {
            var token = q.PeekToken();

            if (token.Type == TokenType.Id)
            {
                return(q.Take().GetUnescapedText());
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        private static string ParseVariableName(TokenQueue q)
        {
            var t = q.PeekToken();

            if (t.Type == TokenType.Variable && IsVariableName(t.GetUnescapedText()))
            {
                q.Take();
                return(t.GetUnescapedText());
            }
            else
            {
                throw new SyntaxException(new[] { "variable name starting with @ $ :" }, q);
            }
        }
Exemple #4
0
        private Ast.IdentifierOrExpr ParseIdentifierOrExpr(TokenQueue q)   // or null
        {
            var token = q.PeekToken();

            if (token.Type == TokenType.Id)
            {
                q.Take();
                return(new Ast.IdentifierOrExpr {
                    SourceToken = token, Identifier = token.GetUnescapedText()
                });
            }
            else if (PeekExpr(q))
            {
                return(new Ast.IdentifierOrExpr {
                    SourceToken = token, Expr = ParseExpr(q)
                });
            }
            else
            {
                return(null);
            }
        }