Skip to content
Merged
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
5 changes: 4 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,10 @@ module.exports = grammar({
)),

pipe_expression: $ => prec.left(seq(
$.primary_expression,
choice(
$.primary_expression,
$.block,
),
choice('->', '|>'),
choice(
$.value_identifier,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove all rules on rhs and use only choice($.primary_expression, $.block)?

There will be minor changes in testing. But I think it's more consistent.

Example:

1 -> #A("foo")

Is parsed as:

yarn run v1.22.19
$ /home/pedro/Desktop/projects/tree-sitter-rescript/node_modules/.bin/tree-sitter parse ../../test-filetypes/rescript_print.res
(source_file [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 14]
    (call_expression [0, 0] - [0, 14]
      function: (pipe_expression [0, 0] - [0, 7]
        (number [0, 0] - [0, 1])
        (polyvar_identifier [0, 5] - [0, 7]))
      arguments: (arguments [0, 7] - [0, 14]
        (string [0, 8] - [0, 13]
          (string_fragment [0, 9] - [0, 12]))))))
Done in 0.47s.

With this change:

yarn run v1.22.19
$ /home/pedro/Desktop/projects/tree-sitter-rescript/node_modules/.bin/tree-sitter parse ../../test-filetypes/rescript_print.res
(source_file [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 14]
    (pipe_expression [0, 0] - [0, 14]
      (number [0, 0] - [0, 1])
      (polyvar [0, 5] - [0, 14]
        (polyvar_identifier [0, 5] - [0, 7])
        (arguments [0, 7] - [0, 14]
          (string [0, 8] - [0, 13]
            (string_fragment [0, 9] - [0, 12])))))))
Done in 0.05s.

Copy link
Collaborator

@aspeddro aspeddro Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually in another PR. See #182

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Fair point, thank you for the PR!

Expand Down
10 changes: 9 additions & 1 deletion test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ foo->{
baz
}

{foo}->print()

---

(source_file
Expand Down Expand Up @@ -243,7 +245,13 @@ foo->{
(value_identifier)
(block
(open_statement (module_identifier))
(expression_statement (value_identifier))))))
(expression_statement (value_identifier)))))
(expression_statement
(call_expression
(pipe_expression
(block (expression_statement (value_identifier)))
(value_identifier))
(arguments))))

===========================================
Record
Expand Down