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
24 changes: 22 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export default grammar({
rules: {
source_file: ($) => $.root_expression,

root_expression: ($) => choice($.open_expression, $.closed_expression),
root_expression: ($) => choice(
$.open_expression,
$.closed_expression,
$.map_shorthand,
),

open_expression: ($) => seq(
$.expression,
Expand All @@ -31,7 +35,23 @@ export default grammar({

closed_expression: ($) => seq(
$.value,
optional(seq("|", $.expression, repeat(seq("|", $.expression)))),
repeat(choice(
seq("|", $.expression),
alias($._pipeline_map_shorthand, $.map_shorthand),
)),
),

map_shorthand: ($) => seq(
"|>",
field("expression", $.open_expression),
),

// In a closed-expression pipeline, the next ordinary `|` belongs to the
// outer pipeline. Alias the single mapped operation as an open expression
// so both forms expose the same CST shape.
_pipeline_map_shorthand: ($) => seq(
"|>",
field("expression", alias($.expression, $.open_expression)),
),

expression: ($) => $.function_call,
Expand Down
100 changes: 68 additions & 32 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading