Skip to content

Commit

Permalink
parser: parse extended for statements as for_phrase
Browse files Browse the repository at this point in the history
Fixes #27
  • Loading branch information
jkbz64 committed Jan 16, 2024
1 parent 5ca0a26 commit 4a6c8cb
Show file tree
Hide file tree
Showing 5 changed files with 49,302 additions and 43,544 deletions.
15 changes: 15 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,20 @@ module.exports = grammar({
sort_clause: ($) =>
seq(optional(kw("BREAK")), seq(kw("BY"), repeat1($.sort_column))),

for_phrase: ($) =>
seq(
field("type", choice(kw("EACH"), kw("FIRST"), kw("LAST"))),
field("table", choice($.identifier, $.qualified_name)),
optional($.of),
optional($._pre_tuning),
optional($.where_clause),
repeat($.query_tuning),
optional(repeat($.sort_clause)),
optional($.on_error_phrase),
optional($.on_quit_phrase),
optional($.on_stop_phrase)
),

for_statement: ($) =>
seq(
optional($.label),
Expand All @@ -709,6 +723,7 @@ module.exports = grammar({
optional($.on_error_phrase),
optional($.on_quit_phrase),
optional($.on_stop_phrase),
repeat(seq(",", $.for_phrase)),
":",
optional($.body),
$._block_terminator
Expand Down
189 changes: 189 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -5477,6 +5477,179 @@
}
]
},
"for_phrase": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[eE][aA][cC][hH]"
}
}
},
"named": false,
"value": "EACH"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[fF][iI][rR][sS][tT]"
}
}
},
"named": false,
"value": "FIRST"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[lL][aA][sS][tT]"
}
}
},
"named": false,
"value": "LAST"
}
]
}
},
{
"type": "FIELD",
"name": "table",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "qualified_name"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "of"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_pre_tuning"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "where_clause"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "query_tuning"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "sort_clause"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "on_error_phrase"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "on_quit_phrase"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "on_stop_phrase"
},
{
"type": "BLANK"
}
]
}
]
},
"for_statement": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -5676,6 +5849,22 @@
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "for_phrase"
}
]
}
},
{
"type": "STRING",
"value": ":"
Expand Down
76 changes: 76 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,78 @@
]
}
},
{
"type": "for_phrase",
"named": true,
"fields": {
"table": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "qualified_name",
"named": true
}
]
},
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "EACH",
"named": false
},
{
"type": "FIRST",
"named": false
},
{
"type": "LAST",
"named": false
}
]
}
},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "of",
"named": true
},
{
"type": "on_error_phrase",
"named": true
},
{
"type": "on_quit_phrase",
"named": true
},
{
"type": "on_stop_phrase",
"named": true
},
{
"type": "query_tuning",
"named": true
},
{
"type": "sort_clause",
"named": true
},
{
"type": "where_clause",
"named": true
}
]
}
},
{
"type": "for_statement",
"named": true,
Expand Down Expand Up @@ -1119,6 +1191,10 @@
"type": "body",
"named": true
},
{
"type": "for_phrase",
"named": true
},
{
"type": "label",
"named": true
Expand Down
Loading

0 comments on commit 4a6c8cb

Please sign in to comment.