Skip to content

Commit

Permalink
Merge pull request m-novikov#51 from DerekStride/derek/bugfix
Browse files Browse the repository at this point in the history
Wrap select expressions in a term node
  • Loading branch information
DerekStride authored Nov 18, 2022
2 parents 70c5026 + 7185335 commit 56d3374
Show file tree
Hide file tree
Showing 12 changed files with 142,861 additions and 59,743 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ generate:

test: generate
${ts} test

format: generate
${ts} test --update

compile: generate
gcc -shared -o target/parser.so -fPIC src/parser.c -I./src
53 changes: 28 additions & 25 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ module.exports = grammar({
$._ddl_statement,
$._dml_statement,
),
';',
optional(';'),
),

_ddl_statement: $ => choice(
Expand Down Expand Up @@ -429,12 +429,13 @@ module.exports = grammar({

_select_expression: $ => choice(
$.all_fields,
seq(
$._expression,
optional($._alias),
),
$.term,
),

term: $ => seq(
field("value", $._expression),
optional($._alias),
),

expression_list :$ => seq(
$._expression_list,
Expand Down Expand Up @@ -513,28 +514,30 @@ module.exports = grammar({
$._select_statement,
),

create_materialized_view: $ => seq(
$.keyword_create,
optional($._or_replace),
$.keyword_materialized,
$.keyword_view,
optional($._if_not_exists),
$.table_reference,
$.keyword_as,
$._select_statement,
optional(
choice(
seq(
$.keyword_with,
$.keyword_data,
),
seq(
$.keyword_with,
$.keyword_no,
$.keyword_data,
create_materialized_view: $ => prec.right(
seq(
$.keyword_create,
optional($._or_replace),
$.keyword_materialized,
$.keyword_view,
optional($._if_not_exists),
$.table_reference,
$.keyword_as,
$._select_statement,
optional(
choice(
seq(
$.keyword_with,
$.keyword_data,
),
seq(
$.keyword_with,
$.keyword_no,
$.keyword_data,
)
)
)
)
),
),

create_index: $ => seq(
Expand Down
236 changes: 128 additions & 108 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1545,8 +1545,16 @@
]
},
{
"type": "STRING",
"value": ";"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down Expand Up @@ -1964,23 +1972,31 @@
"name": "all_fields"
},
{
"type": "SEQ",
"type": "SYMBOL",
"name": "term"
}
]
},
"term": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
"name": "_alias"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_alias"
},
{
"type": "BLANK"
}
]
"type": "BLANK"
}
]
}
Expand Down Expand Up @@ -2311,100 +2327,104 @@
]
},
"create_materialized_view": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_create"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_or_replace"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "keyword_materialized"
},
{
"type": "SYMBOL",
"name": "keyword_view"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_if_not_exists"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "table_reference"
},
{
"type": "SYMBOL",
"name": "keyword_as"
},
{
"type": "SYMBOL",
"name": "_select_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_with"
},
{
"type": "SYMBOL",
"name": "keyword_data"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_with"
},
{
"type": "SYMBOL",
"name": "keyword_no"
},
{
"type": "SYMBOL",
"name": "keyword_data"
}
]
}
]
},
{
"type": "BLANK"
}
]
}
]
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_create"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_or_replace"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "keyword_materialized"
},
{
"type": "SYMBOL",
"name": "keyword_view"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_if_not_exists"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "table_reference"
},
{
"type": "SYMBOL",
"name": "keyword_as"
},
{
"type": "SYMBOL",
"name": "_select_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_with"
},
{
"type": "SYMBOL",
"name": "keyword_data"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_with"
},
{
"type": "SYMBOL",
"name": "keyword_no"
},
{
"type": "SYMBOL",
"name": "keyword_data"
}
]
}
]
},
{
"type": "BLANK"
}
]
}
]
}
},
"create_index": {
"type": "SEQ",
Expand Down
Loading

0 comments on commit 56d3374

Please sign in to comment.