Skip to content

Commit e75d044

Browse files
authored
Merge pull request #222 from aibaars/parser-fixes-3
Some improvements to the parser
2 parents 5b305c3 + f70d9f1 commit e75d044

File tree

6 files changed

+361724
-357803
lines changed

6 files changed

+361724
-357803
lines changed

grammar.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ module.exports = grammar({
100100
rules: {
101101
program: $ => seq(
102102
optional($._statements),
103-
optional(seq(
104-
'__END__',
105-
$._line_break,
106-
$.uninterpreted)
103+
optional(
104+
choice(
105+
seq(/__END__[\r\n]/, $.uninterpreted),
106+
seq('__END__', alias('', $.uninterpreted))
107+
)
107108
)
108109
),
109110

@@ -261,8 +262,10 @@ module.exports = grammar({
261262
class: $ => seq(
262263
'class',
263264
field('name', choice($.constant, $.scope_resolution)),
264-
field('superclass', optional($.superclass)),
265-
$._terminator,
265+
choice(
266+
seq(field('superclass', $.superclass), $._terminator),
267+
optional($._terminator)
268+
),
266269
$._body_statement
267270
),
268271

@@ -279,10 +282,8 @@ module.exports = grammar({
279282
module: $ => seq(
280283
'module',
281284
field('name', choice($.constant, $.scope_resolution)),
282-
choice(
283-
seq($._terminator, $._body_statement),
284-
'end'
285-
)
285+
optional($._terminator),
286+
$._body_statement,
286287
),
287288

288289
return_command: $ => prec.left(seq('return', alias($.command_argument_list, $.argument_list))),
@@ -999,7 +1000,7 @@ module.exports = grammar({
9991000

10001001
operator: $ => choice(
10011002
'..', '|', '^', '&', '<=>', '==', '===', '=~', '>', '>=', '<', '<=', '+',
1002-
'-', '*', '/', '%', '!', '!~', '**', '<<', '>>', '~', '+@', '-@', '[]', '[]=', '`'
1003+
'-', '*', '/', '%', '!', '!~', '**', '<<', '>>', '~', '+@', '-@', '~@', '[]', '[]=', '`'
10031004
),
10041005

10051006
_method_name: $ => choice(

src/grammar.json

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,38 @@
2121
"type": "CHOICE",
2222
"members": [
2323
{
24-
"type": "SEQ",
24+
"type": "CHOICE",
2525
"members": [
2626
{
27-
"type": "STRING",
28-
"value": "__END__"
29-
},
30-
{
31-
"type": "SYMBOL",
32-
"name": "_line_break"
27+
"type": "SEQ",
28+
"members": [
29+
{
30+
"type": "PATTERN",
31+
"value": "__END__[\\r\\n]"
32+
},
33+
{
34+
"type": "SYMBOL",
35+
"name": "uninterpreted"
36+
}
37+
]
3338
},
3439
{
35-
"type": "SYMBOL",
36-
"name": "uninterpreted"
40+
"type": "SEQ",
41+
"members": [
42+
{
43+
"type": "STRING",
44+
"value": "__END__"
45+
},
46+
{
47+
"type": "ALIAS",
48+
"content": {
49+
"type": "STRING",
50+
"value": ""
51+
},
52+
"named": true,
53+
"value": "uninterpreted"
54+
}
55+
]
3756
}
3857
]
3958
},
@@ -894,24 +913,38 @@
894913
}
895914
},
896915
{
897-
"type": "FIELD",
898-
"name": "superclass",
899-
"content": {
900-
"type": "CHOICE",
901-
"members": [
902-
{
903-
"type": "SYMBOL",
904-
"name": "superclass"
905-
},
906-
{
907-
"type": "BLANK"
908-
}
909-
]
910-
}
911-
},
912-
{
913-
"type": "SYMBOL",
914-
"name": "_terminator"
916+
"type": "CHOICE",
917+
"members": [
918+
{
919+
"type": "SEQ",
920+
"members": [
921+
{
922+
"type": "FIELD",
923+
"name": "superclass",
924+
"content": {
925+
"type": "SYMBOL",
926+
"name": "superclass"
927+
}
928+
},
929+
{
930+
"type": "SYMBOL",
931+
"name": "_terminator"
932+
}
933+
]
934+
},
935+
{
936+
"type": "CHOICE",
937+
"members": [
938+
{
939+
"type": "SYMBOL",
940+
"name": "_terminator"
941+
},
942+
{
943+
"type": "BLANK"
944+
}
945+
]
946+
}
947+
]
915948
},
916949
{
917950
"type": "SYMBOL",
@@ -994,23 +1027,17 @@
9941027
"type": "CHOICE",
9951028
"members": [
9961029
{
997-
"type": "SEQ",
998-
"members": [
999-
{
1000-
"type": "SYMBOL",
1001-
"name": "_terminator"
1002-
},
1003-
{
1004-
"type": "SYMBOL",
1005-
"name": "_body_statement"
1006-
}
1007-
]
1030+
"type": "SYMBOL",
1031+
"name": "_terminator"
10081032
},
10091033
{
1010-
"type": "STRING",
1011-
"value": "end"
1034+
"type": "BLANK"
10121035
}
10131036
]
1037+
},
1038+
{
1039+
"type": "SYMBOL",
1040+
"name": "_body_statement"
10141041
}
10151042
]
10161043
},
@@ -6568,6 +6595,10 @@
65686595
"type": "STRING",
65696596
"value": "-@"
65706597
},
6598+
{
6599+
"type": "STRING",
6600+
"value": "~@"
6601+
},
65716602
{
65726603
"type": "STRING",
65736604
"value": "[]"

src/node-types.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4067,5 +4067,9 @@
40674067
{
40684068
"type": "~",
40694069
"named": false
4070+
},
4071+
{
4072+
"type": "~@",
4073+
"named": false
40704074
}
40714075
]

0 commit comments

Comments
 (0)