diff --git a/ast/ast.go b/ast/ast.go index ffc3933b..0a8add6f 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -60,7 +60,9 @@ type Statement interface { // - https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language // - https://cloud.google.com/spanner/docs/reference/standard-sql/dml-syntax -func (BadNode) isStatement() {} +func (BadStatement) isStatement() {} +func (BadDDL) isStatement() {} +func (BadDML) isStatement() {} func (QueryStatement) isStatement() {} func (CreateSchema) isStatement() {} func (DropSchema) isStatement() {} @@ -111,7 +113,7 @@ type QueryExpr interface { isQueryExpr() } -func (BadNode) isQueryExpr() {} +func (BadQueryExpr) isQueryExpr() {} func (Select) isQueryExpr() {} func (Query) isQueryExpr() {} func (FromQuery) isQueryExpr() {} @@ -177,7 +179,7 @@ type Expr interface { isExpr() } -func (BadNode) isExpr() {} +func (BadExpr) isExpr() {} func (BinaryExpr) isExpr() {} func (UnaryExpr) isExpr() {} func (InExpr) isExpr() {} @@ -300,7 +302,7 @@ type Type interface { isType() } -func (BadNode) isType() {} +func (BadType) isType() {} func (SimpleType) isType() {} func (ArrayType) isType() {} func (StructType) isType() {} @@ -348,7 +350,7 @@ type DDL interface { // // - https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language -func (BadNode) isDDL() {} +func (BadDDL) isDDL() {} func (CreateSchema) isDDL() {} func (DropSchema) isDDL() {} func (CreateDatabase) isDDL() {} @@ -507,10 +509,10 @@ type DML interface { isDML() } -func (BadNode) isDML() {} -func (Insert) isDML() {} -func (Delete) isDML() {} -func (Update) isDML() {} +func (BadDML) isDML() {} +func (Insert) isDML() {} +func (Delete) isDML() {} +func (Update) isDML() {} // InsertInput represents input values of INSERT statement. type InsertInput interface { @@ -558,6 +560,66 @@ type BadNode struct { Tokens []*token.Token } +// BadStatement is a BadNode for Statement. +// +// {{.BadNode | sql}} +type BadStatement struct { + // pos = BadNode.pos + // end = BadNode.end + + BadNode *BadNode +} + +// BadQueryExpr is a BadNode for QueryExpr. +// +// {{.BadNode | sql}} +type BadQueryExpr struct { + // pos = BadNode.pos + // end = BadNode.end + + BadNode *BadNode +} + +// BadExpr is a BadNode for Expr. +// +// {{.BadNode | sql}} +type BadExpr struct { + // pos = BadNode.pos + // end = BadNode.end + + BadNode *BadNode +} + +// BadType is a BadNode for Type. +// +// {{.BadNode | sql}} +type BadType struct { + // pos = BadNode.pos + // end = BadNode.end + + BadNode *BadNode +} + +// BadDDL is a BadNode for DDL. +// +// {{.BadNode | sql}} +type BadDDL struct { + // pos = BadNode.pos + // end = BadNode.end + + BadNode *BadNode +} + +// BadDML is a BadNode for DML. +// +// {{.BadNode | sql}} +type BadDML struct { + // pos = BadNode.pos + // end = BadNode.end + + BadNode *BadNode +} + // ================================================================================ // // SELECT @@ -2285,8 +2347,6 @@ type DropProtoBundle struct { Bundle token.Pos // position of "BUNDLE" pseudo keyword } -// end of PROTO BUNDLE statements - // CreateTable is CREATE TABLE statement node. // // CREATE TABLE {{if .IfNotExists}}IF NOT EXISTS{{end}} {{.Name | sql}} ( diff --git a/ast/pos.go b/ast/pos.go index aa9260a6..7ae4f66a 100644 --- a/ast/pos.go +++ b/ast/pos.go @@ -14,6 +14,54 @@ func (b *BadNode) End() token.Pos { return b.NodeEnd } +func (b *BadStatement) Pos() token.Pos { + return nodePos(wrapNode(b.BadNode)) +} + +func (b *BadStatement) End() token.Pos { + return nodeEnd(wrapNode(b.BadNode)) +} + +func (b *BadQueryExpr) Pos() token.Pos { + return nodePos(wrapNode(b.BadNode)) +} + +func (b *BadQueryExpr) End() token.Pos { + return nodeEnd(wrapNode(b.BadNode)) +} + +func (b *BadExpr) Pos() token.Pos { + return nodePos(wrapNode(b.BadNode)) +} + +func (b *BadExpr) End() token.Pos { + return nodeEnd(wrapNode(b.BadNode)) +} + +func (b *BadType) Pos() token.Pos { + return nodePos(wrapNode(b.BadNode)) +} + +func (b *BadType) End() token.Pos { + return nodeEnd(wrapNode(b.BadNode)) +} + +func (b *BadDDL) Pos() token.Pos { + return nodePos(wrapNode(b.BadNode)) +} + +func (b *BadDDL) End() token.Pos { + return nodeEnd(wrapNode(b.BadNode)) +} + +func (b *BadDML) Pos() token.Pos { + return nodePos(wrapNode(b.BadNode)) +} + +func (b *BadDML) End() token.Pos { + return nodeEnd(wrapNode(b.BadNode)) +} + func (q *QueryStatement) Pos() token.Pos { return nodePos(nodeChoice(wrapNode(q.Hint), wrapNode(q.Query))) } diff --git a/ast/sql.go b/ast/sql.go index 27e9c9f7..87e383f9 100644 --- a/ast/sql.go +++ b/ast/sql.go @@ -172,6 +172,13 @@ func (b *BadNode) SQL() string { return sql } +func (b *BadStatement) SQL() string { return b.BadNode.SQL() } +func (b *BadQueryExpr) SQL() string { return b.BadNode.SQL() } +func (b *BadExpr) SQL() string { return b.BadNode.SQL() } +func (b *BadType) SQL() string { return b.BadNode.SQL() } +func (b *BadDDL) SQL() string { return b.BadNode.SQL() } +func (b *BadDML) SQL() string { return b.BadNode.SQL() } + // ================================================================================ // // SELECT diff --git a/parser.go b/parser.go index 63330fce..0cdf2ed8 100644 --- a/parser.go +++ b/parser.go @@ -154,7 +154,7 @@ func (p *Parser) parseStatement() (stmt ast.Statement) { l := p.Lexer.Clone() defer func() { if r := recover(); r != nil { - stmt = p.handleParseStatementError(r, l) + stmt = &ast.BadStatement{BadNode: p.handleParseStatementError(r, l)} } }() @@ -233,7 +233,7 @@ func (p *Parser) parseQueryStatement() (stmt *ast.QueryStatement) { // When parsing is failed on tryParseHint or tryParseWith, the result of these methods are discarded // becasue they are concrete structs and we cannot fill them with *ast.BadNode. stmt = &ast.QueryStatement{ - Query: p.handleParseStatementError(r, l), + Query: &ast.BadQueryExpr{BadNode: p.handleParseStatementError(r, l)}, } } }() @@ -2749,7 +2749,7 @@ func (p *Parser) parseDDL() (ddl ast.DDL) { l := p.Lexer.Clone() defer func() { if r := recover(); r != nil { - ddl = p.handleParseStatementError(r, l) + ddl = &ast.BadDDL{BadNode: p.handleParseStatementError(r, l)} } }() @@ -4641,7 +4641,7 @@ func (p *Parser) parseDML() (dml ast.DML) { l := p.Lexer.Clone() defer func() { if r := recover(); r != nil { - dml = p.handleParseStatementError(r, l) + dml = &ast.BadDML{BadNode: p.handleParseStatementError(r, l)} } }() @@ -5072,7 +5072,7 @@ skip: } } -func (p *Parser) handleParseQueryExprError(simple bool, r any, l *Lexer) *ast.BadNode { +func (p *Parser) handleParseQueryExprError(simple bool, r any, l *Lexer) *ast.BadQueryExpr { p.handleError(r, l) var tokens []*token.Token @@ -5101,14 +5101,16 @@ skip: p.Lexer.nextToken(true) } - return &ast.BadNode{ - NodePos: pos, - NodeEnd: end, - Tokens: tokens, + return &ast.BadQueryExpr{ + BadNode: &ast.BadNode{ + NodePos: pos, + NodeEnd: end, + Tokens: tokens, + }, } } -func (p *Parser) handleParseExprError(r any, l *Lexer) *ast.BadNode { +func (p *Parser) handleParseExprError(r any, l *Lexer) *ast.BadExpr { p.handleError(r, l) var tokens []*token.Token @@ -5137,14 +5139,16 @@ skip: p.Lexer.nextToken(true) } - return &ast.BadNode{ - NodePos: pos, - NodeEnd: end, - Tokens: tokens, + return &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: pos, + NodeEnd: end, + Tokens: tokens, + }, } } -func (p *Parser) handleParseTypeError(r any, l *Lexer) *ast.BadNode { +func (p *Parser) handleParseTypeError(r any, l *Lexer) *ast.BadType { p.handleError(r, l) var tokens []*token.Token @@ -5183,10 +5187,12 @@ skip: p.Lexer.nextToken(true) } - return &ast.BadNode{ - NodePos: pos, - NodeEnd: end, - Tokens: tokens, + return &ast.BadType{ + BadNode: &ast.BadNode{ + NodePos: pos, + NodeEnd: end, + Tokens: tokens, + }, } } diff --git a/testdata/result/dml/!bad_insert.sql.txt b/testdata/result/dml/!bad_insert.sql.txt index 4d2574df..53381dfa 100644 --- a/testdata/result/dml/!bad_insert.sql.txt +++ b/testdata/result/dml/!bad_insert.sql.txt @@ -34,119 +34,121 @@ syntax error: testdata/input/dml/!bad_insert.sql:2:1: expected beginning of simp }, }, Input: &ast.SubQueryInput{ - Query: &ast.BadNode{ - NodePos: 27, - NodeEnd: 59, - Tokens: []*token.Token{ - &token.Token{ - Kind: "", - Space: "\n", - Raw: "vales", - AsString: "vales", - Pos: 27, - End: 32, - }, - &token.Token{ - Kind: "(", - Space: " ", - Raw: "(", - Pos: 33, - End: 34, - }, - &token.Token{ - Kind: "", - Raw: "1", - Base: 10, - Pos: 34, - End: 35, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 35, - End: 36, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "2", - Base: 10, - Pos: 37, - End: 38, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 38, - End: 39, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "3", - Base: 10, - Pos: 40, - End: 41, - }, - &token.Token{ - Kind: ")", - Raw: ")", - Pos: 41, - End: 42, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 42, - End: 43, - }, - &token.Token{ - Kind: "(", - Space: "\n ", - Raw: "(", - Pos: 50, - End: 51, - }, - &token.Token{ - Kind: "", - Raw: "4", - Base: 10, - Pos: 51, - End: 52, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 52, - End: 53, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "5", - Base: 10, - Pos: 54, - End: 55, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 55, - End: 56, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "6", - Base: 10, - Pos: 57, - End: 58, - }, - &token.Token{ - Kind: ")", - Raw: ")", - Pos: 58, - End: 59, + Query: &ast.BadQueryExpr{ + BadNode: &ast.BadNode{ + NodePos: 27, + NodeEnd: 59, + Tokens: []*token.Token{ + &token.Token{ + Kind: "", + Space: "\n", + Raw: "vales", + AsString: "vales", + Pos: 27, + End: 32, + }, + &token.Token{ + Kind: "(", + Space: " ", + Raw: "(", + Pos: 33, + End: 34, + }, + &token.Token{ + Kind: "", + Raw: "1", + Base: 10, + Pos: 34, + End: 35, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 35, + End: 36, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "2", + Base: 10, + Pos: 37, + End: 38, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 38, + End: 39, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "3", + Base: 10, + Pos: 40, + End: 41, + }, + &token.Token{ + Kind: ")", + Raw: ")", + Pos: 41, + End: 42, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 42, + End: 43, + }, + &token.Token{ + Kind: "(", + Space: "\n ", + Raw: "(", + Pos: 50, + End: 51, + }, + &token.Token{ + Kind: "", + Raw: "4", + Base: 10, + Pos: 51, + End: 52, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 52, + End: 53, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "5", + Base: 10, + Pos: 54, + End: 55, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 55, + End: 56, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "6", + Base: 10, + Pos: 57, + End: 58, + }, + &token.Token{ + Kind: ")", + Raw: ")", + Pos: 58, + End: 59, + }, }, }, }, diff --git a/testdata/result/expr/!bad_new_braced_constructor.sql.txt b/testdata/result/expr/!bad_new_braced_constructor.sql.txt index 9cf390ad..6004d3dc 100644 --- a/testdata/result/expr/!bad_new_braced_constructor.sql.txt +++ b/testdata/result/expr/!bad_new_braced_constructor.sql.txt @@ -31,24 +31,26 @@ syntax error: testdata/input/expr/!bad_new_braced_constructor.sql:1:20: unexpect }, Value: &ast.BracedConstructorFieldValueExpr{ Colon: 13, - Expr: &ast.BadNode{ - NodePos: 15, - NodeEnd: 18, - Tokens: []*token.Token{ - &token.Token{ - Kind: "", - Space: " ", - Raw: "1", - Base: 10, - Pos: 15, - End: 16, - }, - &token.Token{ - Kind: "+", - Space: " ", - Raw: "+", - Pos: 17, - End: 18, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 15, + NodeEnd: 18, + Tokens: []*token.Token{ + &token.Token{ + Kind: "", + Space: " ", + Raw: "1", + Base: 10, + Pos: 15, + End: 16, + }, + &token.Token{ + Kind: "+", + Space: " ", + Raw: "+", + Pos: 17, + End: 18, + }, }, }, }, diff --git a/testdata/result/expr/!bad_plus.sql.txt b/testdata/result/expr/!bad_plus.sql.txt index 8866b00f..53433915 100644 --- a/testdata/result/expr/!bad_plus.sql.txt +++ b/testdata/result/expr/!bad_plus.sql.txt @@ -9,21 +9,23 @@ syntax error: testdata/input/expr/!bad_plus.sql:2:1: unexpected token: --- AST -&ast.BadNode{ - NodeEnd: 3, - Tokens: []*token.Token{ - &token.Token{ - Kind: "", - Raw: "1", - Base: 10, - End: 1, - }, - &token.Token{ - Kind: "+", - Space: " ", - Raw: "+", - Pos: 2, - End: 3, +&ast.BadExpr{ + BadNode: &ast.BadNode{ + NodeEnd: 3, + Tokens: []*token.Token{ + &token.Token{ + Kind: "", + Raw: "1", + Base: 10, + End: 1, + }, + &token.Token{ + Kind: "+", + Space: " ", + Raw: "+", + Pos: 2, + End: 3, + }, }, }, } diff --git a/testdata/result/expr/!bad_plus2.sql.txt b/testdata/result/expr/!bad_plus2.sql.txt index 06a9d1bf..9e8ae790 100644 --- a/testdata/result/expr/!bad_plus2.sql.txt +++ b/testdata/result/expr/!bad_plus2.sql.txt @@ -19,23 +19,25 @@ syntax error: testdata/input/expr/!bad_plus2.sql:1:13: unexpected token: ) Op: "+", Left: &ast.ParenExpr{ Rparen: 4, - Expr: &ast.BadNode{ - NodePos: 1, - NodeEnd: 4, - Tokens: []*token.Token{ - &token.Token{ - Kind: "", - Raw: "1", - Base: 10, - Pos: 1, - End: 2, - }, - &token.Token{ - Kind: "+", - Space: " ", - Raw: "+", - Pos: 3, - End: 4, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 1, + NodeEnd: 4, + Tokens: []*token.Token{ + &token.Token{ + Kind: "", + Raw: "1", + Base: 10, + Pos: 1, + End: 2, + }, + &token.Token{ + Kind: "+", + Space: " ", + Raw: "+", + Pos: 3, + End: 4, + }, }, }, }, @@ -43,23 +45,25 @@ syntax error: testdata/input/expr/!bad_plus2.sql:1:13: unexpected token: ) Right: &ast.ParenExpr{ Lparen: 8, Rparen: 12, - Expr: &ast.BadNode{ - NodePos: 9, - NodeEnd: 12, - Tokens: []*token.Token{ - &token.Token{ - Kind: "", - Raw: "2", - Base: 10, - Pos: 9, - End: 10, - }, - &token.Token{ - Kind: "+", - Space: " ", - Raw: "+", - Pos: 11, - End: 12, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 9, + NodeEnd: 12, + Tokens: []*token.Token{ + &token.Token{ + Kind: "", + Raw: "2", + Base: 10, + Pos: 9, + End: 10, + }, + &token.Token{ + Kind: "+", + Space: " ", + Raw: "+", + Pos: 11, + End: 12, + }, }, }, }, diff --git a/testdata/result/expr/!bad_typed_struct.sql.txt b/testdata/result/expr/!bad_typed_struct.sql.txt index 25558938..2ca538c2 100644 --- a/testdata/result/expr/!bad_typed_struct.sql.txt +++ b/testdata/result/expr/!bad_typed_struct.sql.txt @@ -19,39 +19,43 @@ syntax error: testdata/input/expr/!bad_typed_struct.sql:1:14: unexpected token: Rparen: 13, Fields: []*ast.StructField{ &ast.StructField{ - Type: &ast.BadNode{ - NodePos: 7, - NodeEnd: 8, - Tokens: []*token.Token{ - &token.Token{ - Kind: "", - Raw: "1", - Base: 10, - Pos: 7, - End: 8, + Type: &ast.BadType{ + BadNode: &ast.BadNode{ + NodePos: 7, + NodeEnd: 8, + Tokens: []*token.Token{ + &token.Token{ + Kind: "", + Raw: "1", + Base: 10, + Pos: 7, + End: 8, + }, }, }, }, }, }, Values: []ast.Expr{ - &ast.BadNode{ - NodePos: 10, - NodeEnd: 13, - Tokens: []*token.Token{ - &token.Token{ - Kind: "", - Raw: "2", - Base: 10, - Pos: 10, - End: 11, - }, - &token.Token{ - Kind: "+", - Space: " ", - Raw: "+", - Pos: 12, - End: 13, + &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 10, + NodeEnd: 13, + Tokens: []*token.Token{ + &token.Token{ + Kind: "", + Raw: "2", + Base: 10, + Pos: 10, + End: 11, + }, + &token.Token{ + Kind: "+", + Space: " ", + Raw: "+", + Pos: 12, + End: 13, + }, }, }, }, diff --git a/testdata/result/query/!bad_hint_select.sql.txt b/testdata/result/query/!bad_hint_select.sql.txt index eee910a8..9b00c469 100644 --- a/testdata/result/query/!bad_hint_select.sql.txt +++ b/testdata/result/query/!bad_hint_select.sql.txt @@ -10,28 +10,30 @@ syntax error: testdata/input/query/!bad_hint_select.sql:1:3: expected token: {, --- AST &ast.QueryStatement{ - Query: &ast.BadNode{ - NodeEnd: 10, - Tokens: []*token.Token{ - &token.Token{ - Kind: "@", - Raw: "@", - End: 1, - }, - &token.Token{ - Kind: "SELECT", - Space: " ", - Raw: "select", - Pos: 2, - End: 8, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "1", - Base: 10, - Pos: 9, - End: 10, + Query: &ast.BadQueryExpr{ + BadNode: &ast.BadNode{ + NodeEnd: 10, + Tokens: []*token.Token{ + &token.Token{ + Kind: "@", + Raw: "@", + End: 1, + }, + &token.Token{ + Kind: "SELECT", + Space: " ", + Raw: "select", + Pos: 2, + End: 8, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "1", + Base: 10, + Pos: 9, + End: 10, + }, }, }, }, diff --git a/testdata/result/query/!bad_hint_select_2.sql.txt b/testdata/result/query/!bad_hint_select_2.sql.txt index 2ade3407..7cee98e3 100644 --- a/testdata/result/query/!bad_hint_select_2.sql.txt +++ b/testdata/result/query/!bad_hint_select_2.sql.txt @@ -31,9 +31,11 @@ syntax error: testdata/input/query/!bad_hint_select_2.sql:1:19: unexpected token Select: 12, Results: []ast.SelectItem{ &ast.ExprSelectItem{ - Expr: &ast.BadNode{ - NodePos: 18, - NodeEnd: 18, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 18, + NodeEnd: 18, + }, }, }, }, diff --git a/testdata/result/query/!bad_select.sql.txt b/testdata/result/query/!bad_select.sql.txt index e651867d..ab2c1e9f 100644 --- a/testdata/result/query/!bad_select.sql.txt +++ b/testdata/result/query/!bad_select.sql.txt @@ -13,9 +13,11 @@ syntax error: testdata/input/query/!bad_select.sql:2:1: unexpected token: Query: &ast.Select{ Results: []ast.SelectItem{ &ast.ExprSelectItem{ - Expr: &ast.BadNode{ - NodePos: 7, - NodeEnd: 7, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 7, + NodeEnd: 7, + }, }, }, }, diff --git a/testdata/result/query/!bad_select_order.sql.txt b/testdata/result/query/!bad_select_order.sql.txt index e5f0bc4d..01dd9611 100644 --- a/testdata/result/query/!bad_select_order.sql.txt +++ b/testdata/result/query/!bad_select_order.sql.txt @@ -10,43 +10,45 @@ syntax error: testdata/input/query/!bad_select_order.sql:1:16: expected token: B --- AST &ast.QueryStatement{ - Query: &ast.BadNode{ - NodeEnd: 20, - Tokens: []*token.Token{ - &token.Token{ - Kind: "SELECT", - Raw: "select", - End: 6, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "1", - Base: 10, - Pos: 7, - End: 8, - }, - &token.Token{ - Kind: "ORDER", - Space: " ", - Raw: "order", - Pos: 9, - End: 14, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "x", - AsString: "x", - Pos: 15, - End: 16, - }, - &token.Token{ - Kind: "ASC", - Space: " ", - Raw: "asc", - Pos: 17, - End: 20, + Query: &ast.BadQueryExpr{ + BadNode: &ast.BadNode{ + NodeEnd: 20, + Tokens: []*token.Token{ + &token.Token{ + Kind: "SELECT", + Raw: "select", + End: 6, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "1", + Base: 10, + Pos: 7, + End: 8, + }, + &token.Token{ + Kind: "ORDER", + Space: " ", + Raw: "order", + Pos: 9, + End: 14, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "x", + AsString: "x", + Pos: 15, + End: 16, + }, + &token.Token{ + Kind: "ASC", + Space: " ", + Raw: "asc", + Pos: 17, + End: 20, + }, }, }, }, diff --git a/testdata/result/query/!bad_select_union_select.sql.txt b/testdata/result/query/!bad_select_union_select.sql.txt index 6dd19cee..650bddbd 100644 --- a/testdata/result/query/!bad_select_union_select.sql.txt +++ b/testdata/result/query/!bad_select_union_select.sql.txt @@ -22,9 +22,11 @@ syntax error: testdata/input/query/!bad_select_union_select.sql:1:24: unexpected &ast.Select{ Results: []ast.SelectItem{ &ast.ExprSelectItem{ - Expr: &ast.BadNode{ - NodePos: 7, - NodeEnd: 7, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 7, + NodeEnd: 7, + }, }, }, }, @@ -33,9 +35,11 @@ syntax error: testdata/input/query/!bad_select_union_select.sql:1:24: unexpected Select: 17, Results: []ast.SelectItem{ &ast.ExprSelectItem{ - Expr: &ast.BadNode{ - NodePos: 23, - NodeEnd: 23, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 23, + NodeEnd: 23, + }, }, }, }, diff --git a/testdata/result/statement/!bad_hint_select.sql.txt b/testdata/result/statement/!bad_hint_select.sql.txt index eee910a8..9b00c469 100644 --- a/testdata/result/statement/!bad_hint_select.sql.txt +++ b/testdata/result/statement/!bad_hint_select.sql.txt @@ -10,28 +10,30 @@ syntax error: testdata/input/query/!bad_hint_select.sql:1:3: expected token: {, --- AST &ast.QueryStatement{ - Query: &ast.BadNode{ - NodeEnd: 10, - Tokens: []*token.Token{ - &token.Token{ - Kind: "@", - Raw: "@", - End: 1, - }, - &token.Token{ - Kind: "SELECT", - Space: " ", - Raw: "select", - Pos: 2, - End: 8, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "1", - Base: 10, - Pos: 9, - End: 10, + Query: &ast.BadQueryExpr{ + BadNode: &ast.BadNode{ + NodeEnd: 10, + Tokens: []*token.Token{ + &token.Token{ + Kind: "@", + Raw: "@", + End: 1, + }, + &token.Token{ + Kind: "SELECT", + Space: " ", + Raw: "select", + Pos: 2, + End: 8, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "1", + Base: 10, + Pos: 9, + End: 10, + }, }, }, }, diff --git a/testdata/result/statement/!bad_hint_select_2.sql.txt b/testdata/result/statement/!bad_hint_select_2.sql.txt index 2ade3407..7cee98e3 100644 --- a/testdata/result/statement/!bad_hint_select_2.sql.txt +++ b/testdata/result/statement/!bad_hint_select_2.sql.txt @@ -31,9 +31,11 @@ syntax error: testdata/input/query/!bad_hint_select_2.sql:1:19: unexpected token Select: 12, Results: []ast.SelectItem{ &ast.ExprSelectItem{ - Expr: &ast.BadNode{ - NodePos: 18, - NodeEnd: 18, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 18, + NodeEnd: 18, + }, }, }, }, diff --git a/testdata/result/statement/!bad_insert.sql.txt b/testdata/result/statement/!bad_insert.sql.txt index 4d2574df..53381dfa 100644 --- a/testdata/result/statement/!bad_insert.sql.txt +++ b/testdata/result/statement/!bad_insert.sql.txt @@ -34,119 +34,121 @@ syntax error: testdata/input/dml/!bad_insert.sql:2:1: expected beginning of simp }, }, Input: &ast.SubQueryInput{ - Query: &ast.BadNode{ - NodePos: 27, - NodeEnd: 59, - Tokens: []*token.Token{ - &token.Token{ - Kind: "", - Space: "\n", - Raw: "vales", - AsString: "vales", - Pos: 27, - End: 32, - }, - &token.Token{ - Kind: "(", - Space: " ", - Raw: "(", - Pos: 33, - End: 34, - }, - &token.Token{ - Kind: "", - Raw: "1", - Base: 10, - Pos: 34, - End: 35, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 35, - End: 36, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "2", - Base: 10, - Pos: 37, - End: 38, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 38, - End: 39, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "3", - Base: 10, - Pos: 40, - End: 41, - }, - &token.Token{ - Kind: ")", - Raw: ")", - Pos: 41, - End: 42, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 42, - End: 43, - }, - &token.Token{ - Kind: "(", - Space: "\n ", - Raw: "(", - Pos: 50, - End: 51, - }, - &token.Token{ - Kind: "", - Raw: "4", - Base: 10, - Pos: 51, - End: 52, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 52, - End: 53, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "5", - Base: 10, - Pos: 54, - End: 55, - }, - &token.Token{ - Kind: ",", - Raw: ",", - Pos: 55, - End: 56, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "6", - Base: 10, - Pos: 57, - End: 58, - }, - &token.Token{ - Kind: ")", - Raw: ")", - Pos: 58, - End: 59, + Query: &ast.BadQueryExpr{ + BadNode: &ast.BadNode{ + NodePos: 27, + NodeEnd: 59, + Tokens: []*token.Token{ + &token.Token{ + Kind: "", + Space: "\n", + Raw: "vales", + AsString: "vales", + Pos: 27, + End: 32, + }, + &token.Token{ + Kind: "(", + Space: " ", + Raw: "(", + Pos: 33, + End: 34, + }, + &token.Token{ + Kind: "", + Raw: "1", + Base: 10, + Pos: 34, + End: 35, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 35, + End: 36, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "2", + Base: 10, + Pos: 37, + End: 38, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 38, + End: 39, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "3", + Base: 10, + Pos: 40, + End: 41, + }, + &token.Token{ + Kind: ")", + Raw: ")", + Pos: 41, + End: 42, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 42, + End: 43, + }, + &token.Token{ + Kind: "(", + Space: "\n ", + Raw: "(", + Pos: 50, + End: 51, + }, + &token.Token{ + Kind: "", + Raw: "4", + Base: 10, + Pos: 51, + End: 52, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 52, + End: 53, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "5", + Base: 10, + Pos: 54, + End: 55, + }, + &token.Token{ + Kind: ",", + Raw: ",", + Pos: 55, + End: 56, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "6", + Base: 10, + Pos: 57, + End: 58, + }, + &token.Token{ + Kind: ")", + Raw: ")", + Pos: 58, + End: 59, + }, }, }, }, diff --git a/testdata/result/statement/!bad_select.sql.txt b/testdata/result/statement/!bad_select.sql.txt index e651867d..ab2c1e9f 100644 --- a/testdata/result/statement/!bad_select.sql.txt +++ b/testdata/result/statement/!bad_select.sql.txt @@ -13,9 +13,11 @@ syntax error: testdata/input/query/!bad_select.sql:2:1: unexpected token: Query: &ast.Select{ Results: []ast.SelectItem{ &ast.ExprSelectItem{ - Expr: &ast.BadNode{ - NodePos: 7, - NodeEnd: 7, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 7, + NodeEnd: 7, + }, }, }, }, diff --git a/testdata/result/statement/!bad_select_order.sql.txt b/testdata/result/statement/!bad_select_order.sql.txt index e5f0bc4d..01dd9611 100644 --- a/testdata/result/statement/!bad_select_order.sql.txt +++ b/testdata/result/statement/!bad_select_order.sql.txt @@ -10,43 +10,45 @@ syntax error: testdata/input/query/!bad_select_order.sql:1:16: expected token: B --- AST &ast.QueryStatement{ - Query: &ast.BadNode{ - NodeEnd: 20, - Tokens: []*token.Token{ - &token.Token{ - Kind: "SELECT", - Raw: "select", - End: 6, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "1", - Base: 10, - Pos: 7, - End: 8, - }, - &token.Token{ - Kind: "ORDER", - Space: " ", - Raw: "order", - Pos: 9, - End: 14, - }, - &token.Token{ - Kind: "", - Space: " ", - Raw: "x", - AsString: "x", - Pos: 15, - End: 16, - }, - &token.Token{ - Kind: "ASC", - Space: " ", - Raw: "asc", - Pos: 17, - End: 20, + Query: &ast.BadQueryExpr{ + BadNode: &ast.BadNode{ + NodeEnd: 20, + Tokens: []*token.Token{ + &token.Token{ + Kind: "SELECT", + Raw: "select", + End: 6, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "1", + Base: 10, + Pos: 7, + End: 8, + }, + &token.Token{ + Kind: "ORDER", + Space: " ", + Raw: "order", + Pos: 9, + End: 14, + }, + &token.Token{ + Kind: "", + Space: " ", + Raw: "x", + AsString: "x", + Pos: 15, + End: 16, + }, + &token.Token{ + Kind: "ASC", + Space: " ", + Raw: "asc", + Pos: 17, + End: 20, + }, }, }, }, diff --git a/testdata/result/statement/!bad_select_union_select.sql.txt b/testdata/result/statement/!bad_select_union_select.sql.txt index 6dd19cee..650bddbd 100644 --- a/testdata/result/statement/!bad_select_union_select.sql.txt +++ b/testdata/result/statement/!bad_select_union_select.sql.txt @@ -22,9 +22,11 @@ syntax error: testdata/input/query/!bad_select_union_select.sql:1:24: unexpected &ast.Select{ Results: []ast.SelectItem{ &ast.ExprSelectItem{ - Expr: &ast.BadNode{ - NodePos: 7, - NodeEnd: 7, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 7, + NodeEnd: 7, + }, }, }, }, @@ -33,9 +35,11 @@ syntax error: testdata/input/query/!bad_select_union_select.sql:1:24: unexpected Select: 17, Results: []ast.SelectItem{ &ast.ExprSelectItem{ - Expr: &ast.BadNode{ - NodePos: 23, - NodeEnd: 23, + Expr: &ast.BadExpr{ + BadNode: &ast.BadNode{ + NodePos: 23, + NodeEnd: 23, + }, }, }, },