Skip to content

Commit

Permalink
parser: fix logical operator quirks with external scanner
Browse files Browse the repository at this point in the history
Fixes #28, not sure if it's the right way with external scanner but it's
definitely better than the ugly operator variant
  • Loading branch information
jkbz64 committed Feb 23, 2024
1 parent 580f9b3 commit 04254df
Show file tree
Hide file tree
Showing 5 changed files with 86,731 additions and 90,421 deletions.
7 changes: 2 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function kw(keyword) {
module.exports = grammar({
name: "abl",

externals: ($) => [$._namedot, $._namecolon],
externals: ($) => [$._namedot, $._namecolon, $._or_operator, $._and_operator],
extras: ($) => [$.comment, $.include, /[\s\f\uFEFF\u2060\u200B]|\\\r?\n/],
word: ($) => $.identifier,
supertypes: ($) => [$._expression, $._statement, $._terminated_statement],
Expand Down Expand Up @@ -92,10 +92,7 @@ module.exports = grammar({

_logical_operator: ($) =>
prec.left(
choice(
choice(kw(" AND "), kw(" AND\n"), kw(" AND\r\n")),
choice(kw(" OR "), kw(" OR\n"), kw(" OR\r\n"))
)
choice(alias($._and_operator, "AND"), alias($._or_operator, "OR"))
),
logical_expression: ($) =>
prec.right(
Expand Down
124 changes: 22 additions & 102 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,110 +377,22 @@
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[ ][aA][nN][dD][ ]"
}
}
},
"named": false,
"value": " AND "
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[ ][aA][nN][dD][\\n\\n]"
}
}
},
"named": false,
"value": " AND\n"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[ ][aA][nN][dD][\\r\\r][\\n\\n]"
}
}
},
"named": false,
"value": " AND\r\n"
}
]
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_and_operator"
},
"named": false,
"value": "AND"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[ ][oO][rR][ ]"
}
}
},
"named": false,
"value": " OR "
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[ ][oO][rR][\\n\\n]"
}
}
},
"named": false,
"value": " OR\n"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[ ][oO][rR][\\r\\r][\\n\\n]"
}
}
},
"named": false,
"value": " OR\r\n"
}
]
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_or_operator"
},
"named": false,
"value": "OR"
}
]
}
Expand Down Expand Up @@ -11607,6 +11519,14 @@
{
"type": "SYMBOL",
"name": "_namecolon"
},
{
"type": "SYMBOL",
"name": "_or_operator"
},
{
"type": "SYMBOL",
"name": "_and_operator"
}
],
"inline": [],
Expand Down
28 changes: 4 additions & 24 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -3119,30 +3119,6 @@
"type": " ",
"named": false
},
{
"type": " AND\n",
"named": false
},
{
"type": " AND\r\n",
"named": false
},
{
"type": " AND ",
"named": false
},
{
"type": " OR\n",
"named": false
},
{
"type": " OR\r\n",
"named": false
},
{
"type": " OR ",
"named": false
},
{
"type": "\"",
"named": false
Expand Down Expand Up @@ -3731,6 +3707,10 @@
"type": "ON",
"named": false
},
{
"type": "OR",
"named": false
},
{
"type": "OTHERWISE",
"named": false
Expand Down
Loading

0 comments on commit 04254df

Please sign in to comment.