Skip to content

Commit

Permalink
Add support for SQL functions named left or right (#145)
Browse files Browse the repository at this point in the history
These functions collide with SQL keywords such that they didn't parse before this change. But, they are valid PG function names, so these tokens should be included in the fn_name rule.
  • Loading branch information
airhorns authored Jan 8, 2024
1 parent a43e896 commit 855ca49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .deno/syntax/main.ne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,8 @@ const grammar: Grammar = {
{"name": "expr_fn_name$subexpression$2$subexpression$1", "symbols": [(lexerAny.has("kw_any") ? {type: "kw_any"} : kw_any)]},
{"name": "expr_fn_name$subexpression$2$subexpression$1", "symbols": [(lexerAny.has("kw_some") ? {type: "kw_some"} : kw_some)]},
{"name": "expr_fn_name$subexpression$2$subexpression$1", "symbols": [(lexerAny.has("kw_all") ? {type: "kw_all"} : kw_all)]},
{"name": "expr_fn_name$subexpression$2$subexpression$1", "symbols": [(lexerAny.has("kw_left") ? {type: "kw_left"} : kw_left)]},
{"name": "expr_fn_name$subexpression$2$subexpression$1", "symbols": [(lexerAny.has("kw_right") ? {type: "kw_right"} : kw_right)]},
{"name": "expr_fn_name$subexpression$2", "symbols": ["expr_fn_name$subexpression$2$subexpression$1"], "postprocess": x => track(x, {
name: toStr(unwrap(x)),
})},
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/expr.ne
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ expr_fn_name -> ((word %dot):? word_or_keyword {% x => track(x, {
name: unbox(unwrap(x[1])),
...x[0] && { schema: toStr(x[0][0]) },
}) %})
| ((%kw_any | %kw_some | %kw_all) {% x => track(x, {
| ((%kw_any | %kw_some | %kw_all | %kw_left | %kw_right) {% x => track(x, {
name: toStr(unwrap(x)),
})%})

Expand Down
14 changes: 14 additions & 0 deletions src/syntax/expr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,20 @@ line`,
args: [],
});

checkTreeExprLoc([`left('foo')`], {
_location: { start: 0, end: 11 },
type: 'call',
function: {
_location: { start: 0, end: 4 },
name: 'left'
},
args: [{
_location: { start: 5, end: 10 },
type: 'string',
value: 'foo'
}],
});

checkTreeExprLoc([`pg_catalog.col_description(23208,4)`], {
_location: { start: 0, end: 35 },
type: 'call',
Expand Down

0 comments on commit 855ca49

Please sign in to comment.