Skip to content

Commit

Permalink
feat: optional semicolon for the last field or function declaration i…
Browse files Browse the repository at this point in the history
…n trait/contract bodies
  • Loading branch information
novusnota committed Sep 26, 2024
1 parent 3b09624 commit afa6baa
Show file tree
Hide file tree
Showing 5 changed files with 5,698 additions and 5,424 deletions.
49 changes: 42 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,25 @@ module.exports = grammar({
choice(";", field("body", alias($.block_statement, $.function_body))),
),

_function_declaration: ($) =>
seq(
field("attributes", optional($.function_attributes)),
"fun",
field("name", $.identifier),
field("parameters", $.parameter_list),
field("result", optional(seq(":", $._type))),
),

_function_definition: ($) =>
seq(
field("attributes", optional($.function_attributes)),
"fun",
field("name", $.identifier),
field("parameters", $.parameter_list),
field("result", optional(seq(":", $._type))),
field("body", alias($.block_statement, $.function_body)),
),

function_attributes: (_) =>
repeat1(
choice(
Expand Down Expand Up @@ -309,8 +328,18 @@ module.exports = grammar({

field: ($) => seq(field("name", $.identifier), $._field_after_id),

// Like _constant, but without a semicolon at the end
storage_constant: ($) => seq(
field("attributes", optional($.constant_attributes)),
"const",
field("name", $.identifier),
":",
field("type", $._type),
optional(seq("=", field("value", $._expression))),
),

storage_variable: ($) =>
seq(field("name", $.identifier), $._field_after_id, ";"),
seq(field("name", $.identifier), $._field_after_id),

_field_after_id: ($) =>
seq(
Expand Down Expand Up @@ -352,13 +381,13 @@ module.exports = grammar({
"{",
repeat(
choice(
alias($._constant, $.storage_constant),
$.storage_variable,
seq($._body_item_without_semicolon, ";"),
$.init_function,
$._receiver_function,
alias($._function, $.storage_function),
alias($._function_definition, $.storage_function),
),
),
optional($._body_item_without_semicolon),
"}",
),

Expand All @@ -367,15 +396,21 @@ module.exports = grammar({
"{",
repeat(
choice(
alias($._constant, $.storage_constant),
$.storage_variable,
seq($._body_item_without_semicolon, ";"),
$._receiver_function,
alias($._function, $.storage_function),
alias($._function_definition, $.storage_function),
),
),
optional($._body_item_without_semicolon),
"}",
),

_body_item_without_semicolon: ($) => choice(
$.storage_constant,
$.storage_variable,
alias($._function_declaration, $.storage_function),
),

init_function: ($) =>
seq(
"init",
Expand Down
Loading

0 comments on commit afa6baa

Please sign in to comment.