Skip to content

Commit 18f6c6c

Browse files
committed
Use the same AST node for all identifiers
1 parent 3cf73a2 commit 18f6c6c

File tree

7 files changed

+176487
-188780
lines changed

7 files changed

+176487
-188780
lines changed

grammar.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ const RESERVED_WORD_TOKENS = [
7575
["after", "catch", "do", "else", "end", "fn", "rescue"],
7676
].flat();
7777

78-
const SPECIAL_IDENTIFIERS = [
79-
"__MODULE__",
80-
"__DIR__",
81-
"__ENV__",
82-
"__CALLER__",
83-
"__STACKTRACE__",
84-
];
85-
8678
const DIGITS = /[0-9]+/;
8779
const BIN_DIGITS = /[0-1]+/;
8880
const OCT_DIGITS = /[0-7]+/;
@@ -208,7 +200,7 @@ module.exports = grammar({
208200
_expression: ($) =>
209201
choice(
210202
$.block,
211-
$._identifier,
203+
$.identifier,
212204
$.alias,
213205
$.integer,
214206
$.float,
@@ -247,20 +239,13 @@ module.exports = grammar({
247239
")"
248240
),
249241

250-
_identifier: ($) =>
251-
choice($.identifier, $.unused_identifier, $.special_identifier),
252-
253242
identifier: ($) =>
254243
choice(
255244
// See Ref 6. in the docs
256-
/[\p{Ll}\p{Lm}\p{Lo}\p{Nl}\u1885\u1886\u2118\u212E\u309B\u309C][\p{ID_Continue}]*[?!]?/u,
245+
/[_\p{Ll}\p{Lm}\p{Lo}\p{Nl}\u1885\u1886\u2118\u212E\u309B\u309C][\p{ID_Continue}]*[?!]?/u,
257246
"..."
258247
),
259248

260-
unused_identifier: ($) => /_[\p{ID_Continue}]*[?!]?/u,
261-
262-
special_identifier: ($) => choice(...SPECIAL_IDENTIFIERS),
263-
264249
alias: ($) => token(sep1(/[A-Z][_a-zA-Z0-9]*/, /\s*\.\s*/)),
265250

266251
integer: ($) => token(INTEGER),
@@ -422,7 +407,7 @@ module.exports = grammar({
422407
choice(
423408
$.alias,
424409
$._atom,
425-
$._identifier,
410+
$.identifier,
426411
$.unary_operator,
427412
$.dot,
428413
alias($._call_with_parentheses, $.call)
@@ -572,7 +557,7 @@ module.exports = grammar({
572557
_local_call_without_parentheses: ($) =>
573558
prec.left(
574559
seq(
575-
field("target", $._identifier),
560+
field("target", $.identifier),
576561
alias($._call_arguments_without_parentheses, $.arguments),
577562
optional(seq(optional($._newline_before_do), $.do_block))
578563
)
@@ -581,15 +566,15 @@ module.exports = grammar({
581566
_local_call_with_parentheses: ($) =>
582567
prec.left(
583568
seq(
584-
field("target", $._identifier),
569+
field("target", $.identifier),
585570
alias($._call_arguments_with_parentheses_immediate, $.arguments),
586571
optional(seq(optional($._newline_before_do), $.do_block))
587572
)
588573
),
589574

590575
_local_call_just_do_block: ($) =>
591576
// Lower precedence than identifier, because `foo bar do` is `foo(bar) do end`
592-
prec(-1, seq(field("target", $._identifier), $.do_block)),
577+
prec(-1, seq(field("target", $.identifier), $.do_block)),
593578

594579
_remote_call_without_parentheses: ($) =>
595580
prec.left(
@@ -618,7 +603,7 @@ module.exports = grammar({
618603
field(
619604
"right",
620605
choice(
621-
$._identifier,
606+
$.identifier,
622607
alias(choice(...RESERVED_WORD_TOKENS), $.identifier),
623608
$.operator_identifier,
624609
alias($._quoted_i_double, $.string),

src/grammar.json

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
},
110110
{
111111
"type": "SYMBOL",
112-
"name": "_identifier"
112+
"name": "identifier"
113113
},
114114
{
115115
"type": "SYMBOL",
@@ -318,65 +318,19 @@
318318
}
319319
]
320320
},
321-
"_identifier": {
322-
"type": "CHOICE",
323-
"members": [
324-
{
325-
"type": "SYMBOL",
326-
"name": "identifier"
327-
},
328-
{
329-
"type": "SYMBOL",
330-
"name": "unused_identifier"
331-
},
332-
{
333-
"type": "SYMBOL",
334-
"name": "special_identifier"
335-
}
336-
]
337-
},
338321
"identifier": {
339322
"type": "CHOICE",
340323
"members": [
341324
{
342325
"type": "PATTERN",
343-
"value": "[\\p{Ll}\\p{Lm}\\p{Lo}\\p{Nl}\\u1885\\u1886\\u2118\\u212E\\u309B\\u309C][\\p{ID_Continue}]*[?!]?"
326+
"value": "[_\\p{Ll}\\p{Lm}\\p{Lo}\\p{Nl}\\u1885\\u1886\\u2118\\u212E\\u309B\\u309C][\\p{ID_Continue}]*[?!]?"
344327
},
345328
{
346329
"type": "STRING",
347330
"value": "..."
348331
}
349332
]
350333
},
351-
"unused_identifier": {
352-
"type": "PATTERN",
353-
"value": "_[\\p{ID_Continue}]*[?!]?"
354-
},
355-
"special_identifier": {
356-
"type": "CHOICE",
357-
"members": [
358-
{
359-
"type": "STRING",
360-
"value": "__MODULE__"
361-
},
362-
{
363-
"type": "STRING",
364-
"value": "__DIR__"
365-
},
366-
{
367-
"type": "STRING",
368-
"value": "__ENV__"
369-
},
370-
{
371-
"type": "STRING",
372-
"value": "__CALLER__"
373-
},
374-
{
375-
"type": "STRING",
376-
"value": "__STACKTRACE__"
377-
}
378-
]
379-
},
380334
"alias": {
381335
"type": "TOKEN",
382336
"content": {
@@ -2695,7 +2649,7 @@
26952649
},
26962650
{
26972651
"type": "SYMBOL",
2698-
"name": "_identifier"
2652+
"name": "identifier"
26992653
},
27002654
{
27012655
"type": "SYMBOL",
@@ -4195,7 +4149,7 @@
41954149
"name": "target",
41964150
"content": {
41974151
"type": "SYMBOL",
4198-
"name": "_identifier"
4152+
"name": "identifier"
41994153
}
42004154
},
42014155
{
@@ -4250,7 +4204,7 @@
42504204
"name": "target",
42514205
"content": {
42524206
"type": "SYMBOL",
4253-
"name": "_identifier"
4207+
"name": "identifier"
42544208
}
42554209
},
42564210
{
@@ -4305,7 +4259,7 @@
43054259
"name": "target",
43064260
"content": {
43074261
"type": "SYMBOL",
4308-
"name": "_identifier"
4262+
"name": "identifier"
43094263
}
43104264
},
43114265
{
@@ -4473,7 +4427,7 @@
44734427
"members": [
44744428
{
44754429
"type": "SYMBOL",
4476-
"name": "_identifier"
4430+
"name": "identifier"
44774431
},
44784432
{
44794433
"type": "ALIAS",

0 commit comments

Comments
 (0)