Skip to content

Commit a9621dd

Browse files
Allow identifiers with trailing ? or ! in more places
1 parent 0932cff commit a9621dd

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',
@@ -2478,6 +2529,7 @@ module.exports = grammar({
24782529
'out',
24792530
choice(
24802531
$.identifier,
2532+
alias($.identifier_method_call, $.identifier),
24812533
$.instance_var,
24822534
$.underscore,
24832535
$.macro_var,
@@ -2489,6 +2541,7 @@ module.exports = grammar({
24892541
const lhs = field('lhs', choice(
24902542
$.underscore,
24912543
$.identifier,
2544+
alias($.identifier_method_call, $.identifier),
24922545
$.instance_var,
24932546
$.class_var,
24942547
$.macro_var,
@@ -2552,6 +2605,7 @@ module.exports = grammar({
25522605

25532606
const lhs = field('lhs', choice(
25542607
$.identifier,
2608+
alias($.identifier_method_call, $.identifier),
25552609
$.instance_var,
25562610
$.class_var,
25572611
$.macro_var,
@@ -2570,6 +2624,7 @@ module.exports = grammar({
25702624
lhs_splat: $ => seq('*', choice(
25712625
$.underscore,
25722626
$.identifier,
2627+
alias($.identifier_method_call, $.identifier),
25732628
$.instance_var,
25742629
$.class_var,
25752630
$.macro_var,
@@ -2583,6 +2638,7 @@ module.exports = grammar({
25832638
const lhs_basic = choice(
25842639
$.underscore,
25852640
$.identifier,
2641+
alias($.identifier_method_call, $.identifier),
25862642
$.instance_var,
25872643
$.class_var,
25882644
$.macro_var,
@@ -2608,7 +2664,11 @@ module.exports = grammar({
26082664

26092665
uninitialized_assign: $ => {
26102666
return seq(
2611-
field('lhs', choice($.identifier, $.instance_var, $.class_var, $.global_var, $.macro_var)),
2667+
field('lhs', choice(
2668+
$.identifier, alias($.identifier_method_call, $.identifier),
2669+
$.instance_var, $.class_var,
2670+
$.global_var, $.macro_var,
2671+
)),
26122672
'=',
26132673
field('rhs', $.uninitialized_var),
26142674
)
@@ -2618,7 +2678,9 @@ module.exports = grammar({
26182678

26192679
type_declaration: $ => {
26202680
const variable = field('var', choice(
2621-
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression,
2681+
$.identifier, alias($.identifier_method_call, $.identifier),
2682+
$.instance_var, $.class_var,
2683+
$.macro_var, $.macro_expression,
26222684
))
26232685
const type = field('type', $._bare_type)
26242686
const value = field('value', $._expression)
@@ -2643,11 +2705,15 @@ module.exports = grammar({
26432705
field('type', $._bare_type),
26442706
),
26452707

2646-
block_body_param: $ => field('name', $.identifier),
2708+
block_body_param: $ => field('name', choice(
2709+
$.identifier, alias($.identifier_method_call, $.identifier),
2710+
)),
26472711

26482712
block_body_splat_param: $ => seq(
26492713
'*',
2650-
field('name', $.identifier),
2714+
field('name', choice(
2715+
$.identifier, alias($.identifier_method_call, $.identifier),
2716+
)),
26512717
),
26522718

26532719
_block_body_nested_param: $ => {

0 commit comments

Comments
 (0)