pull/844/head
Giacomo Cavalieri 2024-10-21 17:59:52 +07:00 committed by Louis Pilfold
parent 57c9951b29
commit 8db8a0ba8b
4 changed files with 80 additions and 4 deletions

@ -21,6 +21,8 @@ module.exports = grammar({
[$.source_file],
[$._constant_value, $._case_clause_guard_unit],
[$.integer],
[$.pipeline_echo, $.echo],
[$.echo],
],
rules: {
/* General rules */
@ -298,7 +300,13 @@ module.exports = grammar({
binaryExpr(prec.left, 4, ">=", $._expression),
binaryExpr(prec.left, 4, ">.", $._expression),
binaryExpr(prec.left, 4, ">=.", $._expression),
binaryExpr(prec.left, 5, "|>", $._expression),
binaryExpr(
prec.left,
5,
"|>",
$._expression,
choice($.pipeline_echo, $._expression)
),
binaryExpr(prec.left, 6, "+", $._expression),
binaryExpr(prec.left, 6, "+.", $._expression),
binaryExpr(prec.left, 6, "-", $._expression),
@ -330,6 +338,7 @@ module.exports = grammar({
$.todo,
$.panic,
$.tuple,
$.echo,
$.list,
alias($._expression_bit_string, $.bit_string),
$.anonymous_function,
@ -369,6 +378,8 @@ module.exports = grammar({
)
)
),
pipeline_echo: (_$) => " echo",
echo: ($) => seq("echo", $._expression),
tuple: ($) => seq("#", "(", optional(series_of($._expression, ",")), ")"),
list: ($) =>
seq(

@ -73,7 +73,7 @@
; TODO: when tree-sitter supports `#any-of?` in the Rust bindings,
; refactor this to use `#any-of?` rather than `#match?`
((identifier) @error
(#match? @error "^(auto|delegate|derive|else|implement|macro|test|echo)$"))
(#match? @error "^(auto|delegate|derive|else|implement|macro|test)$"))
; Variables
(identifier) @variable
@ -87,6 +87,7 @@
"assert"
"case"
"const"
"echo"
; DEPRECATED: 'external' was removed in v0.30.
"external"
"fn"

@ -0,0 +1,66 @@
================================================================================
Echo with expression
================================================================================
pub fn main() {
echo 1
}
--------------------------------------------------------------------------------
(source_file
(function
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(echo
(integer)))))
================================================================================
Echo in pipeline
================================================================================
pub fn main() {
[]
|> echo
|> panic
}
--------------------------------------------------------------------------------
(source_file
(function
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(binary_expression
(binary_expression
(list)
(pipeline_echo))
(panic)))))
================================================================================
Echo last in pipeline
================================================================================
pub fn main() {
[]
|> echo
1
}
--------------------------------------------------------------------------------
(source_file
(function
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(binary_expression
(list)
(pipeline_echo))
(integer))))

@ -12,5 +12,3 @@ macro
// <- error
test
// <- error
echo
// <- error