Skip to content

Commit 08ec53f

Browse files
Allow identifiers with trailing ? or ! in more places
1 parent 6172504 commit 08ec53f

7 files changed

+976015
-959980
lines changed

grammar.js

+78-12
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,18 @@ module.exports = grammar({
285285
$.pseudo_call_argument_list,
286286
$._parenthesized_type,
287287
],
288+
289+
// Ternary has precedence over type declaration
290+
[
291+
$.call,
292+
$.type_declaration,
293+
],
294+
295+
// Want to prefer identifiers ending with `?`
296+
[
297+
$.identifier_method_call,
298+
$.identifier,
299+
],
288300
],
289301

290302
conflicts: $ => [
@@ -981,6 +993,7 @@ module.exports = grammar({
981993
method_proc: $ => {
982994
const receiver = field('receiver', choice(
983995
$.identifier,
996+
alias($.identifier_method_call, $.identifier),
984997
$.instance_var,
985998
$.class_var,
986999
$.self,
@@ -1180,7 +1193,10 @@ module.exports = grammar({
11801193
},
11811194

11821195
fun_param: $ => {
1183-
const name = field('name', choice($.identifier, $.constant))
1196+
const name = field('name', choice(
1197+
$.identifier, $.constant,
1198+
alias($.identifier_method_call, $.identifier),
1199+
))
11841200
const type = field('type', seq(/[ \t]:\s/, $._bare_type))
11851201

11861202
return seq(
@@ -1227,7 +1243,19 @@ module.exports = grammar({
12271243
),
12281244

12291245
c_struct_fields: $ => {
1230-
const names = seq($.identifier, repeat(seq(',', $.identifier)))
1246+
const names = seq(
1247+
choice(
1248+
$.identifier,
1249+
alias($.identifier_method_call, $.identifier),
1250+
),
1251+
repeat(seq(
1252+
',',
1253+
choice(
1254+
$.identifier,
1255+
alias($.identifier_method_call, $.identifier),
1256+
),
1257+
)),
1258+
)
12311259

12321260
return seq(
12331261
names,
@@ -1266,7 +1294,19 @@ module.exports = grammar({
12661294
),
12671295

12681296
union_fields: $ => {
1269-
const names = seq($.identifier, repeat(seq(',', $.identifier)))
1297+
const names = seq(
1298+
choice(
1299+
$.identifier,
1300+
alias($.identifier_method_call, $.identifier),
1301+
),
1302+
repeat(seq(
1303+
',',
1304+
choice(
1305+
$.identifier,
1306+
alias($.identifier_method_call, $.identifier),
1307+
),
1308+
)),
1309+
)
12701310

12711311
return seq(
12721312
names,
@@ -1425,7 +1465,9 @@ module.exports = grammar({
14251465
param: $ => {
14261466
const extern_name = field('extern_name', $.identifier)
14271467
const name = field('name', choice(
1428-
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression,
1468+
$.identifier, alias($.identifier_method_call, $.identifier),
1469+
$.instance_var, $.class_var,
1470+
$.macro_var, $.macro_expression,
14291471
))
14301472
const type = field('type', seq(/[ \t]:\s/, $._bare_type))
14311473
const default_value = field('default', seq('=', $._expression))
@@ -1441,7 +1483,9 @@ module.exports = grammar({
14411483

14421484
splat_param: $ => {
14431485
const name = field('name', choice(
1444-
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression,
1486+
$.identifier, alias($.identifier_method_call, $.identifier),
1487+
$.instance_var, $.class_var,
1488+
$.macro_var, $.macro_expression,
14451489
))
14461490
const type = field('type', seq(/[ \t]:\s/, $._bare_type))
14471491

@@ -1455,7 +1499,9 @@ module.exports = grammar({
14551499

14561500
double_splat_param: $ => {
14571501
const name = field('name', choice(
1458-
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression,
1502+
$.identifier, alias($.identifier_method_call, $.identifier),
1503+
$.instance_var, $.class_var,
1504+
$.macro_var, $.macro_expression,
14591505
))
14601506
const type = field('type', seq(/[ \t]:\s/, $._bare_type))
14611507

@@ -1469,7 +1515,9 @@ module.exports = grammar({
14691515

14701516
block_param: $ => {
14711517
const name = field('name', choice(
1472-
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression,
1518+
$.identifier, alias($.identifier_method_call, $.identifier),
1519+
$.instance_var, $.class_var,
1520+
$.macro_var, $.macro_expression,
14731521
))
14741522
const type = field('type', seq(/:\s/, $._bare_type))
14751523

@@ -1930,7 +1978,10 @@ module.exports = grammar({
19301978
)),
19311979

19321980
macro_for: $ => {
1933-
const var_name = field('var', choice($.underscore, $.identifier))
1981+
const var_name = field('var', choice(
1982+
$.underscore, $.identifier,
1983+
alias($.identifier_method_call, $.identifier),
1984+
))
19341985

19351986
return seq(
19361987
'for',
@@ -2477,6 +2528,7 @@ module.exports = grammar({
24772528
'out',
24782529
choice(
24792530
$.identifier,
2531+
alias($.identifier_method_call, $.identifier),
24802532
$.instance_var,
24812533
$.underscore,
24822534
$.macro_var,
@@ -2488,6 +2540,7 @@ module.exports = grammar({
24882540
const lhs = field('lhs', choice(
24892541
$.underscore,
24902542
$.identifier,
2543+
alias($.identifier_method_call, $.identifier),
24912544
$.instance_var,
24922545
$.class_var,
24932546
$.macro_var,
@@ -2551,6 +2604,7 @@ module.exports = grammar({
25512604

25522605
const lhs = field('lhs', choice(
25532606
$.identifier,
2607+
alias($.identifier_method_call, $.identifier),
25542608
$.instance_var,
25552609
$.class_var,
25562610
$.macro_var,
@@ -2569,6 +2623,7 @@ module.exports = grammar({
25692623
lhs_splat: $ => seq('*', choice(
25702624
$.underscore,
25712625
$.identifier,
2626+
alias($.identifier_method_call, $.identifier),
25722627
$.instance_var,
25732628
$.class_var,
25742629
$.macro_var,
@@ -2582,6 +2637,7 @@ module.exports = grammar({
25822637
const lhs_basic = choice(
25832638
$.underscore,
25842639
$.identifier,
2640+
alias($.identifier_method_call, $.identifier),
25852641
$.instance_var,
25862642
$.class_var,
25872643
$.macro_var,
@@ -2607,7 +2663,11 @@ module.exports = grammar({
26072663

26082664
uninitialized_assign: $ => {
26092665
return seq(
2610-
field('lhs', choice($.identifier, $.instance_var, $.class_var, $.global_var, $.macro_var)),
2666+
field('lhs', choice(
2667+
$.identifier, alias($.identifier_method_call, $.identifier),
2668+
$.instance_var, $.class_var,
2669+
$.global_var, $.macro_var,
2670+
)),
26112671
'=',
26122672
field('rhs', $.uninitialized_var),
26132673
)
@@ -2617,7 +2677,9 @@ module.exports = grammar({
26172677

26182678
type_declaration: $ => {
26192679
const variable = field('var', choice(
2620-
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression,
2680+
$.identifier, alias($.identifier_method_call, $.identifier),
2681+
$.instance_var, $.class_var,
2682+
$.macro_var, $.macro_expression,
26212683
))
26222684
const type = field('type', $._bare_type)
26232685
const value = field('value', $._expression)
@@ -2642,11 +2704,15 @@ module.exports = grammar({
26422704
field('type', $._bare_type),
26432705
),
26442706

2645-
block_body_param: $ => field('name', $.identifier),
2707+
block_body_param: $ => field('name', choice(
2708+
$.identifier, alias($.identifier_method_call, $.identifier),
2709+
)),
26462710

26472711
block_body_splat_param: $ => seq(
26482712
'*',
2649-
field('name', $.identifier),
2713+
field('name', choice(
2714+
$.identifier, alias($.identifier_method_call, $.identifier),
2715+
)),
26502716
),
26512717

26522718
_block_body_nested_param: $ => {

0 commit comments

Comments
 (0)