Use the same AST node for all identifiers

This commit is contained in:
Jonatan Kłosko 2021-09-29 12:44:04 +02:00
parent 3cf73a2529
commit 18f6c6cc5d
7 changed files with 300008 additions and 312301 deletions

View File

@ -75,14 +75,6 @@ const RESERVED_WORD_TOKENS = [
["after", "catch", "do", "else", "end", "fn", "rescue"],
].flat();
const SPECIAL_IDENTIFIERS = [
"__MODULE__",
"__DIR__",
"__ENV__",
"__CALLER__",
"__STACKTRACE__",
];
const DIGITS = /[0-9]+/;
const BIN_DIGITS = /[0-1]+/;
const OCT_DIGITS = /[0-7]+/;
@ -208,7 +200,7 @@ module.exports = grammar({
_expression: ($) =>
choice(
$.block,
$._identifier,
$.identifier,
$.alias,
$.integer,
$.float,
@ -247,20 +239,13 @@ module.exports = grammar({
")"
),
_identifier: ($) =>
choice($.identifier, $.unused_identifier, $.special_identifier),
identifier: ($) =>
choice(
// See Ref 6. in the docs
/[\p{Ll}\p{Lm}\p{Lo}\p{Nl}\u1885\u1886\u2118\u212E\u309B\u309C][\p{ID_Continue}]*[?!]?/u,
/[_\p{Ll}\p{Lm}\p{Lo}\p{Nl}\u1885\u1886\u2118\u212E\u309B\u309C][\p{ID_Continue}]*[?!]?/u,
"..."
),
unused_identifier: ($) => /_[\p{ID_Continue}]*[?!]?/u,
special_identifier: ($) => choice(...SPECIAL_IDENTIFIERS),
alias: ($) => token(sep1(/[A-Z][_a-zA-Z0-9]*/, /\s*\.\s*/)),
integer: ($) => token(INTEGER),
@ -422,7 +407,7 @@ module.exports = grammar({
choice(
$.alias,
$._atom,
$._identifier,
$.identifier,
$.unary_operator,
$.dot,
alias($._call_with_parentheses, $.call)
@ -572,7 +557,7 @@ module.exports = grammar({
_local_call_without_parentheses: ($) =>
prec.left(
seq(
field("target", $._identifier),
field("target", $.identifier),
alias($._call_arguments_without_parentheses, $.arguments),
optional(seq(optional($._newline_before_do), $.do_block))
)
@ -581,7 +566,7 @@ module.exports = grammar({
_local_call_with_parentheses: ($) =>
prec.left(
seq(
field("target", $._identifier),
field("target", $.identifier),
alias($._call_arguments_with_parentheses_immediate, $.arguments),
optional(seq(optional($._newline_before_do), $.do_block))
)
@ -589,7 +574,7 @@ module.exports = grammar({
_local_call_just_do_block: ($) =>
// Lower precedence than identifier, because `foo bar do` is `foo(bar) do end`
prec(-1, seq(field("target", $._identifier), $.do_block)),
prec(-1, seq(field("target", $.identifier), $.do_block)),
_remote_call_without_parentheses: ($) =>
prec.left(
@ -618,7 +603,7 @@ module.exports = grammar({
field(
"right",
choice(
$._identifier,
$.identifier,
alias(choice(...RESERVED_WORD_TOKENS), $.identifier),
$.operator_identifier,
alias($._quoted_i_double, $.string),

View File

@ -109,7 +109,7 @@
},
{
"type": "SYMBOL",
"name": "_identifier"
"name": "identifier"
},
{
"type": "SYMBOL",
@ -318,29 +318,12 @@
}
]
},
"_identifier": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "unused_identifier"
},
{
"type": "SYMBOL",
"name": "special_identifier"
}
]
},
"identifier": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[\\p{Ll}\\p{Lm}\\p{Lo}\\p{Nl}\\u1885\\u1886\\u2118\\u212E\\u309B\\u309C][\\p{ID_Continue}]*[?!]?"
"value": "[_\\p{Ll}\\p{Lm}\\p{Lo}\\p{Nl}\\u1885\\u1886\\u2118\\u212E\\u309B\\u309C][\\p{ID_Continue}]*[?!]?"
},
{
"type": "STRING",
@ -348,35 +331,6 @@
}
]
},
"unused_identifier": {
"type": "PATTERN",
"value": "_[\\p{ID_Continue}]*[?!]?"
},
"special_identifier": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "__MODULE__"
},
{
"type": "STRING",
"value": "__DIR__"
},
{
"type": "STRING",
"value": "__ENV__"
},
{
"type": "STRING",
"value": "__CALLER__"
},
{
"type": "STRING",
"value": "__STACKTRACE__"
}
]
},
"alias": {
"type": "TOKEN",
"content": {
@ -2695,7 +2649,7 @@
},
{
"type": "SYMBOL",
"name": "_identifier"
"name": "identifier"
},
{
"type": "SYMBOL",
@ -4195,7 +4149,7 @@
"name": "target",
"content": {
"type": "SYMBOL",
"name": "_identifier"
"name": "identifier"
}
},
{
@ -4250,7 +4204,7 @@
"name": "target",
"content": {
"type": "SYMBOL",
"name": "_identifier"
"name": "identifier"
}
},
{
@ -4305,7 +4259,7 @@
"name": "target",
"content": {
"type": "SYMBOL",
"name": "_identifier"
"name": "identifier"
}
},
{
@ -4473,7 +4427,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_identifier"
"name": "identifier"
},
{
"type": "ALIAS",

View File

@ -87,10 +87,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -102,10 +98,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
},
@ -193,10 +185,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -208,10 +196,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -305,10 +289,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "stab_clause",
"named": true
@ -324,10 +304,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -439,10 +415,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -454,10 +426,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -558,10 +526,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -573,10 +537,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
},
@ -854,10 +814,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -869,10 +825,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -970,10 +922,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -985,10 +933,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -1081,10 +1025,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "stab_clause",
"named": true
@ -1100,10 +1040,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -1196,10 +1132,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -1211,10 +1143,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -1243,14 +1171,6 @@
{
"type": "identifier",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -1358,10 +1278,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "stab_clause",
"named": true
@ -1377,10 +1293,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -1541,10 +1453,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "stab_clause",
"named": true
@ -1560,10 +1468,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -1656,10 +1560,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -1671,10 +1571,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
},
@ -1708,10 +1604,6 @@
"type": "operator_identifier",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -1719,10 +1611,6 @@
{
"type": "tuple",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -1816,10 +1704,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "stab_clause",
"named": true
@ -1835,10 +1719,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -1936,10 +1816,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -1951,10 +1827,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -2066,10 +1938,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -2081,10 +1949,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -2200,10 +2064,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -2215,10 +2075,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -2335,10 +2191,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -2350,10 +2202,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -2551,10 +2399,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "stab_clause",
"named": true
@ -2570,10 +2414,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -2790,10 +2630,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -2805,19 +2641,10 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
},
{
"type": "special_identifier",
"named": true,
"fields": {}
},
{
"type": "stab_clause",
"named": true,
@ -2942,17 +2769,9 @@
"type": "quoted_atom",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -3049,10 +2868,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -3064,10 +2879,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
}
@ -3168,10 +2979,6 @@
"type": "sigil",
"named": true
},
{
"type": "special_identifier",
"named": true
},
{
"type": "string",
"named": true
@ -3183,10 +2990,6 @@
{
"type": "unary_operator",
"named": true
},
{
"type": "unused_identifier",
"named": true
}
]
},
@ -3458,26 +3261,6 @@
"type": "^^^",
"named": false
},
{
"type": "__CALLER__",
"named": false
},
{
"type": "__DIR__",
"named": false
},
{
"type": "__ENV__",
"named": false
},
{
"type": "__MODULE__",
"named": false
},
{
"type": "__STACKTRACE__",
"named": false
},
{
"type": "after",
"named": false
@ -3578,10 +3361,6 @@
"type": "true",
"named": false
},
{
"type": "unused_identifier",
"named": true
},
{
"type": "when",
"named": false

611981
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@ -80,5 +80,5 @@ __MODULE__.Child
(source
(dot
(special_identifier)
(identifier)
(alias)))

View File

@ -146,7 +146,7 @@ unused struct identifier
(source
(map
(struct
(unused_identifier))))
(identifier))))
=====================================
matching struct identifier
@ -187,11 +187,11 @@ with special identifier
(source
(map
(struct
(special_identifier)))
(identifier)))
(map
(struct
(dot
(special_identifier)
(identifier)
(alias)))))
=====================================

View File

@ -34,9 +34,9 @@ __TEST__
---
(source
(unused_identifier)
(unused_identifier)
(unused_identifier))
(identifier)
(identifier)
(identifier))
=====================================
three dots identifier
@ -59,5 +59,5 @@ __DIR__
---
(source
(special_identifier)
(special_identifier))
(identifier)
(identifier))