Skip to content

Commit cbd998c

Browse files
committed
Move constant_suffix and identifier_suffix to scanner
1 parent 6fa6332 commit cbd998c

File tree

5 files changed

+320620
-308922
lines changed

5 files changed

+320620
-308922
lines changed

grammar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ module.exports = grammar({
6262
$._binary_star,
6363
$._singleton_class_left_angle_left_langle,
6464
$.hash_key_symbol,
65+
$._identifier_suffix,
66+
$._constant_suffix,
6567
$._hash_splat_star_star,
6668
$._binary_star_star,
6769
$._element_reference_bracket,
@@ -1054,9 +1056,9 @@ module.exports = grammar({
10541056
nil: $ => 'nil',
10551057

10561058
constant: $ => token(seq(/[A-Z]/, IDENTIFIER_CHARS)),
1057-
constant_suffix: $ => token(seq(/[A-Z]/, IDENTIFIER_CHARS, /[?!]/)),
1059+
constant_suffix: $ => choice(token(seq(/[A-Z]/, IDENTIFIER_CHARS, /[?]/)), $._constant_suffix),
10581060
identifier: $ => token(seq(LOWER_ALPHA_CHAR, IDENTIFIER_CHARS)),
1059-
identifier_suffix: $ => token(seq(LOWER_ALPHA_CHAR, IDENTIFIER_CHARS, /[?!]/)),
1061+
identifier_suffix: $ => choice(token(seq(LOWER_ALPHA_CHAR, IDENTIFIER_CHARS, /[?]/)), $._identifier_suffix),
10601062
instance_variable: $ => token(seq('@', ALPHA_CHAR, IDENTIFIER_CHARS)),
10611063
class_variable: $ => token(seq('@@', ALPHA_CHAR, IDENTIFIER_CHARS)),
10621064

src/grammar.json

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6893,24 +6893,33 @@
68936893
}
68946894
},
68956895
"constant_suffix": {
6896-
"type": "TOKEN",
6897-
"content": {
6898-
"type": "SEQ",
6899-
"members": [
6900-
{
6901-
"type": "PATTERN",
6902-
"value": "[A-Z]"
6903-
},
6904-
{
6905-
"type": "PATTERN",
6906-
"value": "[^\\x00-\\x1F\\s:;`\"'@$#.,|^&<=>+\\-*/\\\\%?!~()\\[\\]{}]*"
6907-
},
6908-
{
6909-
"type": "PATTERN",
6910-
"value": "[?!]"
6896+
"type": "CHOICE",
6897+
"members": [
6898+
{
6899+
"type": "TOKEN",
6900+
"content": {
6901+
"type": "SEQ",
6902+
"members": [
6903+
{
6904+
"type": "PATTERN",
6905+
"value": "[A-Z]"
6906+
},
6907+
{
6908+
"type": "PATTERN",
6909+
"value": "[^\\x00-\\x1F\\s:;`\"'@$#.,|^&<=>+\\-*/\\\\%?!~()\\[\\]{}]*"
6910+
},
6911+
{
6912+
"type": "PATTERN",
6913+
"value": "[?]"
6914+
}
6915+
]
69116916
}
6912-
]
6913-
}
6917+
},
6918+
{
6919+
"type": "SYMBOL",
6920+
"name": "_constant_suffix"
6921+
}
6922+
]
69146923
},
69156924
"identifier": {
69166925
"type": "TOKEN",
@@ -6929,24 +6938,33 @@
69296938
}
69306939
},
69316940
"identifier_suffix": {
6932-
"type": "TOKEN",
6933-
"content": {
6934-
"type": "SEQ",
6935-
"members": [
6936-
{
6937-
"type": "PATTERN",
6938-
"value": "[^\\x00-\\x1F\\sA-Z0-9:;`\"'@$#.,|^&<=>+\\-*/\\\\%?!~()\\[\\]{}]"
6939-
},
6940-
{
6941-
"type": "PATTERN",
6942-
"value": "[^\\x00-\\x1F\\s:;`\"'@$#.,|^&<=>+\\-*/\\\\%?!~()\\[\\]{}]*"
6943-
},
6944-
{
6945-
"type": "PATTERN",
6946-
"value": "[?!]"
6941+
"type": "CHOICE",
6942+
"members": [
6943+
{
6944+
"type": "TOKEN",
6945+
"content": {
6946+
"type": "SEQ",
6947+
"members": [
6948+
{
6949+
"type": "PATTERN",
6950+
"value": "[^\\x00-\\x1F\\sA-Z0-9:;`\"'@$#.,|^&<=>+\\-*/\\\\%?!~()\\[\\]{}]"
6951+
},
6952+
{
6953+
"type": "PATTERN",
6954+
"value": "[^\\x00-\\x1F\\s:;`\"'@$#.,|^&<=>+\\-*/\\\\%?!~()\\[\\]{}]*"
6955+
},
6956+
{
6957+
"type": "PATTERN",
6958+
"value": "[?]"
6959+
}
6960+
]
69476961
}
6948-
]
6949-
}
6962+
},
6963+
{
6964+
"type": "SYMBOL",
6965+
"name": "_identifier_suffix"
6966+
}
6967+
]
69506968
},
69516969
"instance_variable": {
69526970
"type": "TOKEN",
@@ -7893,6 +7911,14 @@
78937911
"type": "SYMBOL",
78947912
"name": "hash_key_symbol"
78957913
},
7914+
{
7915+
"type": "SYMBOL",
7916+
"name": "_identifier_suffix"
7917+
},
7918+
{
7919+
"type": "SYMBOL",
7920+
"name": "_constant_suffix"
7921+
},
78967922
{
78977923
"type": "SYMBOL",
78987924
"name": "_hash_splat_star_star"

src/node-types.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,11 @@
14451445
}
14461446
}
14471447
},
1448+
{
1449+
"type": "constant",
1450+
"named": true,
1451+
"fields": {}
1452+
},
14481453
{
14491454
"type": "delimited_symbol",
14501455
"named": true,
@@ -1896,6 +1901,11 @@
18961901
]
18971902
}
18981903
},
1904+
{
1905+
"type": "hash_key_symbol",
1906+
"named": true,
1907+
"fields": {}
1908+
},
18991909
{
19001910
"type": "hash_pattern",
19011911
"named": true,
@@ -1993,6 +2003,11 @@
19932003
]
19942004
}
19952005
},
2006+
{
2007+
"type": "identifier",
2008+
"named": true,
2009+
"fields": {}
2010+
},
19962011
{
19972012
"type": "if",
19982013
"named": true,
@@ -3837,10 +3852,6 @@
38373852
"type": "comment",
38383853
"named": true
38393854
},
3840-
{
3841-
"type": "constant",
3842-
"named": true
3843-
},
38443855
{
38453856
"type": "def",
38463857
"named": false
@@ -3897,10 +3908,6 @@
38973908
"type": "global_variable",
38983909
"named": true
38993910
},
3900-
{
3901-
"type": "hash_key_symbol",
3902-
"named": true
3903-
},
39043911
{
39053912
"type": "heredoc_beginning",
39063913
"named": true
@@ -3917,10 +3924,6 @@
39173924
"type": "i",
39183925
"named": false
39193926
},
3920-
{
3921-
"type": "identifier",
3922-
"named": true
3923-
},
39243927
{
39253928
"type": "if",
39263929
"named": false

0 commit comments

Comments
 (0)