Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module.exports = grammar({
'member',
'call',
$.spread_element,
'binary_pipe',
$.await_expression,
$.pipe_expression,
$.lazy_expression,
'binary_times',
'binary_pow',
Expand All @@ -55,6 +55,7 @@ module.exports = grammar({
$.mutation_expression,
$.function,
$.let_binding,
$.try_expression
],
// Nested.Module.Path precendence
[
Expand All @@ -63,7 +64,7 @@ module.exports = grammar({
$.nested_variant_identifier,
$.module_identifier_path,
],
[$._jsx_attribute_value, $.pipe_expression],
[$._jsx_attribute_value, $.binary_expression],
[$.function_type_parameters, $.function_type],
],

Expand Down Expand Up @@ -106,7 +107,9 @@ module.exports = grammar({
[$.variant_declaration],
[$.unit, $._function_type_parameter_list],
[$.functor_parameter, $.module_primary_expression, $.module_identifier_path],
[$._reserved_identifier, $.function]
[$._reserved_identifier, $.function],
[$._jsx_attribute_value, $.ternary_expression],
[$.jsx_expression, $.block],
],

rules: {
Expand Down Expand Up @@ -522,7 +525,6 @@ module.exports = grammar({
$.switch_expression,
$.try_expression,
$.call_expression,
$.pipe_expression,
$.subscript_expression,
$.member_expression,
$.module_pack,
Expand Down Expand Up @@ -717,10 +719,7 @@ module.exports = grammar({

try_expression: $ => seq(
'try',
choice(
$.block,
$.primary_expression,
),
$.expression,
'catch',
'{',
repeat($.switch_match),
Expand All @@ -742,20 +741,6 @@ module.exports = grammar({
field('arguments', alias($.call_arguments, $.arguments)),
)),

pipe_expression: $ => prec.left(seq(
$.primary_expression,
choice('->', '|>'),
choice(
$.value_identifier,
$.value_identifier_path,
$.variant_identifier,
$.polyvar_identifier,
$.nested_variant_identifier,
$.parenthesized_expression,
$.block,
),
)),

module_pack: $ => seq(
'module',
'(',
Expand Down Expand Up @@ -1046,7 +1031,7 @@ module.exports = grammar({
),

_jsx_attribute_value: $ => choice(
$.primary_expression,
$.expression,
$.jsx_expression,
),

Expand Down Expand Up @@ -1150,6 +1135,7 @@ module.exports = grammar({
['!==', 'binary_relation'],
['>=', 'binary_relation'],
['>', 'binary_relation'],
[choice('|>', '->'), 'binary_pipe']
].map(([operator, precedence]) =>
prec.left(precedence, seq(
field('left', $.expression),
Expand Down
2 changes: 1 addition & 1 deletion test/corpus/comments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ switch foo {
(comment)
(expression_statement (number))
(expression_statement
(pipe_expression
(binary_expression
(value_identifier)
(comment)
(value_identifier)))
Expand Down
59 changes: 33 additions & 26 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ f(raise)
(function
parameter: (value_identifier)
body: (binary_expression
left: (pipe_expression
(value_identifier)
(value_identifier_path
left: (binary_expression
left: (value_identifier)
right: (value_identifier_path
(module_identifier)
(value_identifier)))
right: (number))))))
Expand Down Expand Up @@ -196,54 +196,61 @@ foo->{
baz
}

{foo}->print()

---

(source_file
(expression_statement
(pipe_expression
(pipe_expression (value_identifier) (value_identifier))
(binary_expression
(binary_expression (value_identifier) (value_identifier))
(value_identifier)))
(expression_statement
(pipe_expression
(pipe_expression (value_identifier) (value_identifier))
(binary_expression
(binary_expression (value_identifier) (value_identifier))
(value_identifier)))
(expression_statement
(pipe_expression
(call_expression
(pipe_expression
(value_identifier)
(binary_expression
(binary_expression
(value_identifier)
(call_expression
(value_identifier_path
(module_identifier)
(value_identifier)))
(arguments (value_identifier)))
(module_identifier) (value_identifier))
(arguments
(value_identifier))))
(value_identifier_path
(module_identifier)
(value_identifier))))
(expression_statement
(pipe_expression
(binary_expression
(number)
(variant_identifier)))
(variant (variant_identifier))))
(expression_statement
(pipe_expression
(binary_expression
(value_identifier)
(polyvar_identifier)))
(polyvar (polyvar_identifier))))
(expression_statement
(pipe_expression
(binary_expression
(value_identifier)
(value_identifier)))
(expression_statement
(pipe_expression
(binary_expression
(value_identifier)
(parenthesized_expression
(function
(value_identifier)
(binary_expression (value_identifier) (number))))))
(expression_statement
(pipe_expression
(binary_expression
(value_identifier)
(block
(open_statement (module_identifier))
(expression_statement (value_identifier))))))
(expression_statement (value_identifier)))))
(expression_statement
(binary_expression
(block
(expression_statement (value_identifier)))
(call_expression (value_identifier) (arguments)))))

===========================================
Record
Expand Down Expand Up @@ -737,9 +744,9 @@ switch (element->HtmlInputElement.ofElement) {
(expression_statement
(switch_expression
(parenthesized_expression
(pipe_expression
(value_identifier)
(value_identifier_path (module_identifier) (value_identifier))))
(binary_expression
left: (value_identifier)
right: (value_identifier_path (module_identifier) (value_identifier))))
(switch_match
(variant_pattern
(variant_identifier)
Expand Down Expand Up @@ -1380,7 +1387,7 @@ await foo->bar + 5
(expression_statement
(binary_expression
(await_expression
(pipe_expression (value_identifier) (value_identifier)))
(binary_expression (value_identifier) (value_identifier)))
(number))))

===========================================
Expand Down
2 changes: 1 addition & 1 deletion test/corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Operator precendence
(expression_statement (function
(formal_parameters (parameter (value_identifier)))
(binary_expression
(pipe_expression
(binary_expression
(value_identifier)
(value_identifier_path (module_identifier) (value_identifier)))
(number)))))
Expand Down
2 changes: 1 addition & 1 deletion test/corpus/jsx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Attribute values
(jsx_identifier)
(jsx_attribute
(property_identifier)
(pipe_expression (value_identifier) (value_identifier)))
(binary_expression (value_identifier) (value_identifier)))
(jsx_attribute
(property_identifier)
(true)))))
Expand Down