Skip to content

Commit

Permalink
parser: add on error phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbz64 committed Dec 14, 2023
1 parent 000ef0e commit c18c8e7
Show file tree
Hide file tree
Showing 5 changed files with 23,840 additions and 23,278 deletions.
18 changes: 17 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,22 @@ module.exports = grammar({
$._terminator
),

on_error_phrase: ($) =>
seq(
kw("ON"),
kw("ERROR"),
kw("UNDO"),
field("label", optional($.identifier)),
",",
choice(
seq(kw("LEAVE"), field("label", optional($.identifier))),
seq(kw("NEXT"), field("label", optional($.identifier))),
seq(kw("RETRY"), field("label", optional($.identifier))),
seq(kw("RETURN"), choice(seq(kw("ERROR")), kw("NO-APPLY"))),
kw("THROW")
)
),

on_stop_phrase: ($) =>
seq(
kw("ON"),
Expand Down Expand Up @@ -617,7 +633,7 @@ module.exports = grammar({
do_block: ($) =>
seq(
kw("DO"),
optional(choice($.on_stop_phrase, $.on_quit_phrase)),
optional(choice($.on_error_phrase, $.on_stop_phrase, $.on_quit_phrase)),
":",
optional($.body),
$._block_terminator
Expand Down
272 changes: 272 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4193,6 +4193,274 @@
}
]
},
"on_error_phrase": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[oO][nN]"
}
}
},
"named": false,
"value": "ON"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[eE][rR][rR][oO][rR]"
}
}
},
"named": false,
"value": "ERROR"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[uU][nN][dD][oO]"
}
}
},
"named": false,
"value": "UNDO"
},
{
"type": "FIELD",
"name": "label",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
"value": ","
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[lL][eE][aA][vV][eE]"
}
}
},
"named": false,
"value": "LEAVE"
},
{
"type": "FIELD",
"name": "label",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "BLANK"
}
]
}
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[nN][eE][xX][tT]"
}
}
},
"named": false,
"value": "NEXT"
},
{
"type": "FIELD",
"name": "label",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "BLANK"
}
]
}
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[rR][eE][tT][rR][yY]"
}
}
},
"named": false,
"value": "RETRY"
},
{
"type": "FIELD",
"name": "label",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "BLANK"
}
]
}
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[rR][eE][tT][uU][rR][nN]"
}
}
},
"named": false,
"value": "RETURN"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[eE][rR][rR][oO][rR]"
}
}
},
"named": false,
"value": "ERROR"
}
]
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[nN][oO][--][aA][pP][pP][lL][yY]"
}
}
},
"named": false,
"value": "NO-APPLY"
}
]
}
]
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[tT][hH][rR][oO][wW]"
}
}
},
"named": false,
"value": "THROW"
}
]
}
]
},
"on_stop_phrase": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -4731,6 +4999,10 @@
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "on_error_phrase"
},
{
"type": "SYMBOL",
"name": "on_stop_phrase"
Expand Down
20 changes: 20 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,10 @@
"type": "body",
"named": true
},
{
"type": "on_error_phrase",
"named": true
},
{
"type": "on_quit_phrase",
"named": true
Expand Down Expand Up @@ -1596,6 +1600,22 @@
]
}
},
{
"type": "on_error_phrase",
"named": true,
"fields": {
"label": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
}
},
{
"type": "on_quit_phrase",
"named": true,
Expand Down
Loading

0 comments on commit c18c8e7

Please sign in to comment.