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); }
private Ast.DeclareStmt ParseDeclareStmt(TokenQueue q) { var stmt = new Ast.DeclareStmt { SourceToken = q.SourceToken }; q.Take("declare"); if (q.Peek() == "parameter") { q.Take(); stmt.IsParameter = true; } ParseAssignmentStmtCore(q, stmt); return(stmt); }
private Ast.Stmt ParseIfStmt(TokenQueue q) { var stmt = new Ast.IfStmt { SourceToken = q.SourceToken }; q.Take("if"); stmt.Condition = ParseExpr(q); stmt.Block = ParseBlock(q); if (q.Peek() == "else") { q.Take("else"); stmt.ElseBlock = ParseBlock(q); } return(stmt); }
public override MatchResult?MatchStep(MatchStack stack, MatchFrame frame, TokenQueue q) { int idx = (int)q.Take().Type; var match = idx >= 0 && idx < _bitmap.Length && _bitmap[idx]; return(match ? MatchResult.Matched : MatchResult.NoMatch); }
private void ParseAssignmentStmtCore(TokenQueue q, Ast.AssignmentStmt stmt) { stmt.VariableName = ParseVariableName(q); if (q.Peek() == "=") { q.Take(); stmt.InitialValue = ParseExpr(q); } ConsumeSemicolon(q); }
private Ast.Stmt ParseSetStmt(TokenQueue q) { var stmt = new Ast.SetStmt { SourceToken = q.SourceToken }; q.Take("set"); ParseAssignmentStmtCore(q, stmt); return(stmt); }
private Ast.Stmt ParseContinueStmt(TokenQueue q) { var stmt = new Ast.ContinueStmt { SourceToken = q.SourceToken }; q.Take("continue"); ConsumeSemicolon(q); return(stmt); }
private Ast.Stmt ParseBreakStmt(TokenQueue q) { var stmt = new Ast.BreakStmt { SourceToken = q.SourceToken }; q.Take("break"); ConsumeSemicolon(q); return(stmt); }
private Ast.Stmt ParsePrintStmt(TokenQueue q) { var stmt = new Ast.PrintStmt { SourceToken = q.SourceToken }; q.Take("print"); stmt.Value = ParseExpr(q); ConsumeSemicolon(q); return(stmt); }
private Ast.Stmt ParseForStmt(TokenQueue q) { var stmt = new Ast.ForStmt { SourceToken = q.SourceToken }; q.Take("for"); stmt.VariableName = ParseVariableName(q); q.Take("="); stmt.FirstNumberExpr = ParseExpr(q); q.Take("to"); stmt.LastNumberExpr = ParseExpr(q); if (q.TakeMaybe("step")) { stmt.StepExpr = ParseExpr(q); } stmt.Block = ParseBlock(q); ConsumeSemicolon(q); return(stmt); }
private Ast.Stmt ParseWhileStmt(TokenQueue q) { var stmt = new Ast.WhileStmt { SourceToken = q.SourceToken }; q.Take("while"); stmt.Condition = ParseExpr(q); stmt.Block = ParseBlock(q); ConsumeSemicolon(q); return(stmt); }
public override MatchResult?MatchStep(MatchStack stack, MatchFrame frame, TokenQueue q) { switch (q.Take().Type) { case TokenType.Id: case TokenType.Ties: case TokenType.Variable when AllowVariable: return(MatchResult.Matched); default: return(MatchResult.NoMatch); } }
private Ast.Stmt ParseReturnStmt(TokenQueue q) { var stmt = new Ast.ReturnStmt { SourceToken = q.SourceToken }; q.Take("return"); if (PeekExpr(q)) { stmt.Value = ParseExpr(q); } ConsumeSemicolon(q); return(stmt); }
private Ast.Stmt ParseThrowStmt(TokenQueue q) { var stmt = new Ast.ThrowStmt { SourceToken = q.SourceToken }; q.Take("throw"); if (PeekExpr(q)) { stmt.HasErrorValues = true; stmt.Message = ParseExpr(q); } ConsumeSemicolon(q); return(stmt); }
private Ast.Stmt ParseTryCatchStmt(TokenQueue q) { var stmt = new Ast.TryCatchStmt { SourceToken = q.SourceToken }; q.Take("begin"); q.Take("try"); stmt.TryBlock = new Ast.Block { SourceToken = q.SourceToken }; while (q.Peek() != "end") { var tryStmt = ParseStmt(q); if (tryStmt != null) { stmt.TryBlock.Statements.Add(tryStmt); } } q.Take("end"); q.Take("try"); q.Take("begin"); q.Take("catch"); stmt.CatchBlock = new Ast.Block { SourceToken = q.SourceToken }; while (q.Peek() != "end") { var catchStmt = ParseStmt(q); if (catchStmt != null) { stmt.CatchBlock.Statements.Add(catchStmt); } } q.Take("end"); q.Take("catch"); return(stmt); }
private Ast.Stmt ParseStmt(TokenQueue q) // or null { switch (q.Peek(0)) { case ";": q.Take(";"); return(null); case "declare": return(ParseDeclareStmt(q)); case "while": return(ParseWhileStmt(q)); case "break": return(ParseBreakStmt(q)); case "continue": return(ParseContinueStmt(q)); case "print": return(ParsePrintStmt(q)); case "exec": case "execute": return(ParseExecuteStmt(q)); case "return": return(ParseReturnStmt(q)); case "throw": return(ParseThrowStmt(q)); case "set": return(ParseSetStmt(q)); case "if": return(ParseIfStmt(q)); case "begin": return(q.Peek(1) == "try" ? ParseTryCatchStmt(q) : ParseSqlStmt(q)); case "import": return(ParseImportStmt(q)); case "export": return(ParseExportStmt(q)); case "for": return(ParseForStmt(q)); default: return(ParseSqlStmt(q)); } }
public override MatchResult?MatchStep(MatchStack stack, MatchFrame frame, TokenQueue q) { return(q.Take().Type == TokenType.String ? MatchResult.Matched : MatchResult.NoMatch); }
public override MatchResult?MatchStep(MatchStack stack, MatchFrame frame, TokenQueue q) { return(q.Take().Text.ToLower() == Text.ToLower() ? MatchResult.Matched : MatchResult.NoMatch); }