Skip to content

Commit

Permalink
fix(functions): remove function body alias and use block (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
rawhat authored Feb 7, 2025
1 parent 066704e commit 3a5c285
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 66 deletions.
14 changes: 3 additions & 11 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,7 @@ module.exports = grammar({
field("name", $.identifier),
field("parameters", $.function_parameters),
optional(seq("->", field("return_type", $._type))),
optional(
seq(
"{",
optional(field("body", alias($._statement_seq, $.function_body))),
"}"
)
)
optional(field("body", $.block))
)
),
function_parameters: ($) =>
Expand Down Expand Up @@ -406,9 +400,7 @@ module.exports = grammar({
alias($.anonymous_function_parameters, $.function_parameters)
),
optional(seq("->", field("return_type", $._type))),
"{",
field("body", alias($._statement_seq, $.function_body)),
"}"
field("body", $.block)
),
anonymous_function_parameters: ($) =>
seq(
Expand All @@ -426,7 +418,7 @@ module.exports = grammar({
choice($._discard_param, $._name_param),
optional($._type_annotation)
),
block: ($) => seq("{", $._statement_seq, "}"),
block: ($) => seq("{", optional($._statement_seq), "}"),
case: ($) =>
seq(
"case",
Expand Down
6 changes: 3 additions & 3 deletions test/corpus/attributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn main() { todo }
(visibility_modifier)
name: (identifier)
parameters: (function_parameters)
body: (function_body
body: (block
(todo))))

================================================================================
Expand All @@ -44,7 +44,7 @@ pub fn wibble() { todo }
(visibility_modifier)
name: (identifier)
parameters: (function_parameters)
body: (function_body
body: (block
(todo))))

================================================================================
Expand All @@ -63,5 +63,5 @@ pub fn wibble() { todo }
(visibility_modifier)
name: (identifier)
parameters: (function_parameters)
body: (function_body
body: (block
(todo))))
2 changes: 1 addition & 1 deletion test/corpus/cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn listed(names: List(String), person: Person) -> String {
(type_identifier))))
(type
(type_identifier))
(function_body
(block
(case
(case_subjects
(identifier))
Expand Down
4 changes: 2 additions & 2 deletions test/corpus/destructuring.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn main() {
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(block
(case
(case_subjects
(identifier))
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn main() {
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(block
(let
(record_pattern
(constructor_name)
Expand Down
10 changes: 5 additions & 5 deletions test/corpus/echo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn main() {
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(block
(echo
(integer)))))

Expand All @@ -34,7 +34,7 @@ pub fn main() {
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(block
(binary_expression
(binary_expression
(list)
Expand All @@ -59,7 +59,7 @@ pub fn main() {
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(block
(binary_expression
(list)
(pipeline_echo))
Expand All @@ -81,7 +81,7 @@ pub fn main() {
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(block
(echo
(binary_expression
(integer)
Expand All @@ -104,7 +104,7 @@ pub fn main() {
(visibility_modifier)
(identifier)
(function_parameters)
(function_body
(block
(echo
(binary_expression
(integer)
Expand Down
Loading

0 comments on commit 3a5c285

Please sign in to comment.