Skip to content

Commit 64de06a

Browse files
committed
refactor: reduce case count
1 parent 83df164 commit 64de06a

File tree

3 files changed

+285381
-290943
lines changed

3 files changed

+285381
-290943
lines changed

grammar.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,27 +1933,22 @@ function _range_rule(anonymous) {
19331933
* @param {string} type
19341934
*/
19351935
function _unquoted_with_expr_rule(type) {
1936-
let excluded = '';
1937-
switch (type) {
1938-
case 'list':
1939-
excluded += '\\[\\],';
1940-
break;
1941-
case 'record':
1942-
excluded += '{}:,';
1943-
break;
1944-
}
1945-
const pattern_repeat = token.immediate(repeat(none_of(excluded)));
1946-
const pattern_repeat1 = token.immediate(repeat1(none_of(excluded)));
19471936
return ($) => {
19481937
let unquoted_head = $.unquoted;
1938+
let excluded = '';
19491939
switch (type) {
19501940
case 'list':
19511941
unquoted_head = $._unquoted_in_list;
1942+
excluded += '\\[\\],';
19521943
break;
19531944
case 'record':
19541945
unquoted_head = $._unquoted_in_record;
1946+
excluded += '{}:,';
19551947
break;
19561948
}
1949+
const pattern_once = token.immediate(none_of(excluded));
1950+
const pattern_repeat = token.immediate(repeat(none_of(excluded)));
1951+
19571952
return seq(
19581953
choice(
19591954
seq(
@@ -1968,7 +1963,7 @@ function _unquoted_with_expr_rule(type) {
19681963
seq(
19691964
$.expr_parenthesized,
19701965
choice(
1971-
pattern_repeat1,
1966+
pattern_once,
19721967
alias($._expr_parenthesized_immediate, $.expr_parenthesized),
19731968
),
19741969
),

src/grammar.json

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17390,11 +17390,8 @@
1739017390
{
1739117391
"type": "IMMEDIATE_TOKEN",
1739217392
"content": {
17393-
"type": "REPEAT1",
17394-
"content": {
17395-
"type": "PATTERN",
17396-
"value": "[^\\s\\r\\n\\t\\|();]"
17397-
}
17393+
"type": "PATTERN",
17394+
"value": "[^\\s\\r\\n\\t\\|();]"
1739817395
}
1739917396
},
1740017397
{
@@ -17510,11 +17507,8 @@
1751017507
{
1751117508
"type": "IMMEDIATE_TOKEN",
1751217509
"content": {
17513-
"type": "REPEAT1",
17514-
"content": {
17515-
"type": "PATTERN",
17516-
"value": "[^\\s\\r\\n\\t\\|();\\[\\],]"
17517-
}
17510+
"type": "PATTERN",
17511+
"value": "[^\\s\\r\\n\\t\\|();\\[\\],]"
1751817512
}
1751917513
},
1752017514
{
@@ -17630,11 +17624,8 @@
1763017624
{
1763117625
"type": "IMMEDIATE_TOKEN",
1763217626
"content": {
17633-
"type": "REPEAT1",
17634-
"content": {
17635-
"type": "PATTERN",
17636-
"value": "[^\\s\\r\\n\\t\\|();{}:,]"
17637-
}
17627+
"type": "PATTERN",
17628+
"value": "[^\\s\\r\\n\\t\\|();{}:,]"
1763817629
}
1763917630
},
1764017631
{

0 commit comments

Comments
 (0)