Skip to content

Commit 628971f

Browse files
authored
Model heredoc bodies using non-terminal extras (#111)
1 parent 852d3eb commit 628971f

File tree

5 files changed

+155320
-164247
lines changed

5 files changed

+155320
-164247
lines changed

grammar.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = grammar({
6565

6666
extras: $ => [
6767
$.comment,
68+
$.heredoc_body,
6869
/\s|\\\n/
6970
],
7071

@@ -466,7 +467,6 @@ module.exports = grammar({
466467
call: $ => prec.left(PREC.CALL, seq(
467468
field('receiver', $._primary),
468469
choice('.', '&.'),
469-
repeat($.heredoc_body),
470470
field('method', choice($.identifier, $.operator, $.constant, $.argument_list))
471471
)),
472472

@@ -497,24 +497,19 @@ module.exports = grammar({
497497
},
498498

499499
command_argument_list: $ => choice(
500-
prec.right(seq(
501-
sep1($._argument, seq(',', optional($.heredoc_body))),
502-
repeat($.heredoc_body)
503-
)),
500+
commaSep1($._argument),
504501
$.command_call,
505502
),
506503

507504
argument_list: $ => prec.right(seq(
508505
token.immediate('('),
509506
optional($._argument_list_with_trailing_comma),
510-
')',
511-
repeat($.heredoc_body)
507+
')'
512508
)),
513509

514510
_argument_list_with_trailing_comma: $ => prec.right(seq(
515-
sep1($._argument, seq(',', optional($.heredoc_body))),
516-
optional(','),
517-
optional($.heredoc_body)
511+
commaSep1($._argument),
512+
optional(',')
518513
)),
519514

520515
_argument: $ => choice(
@@ -806,16 +801,13 @@ module.exports = grammar({
806801

807802
hash: $ => seq(
808803
'{',
809-
optional($._hash_items),
810-
optional($.heredoc_body),
804+
optional(seq(
805+
commaSep1(choice($.pair, $.hash_splat_argument)),
806+
optional(',')
807+
)),
811808
'}'
812809
),
813810

814-
_hash_items: $ => seq(
815-
choice($.pair, $.hash_splat_argument),
816-
optional(prec.right(seq(',', optional($.heredoc_body), optional($._hash_items))))
817-
),
818-
819811
pair: $ => choice(
820812
seq(
821813
field('key', $._arg),
@@ -847,7 +839,6 @@ module.exports = grammar({
847839

848840
_terminator: $ => choice(
849841
$._line_break,
850-
$.heredoc_body,
851842
';'
852843
),
853844
}

src/grammar.json

Lines changed: 79 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,13 +2419,6 @@
24192419
}
24202420
]
24212421
},
2422-
{
2423-
"type": "REPEAT",
2424-
"content": {
2425-
"type": "SYMBOL",
2426-
"name": "heredoc_body"
2427-
}
2428-
},
24292422
{
24302423
"type": "FIELD",
24312424
"name": "method",
@@ -2831,62 +2824,29 @@
28312824
"type": "CHOICE",
28322825
"members": [
28332826
{
2834-
"type": "PREC_RIGHT",
2835-
"value": 0,
2836-
"content": {
2837-
"type": "SEQ",
2838-
"members": [
2839-
{
2827+
"type": "SEQ",
2828+
"members": [
2829+
{
2830+
"type": "SYMBOL",
2831+
"name": "_argument"
2832+
},
2833+
{
2834+
"type": "REPEAT",
2835+
"content": {
28402836
"type": "SEQ",
28412837
"members": [
28422838
{
2843-
"type": "SYMBOL",
2844-
"name": "_argument"
2839+
"type": "STRING",
2840+
"value": ","
28452841
},
28462842
{
2847-
"type": "REPEAT",
2848-
"content": {
2849-
"type": "SEQ",
2850-
"members": [
2851-
{
2852-
"type": "SEQ",
2853-
"members": [
2854-
{
2855-
"type": "STRING",
2856-
"value": ","
2857-
},
2858-
{
2859-
"type": "CHOICE",
2860-
"members": [
2861-
{
2862-
"type": "SYMBOL",
2863-
"name": "heredoc_body"
2864-
},
2865-
{
2866-
"type": "BLANK"
2867-
}
2868-
]
2869-
}
2870-
]
2871-
},
2872-
{
2873-
"type": "SYMBOL",
2874-
"name": "_argument"
2875-
}
2876-
]
2877-
}
2843+
"type": "SYMBOL",
2844+
"name": "_argument"
28782845
}
28792846
]
2880-
},
2881-
{
2882-
"type": "REPEAT",
2883-
"content": {
2884-
"type": "SYMBOL",
2885-
"name": "heredoc_body"
2886-
}
28872847
}
2888-
]
2889-
}
2848+
}
2849+
]
28902850
},
28912851
{
28922852
"type": "SYMBOL",
@@ -2922,13 +2882,6 @@
29222882
{
29232883
"type": "STRING",
29242884
"value": ")"
2925-
},
2926-
{
2927-
"type": "REPEAT",
2928-
"content": {
2929-
"type": "SYMBOL",
2930-
"name": "heredoc_body"
2931-
}
29322885
}
29332886
]
29342887
}
@@ -2952,25 +2905,8 @@
29522905
"type": "SEQ",
29532906
"members": [
29542907
{
2955-
"type": "SEQ",
2956-
"members": [
2957-
{
2958-
"type": "STRING",
2959-
"value": ","
2960-
},
2961-
{
2962-
"type": "CHOICE",
2963-
"members": [
2964-
{
2965-
"type": "SYMBOL",
2966-
"name": "heredoc_body"
2967-
},
2968-
{
2969-
"type": "BLANK"
2970-
}
2971-
]
2972-
}
2973-
]
2908+
"type": "STRING",
2909+
"value": ","
29742910
},
29752911
{
29762912
"type": "SYMBOL",
@@ -2992,18 +2928,6 @@
29922928
"type": "BLANK"
29932929
}
29942930
]
2995-
},
2996-
{
2997-
"type": "CHOICE",
2998-
"members": [
2999-
{
3000-
"type": "SYMBOL",
3001-
"name": "heredoc_body"
3002-
},
3003-
{
3004-
"type": "BLANK"
3005-
}
3006-
]
30072931
}
30082932
]
30092933
}
@@ -5383,20 +5307,64 @@
53835307
"type": "CHOICE",
53845308
"members": [
53855309
{
5386-
"type": "SYMBOL",
5387-
"name": "_hash_items"
5388-
},
5389-
{
5390-
"type": "BLANK"
5391-
}
5392-
]
5393-
},
5394-
{
5395-
"type": "CHOICE",
5396-
"members": [
5397-
{
5398-
"type": "SYMBOL",
5399-
"name": "heredoc_body"
5310+
"type": "SEQ",
5311+
"members": [
5312+
{
5313+
"type": "SEQ",
5314+
"members": [
5315+
{
5316+
"type": "CHOICE",
5317+
"members": [
5318+
{
5319+
"type": "SYMBOL",
5320+
"name": "pair"
5321+
},
5322+
{
5323+
"type": "SYMBOL",
5324+
"name": "hash_splat_argument"
5325+
}
5326+
]
5327+
},
5328+
{
5329+
"type": "REPEAT",
5330+
"content": {
5331+
"type": "SEQ",
5332+
"members": [
5333+
{
5334+
"type": "STRING",
5335+
"value": ","
5336+
},
5337+
{
5338+
"type": "CHOICE",
5339+
"members": [
5340+
{
5341+
"type": "SYMBOL",
5342+
"name": "pair"
5343+
},
5344+
{
5345+
"type": "SYMBOL",
5346+
"name": "hash_splat_argument"
5347+
}
5348+
]
5349+
}
5350+
]
5351+
}
5352+
}
5353+
]
5354+
},
5355+
{
5356+
"type": "CHOICE",
5357+
"members": [
5358+
{
5359+
"type": "STRING",
5360+
"value": ","
5361+
},
5362+
{
5363+
"type": "BLANK"
5364+
}
5365+
]
5366+
}
5367+
]
54005368
},
54015369
{
54025370
"type": "BLANK"
@@ -5409,69 +5377,6 @@
54095377
}
54105378
]
54115379
},
5412-
"_hash_items": {
5413-
"type": "SEQ",
5414-
"members": [
5415-
{
5416-
"type": "CHOICE",
5417-
"members": [
5418-
{
5419-
"type": "SYMBOL",
5420-
"name": "pair"
5421-
},
5422-
{
5423-
"type": "SYMBOL",
5424-
"name": "hash_splat_argument"
5425-
}
5426-
]
5427-
},
5428-
{
5429-
"type": "CHOICE",
5430-
"members": [
5431-
{
5432-
"type": "PREC_RIGHT",
5433-
"value": 0,
5434-
"content": {
5435-
"type": "SEQ",
5436-
"members": [
5437-
{
5438-
"type": "STRING",
5439-
"value": ","
5440-
},
5441-
{
5442-
"type": "CHOICE",
5443-
"members": [
5444-
{
5445-
"type": "SYMBOL",
5446-
"name": "heredoc_body"
5447-
},
5448-
{
5449-
"type": "BLANK"
5450-
}
5451-
]
5452-
},
5453-
{
5454-
"type": "CHOICE",
5455-
"members": [
5456-
{
5457-
"type": "SYMBOL",
5458-
"name": "_hash_items"
5459-
},
5460-
{
5461-
"type": "BLANK"
5462-
}
5463-
]
5464-
}
5465-
]
5466-
}
5467-
},
5468-
{
5469-
"type": "BLANK"
5470-
}
5471-
]
5472-
}
5473-
]
5474-
},
54755380
"pair": {
54765381
"type": "CHOICE",
54775382
"members": [
@@ -5638,10 +5543,6 @@
56385543
"type": "SYMBOL",
56395544
"name": "_line_break"
56405545
},
5641-
{
5642-
"type": "SYMBOL",
5643-
"name": "heredoc_body"
5644-
},
56455546
{
56465547
"type": "STRING",
56475548
"value": ";"
@@ -5654,6 +5555,10 @@
56545555
"type": "SYMBOL",
56555556
"name": "comment"
56565557
},
5558+
{
5559+
"type": "SYMBOL",
5560+
"name": "heredoc_body"
5561+
},
56575562
{
56585563
"type": "PATTERN",
56595564
"value": "\\s|\\\\\\n"

0 commit comments

Comments
 (0)