private Ast.ImportTxtStmt ParseImportTxtStmt(TokenQueue q) // or null { var stmt = new Ast.ImportTxtStmt { SourceToken = q.SourceToken }; var start = q.GetLocation(); if (!q.TakeMaybe("import")) { q.Jump(start); return(null); } if (!q.TakeMaybe("txt", "text")) { q.Jump(start); return(null); } stmt.FilenameExpr = ParseExpr(q); q.Take("into"); stmt.TableName = Check(q, ParseIdentifierOrExpr(q)); if (q.Peek() == "(") { q.Take("("); stmt.LineNumberColumnName = Check(q, ParseIdentifierOrExpr(q)); q.Take(","); stmt.TextColumnName = Check(q, ParseIdentifierOrExpr(q)); q.Take(")"); } if (q.TakeMaybe("options")) { stmt.OptionsList = Check(q, ParseOptionsList(q)); } ConsumeSemicolon(q); return(stmt); }
private Ast.ExportTxtStmt ParseExportTxtStmt(TokenQueue q) // or null { var stmt = new Ast.ExportTxtStmt { SourceToken = q.SourceToken }; var start = q.GetLocation(); if (!q.TakeMaybe("export")) { q.Jump(start); return(null); } if (!q.TakeMaybe("txt", "text")) { q.Jump(start); return(null); } stmt.FilenameExpr = ParseExpr(q); q.Take("from"); q.Take("("); stmt.SelectStmt = ParseSqlStmt(q, "select-stmt"); q.Take(")"); if (q.TakeMaybe("options")) { stmt.OptionsList = Check(q, ParseOptionsList(q)); } ConsumeSemicolon(q); return(stmt); }
private Ast.ImportXlsStmt ParseImportXlsStmt(TokenQueue q) // or null { var stmt = new Ast.ImportXlsStmt { SourceToken = q.SourceToken }; var start = q.GetLocation(); if (!q.TakeMaybe("import")) { q.Jump(start); return(null); } if (!q.TakeMaybe("xls", "xlsx")) { q.Jump(start); return(null); } stmt.FilenameExpr = ParseExpr(q); if (q.TakeMaybe("worksheet")) { stmt.WhichSheetExpr = ParseExpr(q); } q.Take("into"); stmt.ImportTable = Check(q, ParseImportTable(q)); if (q.TakeMaybe("options")) { stmt.OptionsList = Check(q, ParseOptionsList(q)); } ConsumeSemicolon(q); return(stmt); }
private Ast.OptionsList ParseOptionsList(TokenQueue q) // or null { var n = new Ast.OptionsList { SourceToken = q.SourceToken }; if (!q.TakeMaybe("(")) { return(null); } do { var key = Check(q, ParseIdentifier(q)).ToLower(); q.Take(":"); var value = ParseExpr(q); n.Options[key] = value; } while (q.TakeMaybe(",")); q.Take(")"); return(n); }
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.ImportTable ParseImportTable(TokenQueue q) { var n = new Ast.ImportTable { SourceToken = q.SourceToken }; n.TableName = Check(q, ParseIdentifierOrExpr(q)); if (q.Peek() == "(") { q.Take("("); do { n.ImportColumns.Add(Check(q, ParseImportColumn(q))); } while (q.TakeMaybe(",")); q.Take(")"); } return(n); }
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); }