cloudspannerecosystem / memefish

memefish is the foundation to analyze Spanner SQL
https://cloudspannerecosystem.dev/memefish/
MIT License
76 stars 19 forks source link

Fix InvalidPos handling of ARRAY keyword in ArrayLiteral #145

Closed apstndb closed 3 weeks ago

apstndb commented 3 weeks ago

fixes #144

This PR fixes the spec of ArrayLiteral.SQL() to preserve lexical tokens.

$ go run ./tools/parse --mode expr '[]'     
--- AST
&ast.ArrayLiteral{
  Array:  -1,
  Lbrack: 0,
  Rbrack: 1,
  Type:   nil,
  Values: []ast.Expr(nil),
}

--- SQL
[]
$ go run ./tools/parse --mode expr 'ARRAY[]'
--- AST
&ast.ArrayLiteral{
  Array:  0,
  Lbrack: 5,
  Rbrack: 6,
  Type:   nil,
  Values: []ast.Expr(nil),
}

--- SQL
ARRAY[]
$ go run ./tools/parse --mode expr 'ARRAY<INT64>[]'
--- AST
&ast.ArrayLiteral{
  Array:  0,
  Lbrack: 12,
  Rbrack: 13,
  Type:   &ast.SimpleType{
    NamePos: 6,
    Name:    "INT64",
  },
  Values: []ast.Expr(nil),
}

--- SQL
ARRAY<INT64>[]