Skip to content

Commit 170a88a

Browse files
committed
fix: % in words, better definitions
1 parent a4175c6 commit 170a88a

File tree

7 files changed

+4222
-3640
lines changed

7 files changed

+4222
-3640
lines changed

grammar/func/grammar.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,11 @@ module.exports = grammar({
100100
multiline_comment
101101
));
102102
}
103-
}
103+
},
104+
105+
conflicts: $ => [
106+
[$.parameter_list_relaxed, $.type_identifier],
107+
[$.parameter_list_relaxed, $.hole_type],
108+
[$.parameter_list_relaxed, $.parameter_list]
109+
]
104110
});

grammar/func/grammar/functions.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
const {commaSep, commaSep1, commaSep2} = require('./utils.js')
1+
const { commaSep, commaSep1, commaSep2 } = require('./utils.js')
22

33
module.exports = {
44
function_definition: $ => seq(
55
field("type_variables", optional($.type_variables_list)),
66
field("return_type", $._type),
77
field("name", $.function_name),
8-
field("arguments", $.parameter_list),
9-
field("specifiers", optional($.specifiers_list)),
108
choice(
11-
';',
12-
field("body", $.block_statement),
13-
field("asm_body", $.asm_function_body)
9+
seq(
10+
field("arguments", $.parameter_list),
11+
field("specifiers", optional($.specifiers_list)),
12+
choice(
13+
field("body", $.block_statement),
14+
field("asm_body", $.asm_function_body)
15+
)
16+
),
17+
seq(
18+
field("arguments", $.parameter_list_relaxed),
19+
field("specifiers", optional($.specifiers_list)),
20+
';',
21+
)
1422
)
1523
),
1624

17-
function_name: $ => /(`.*`)|((\.|~)?(([$a-zA-Z_](\w|['?:$])+)|([a-zA-Z$])))/,
25+
function_name: $ => /(`.*`)|((\.|~)?(([$%a-zA-Z_](\w|['?:$%])+)|([a-zA-Z%$])))/,
1826

1927
impure: $ => "impure",
2028
inline: $ => choice("inline", "inline_ref"),
@@ -23,8 +31,8 @@ module.exports = {
2331
)),
2432

2533
specifiers_list: $ => choice(
26-
seq($.impure, optional($.inline), optional($.method_id)),
27-
seq($.inline, optional($.method_id)),
34+
seq($.impure, optional($.inline), optional($.method_id)),
35+
seq($.inline, optional($.method_id)),
2836
$.method_id
2937
),
3038

@@ -34,17 +42,31 @@ module.exports = {
3442
"->"
3543
),
3644

37-
parameter_list: $ => seq(
45+
parameter_list: $ => prec(1, seq(
3846
'(',
3947
commaSep($.parameter_declaration),
4048
')'
49+
)),
50+
51+
parameter_list_relaxed: $ => seq(
52+
'(',
53+
commaSep(
54+
choice(
55+
$.parameter_declaration,
56+
field('name', $.identifier),
57+
$.underscore
58+
)
59+
),
60+
')'
4161
),
4262

4363
parameter_declaration: $ => seq(
44-
optional(field('type', $._type)),
45-
choice(
46-
field('name', $.identifier),
47-
$.underscore
64+
field('type', $._type),
65+
optional(
66+
choice(
67+
field('name', $.identifier),
68+
$.underscore
69+
)
4870
)
4971
),
5072

0 commit comments

Comments
 (0)