Skip to content

Commit

Permalink
feat: match 1.4.1 (#36)
Browse files Browse the repository at this point in the history
* chore: replace _lvalue with _path_expression (assignments) and _expression (foreach)

As a bonus we have one less conflict, which boosts the speed of the
parser despite introducing new choice in _path_expression

* feat: reduce options to type identifiers in `primitive`

* fix: incorrect package manager

* chore: formatting

* fix: erroneous parse of field parent nodes inside structs and messages

Discovered in tact-lsp via hover event-driven debugging :)

* fix: FunC identifiers recognition now matches actual grammar rules of FunC
  • Loading branch information
novusnota authored Aug 24, 2024
1 parent 91cc49a commit f264041
Show file tree
Hide file tree
Showing 15 changed files with 4,645 additions and 4,779 deletions.
2 changes: 0 additions & 2 deletions editor_queries/helix/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
(field_access_expression
name: (identifier) @variable.other.member)

(lvalue (_) (_) @variable.other.member)

(instance_argument
name: (identifier) @variable.other.member)

Expand Down
4 changes: 0 additions & 4 deletions editor_queries/neovim/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@
(instance_argument
name: (identifier) @variable.member)

(lvalue
(_)
(_) @variable.member)

(field_access_expression
name: (identifier) @variable.member)

Expand Down
4 changes: 2 additions & 2 deletions editor_queries/neovim/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@
(value_expression
(identifier) @local.reference)

(lvalue
(identifier) @local.reference)
(field_access_expression
name: (identifier) @local.reference)
50 changes: 22 additions & 28 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ module.exports = grammar({

/* Each inner array represents a set of rules that's involved in an LR(1) conflict
that is intended to exist in the grammar and be resolved by Tree-sitter at runtime using GLR algorithm */
conflicts: ($) => [
[$.constant_attributes, $.function_attributes],
[$._lvalue, $.value_expression],
],
conflicts: ($) => [[$.constant_attributes, $.function_attributes]],

/* Mapping of grammar rule names to rule builder functions */
rules: {
Expand All @@ -141,7 +138,12 @@ module.exports = grammar({

/* Built-in declarations */

primitive: ($) => seq("primitive", field("type", $._type), ";"),
primitive: ($) =>
seq(
"primitive",
field("type", alias($._type_identifier, $.type_identifier)),
";",
),

/* Constants */

Expand Down Expand Up @@ -224,22 +226,23 @@ module.exports = grammar({

message_value: ($) => seq("(", $.integer, ")"),

struct_body: ($) =>
seq("{", semicolonSepWithTrailing(alias($._field, $.field)), "}"),
struct_body: ($) => seq("{", semicolonSepWithTrailing($.field), "}"),

/* Fields (of messages, structs, contracts, traits) */

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

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

_field_after_id: ($) =>
seq(
field("name", $.identifier),
":",
field("type", $._type),
field("tlb", optional($.tlb_serialization)),
optional(seq("=", field("value", $._expression))),
),

storage_variable: ($) => seq($._field, ";"),

/* Contracts, Traits */

contract: ($) =>
Expand Down Expand Up @@ -385,7 +388,7 @@ module.exports = grammar({
prec.right(
"assign_stmt",
seq(
field("left", alias($._lvalue, $.lvalue)),
field("left", $._path_expression),
"=",
field("right", $._expression),
),
Expand All @@ -395,7 +398,7 @@ module.exports = grammar({
prec.right(
"assign_stmt",
seq(
field("left", alias($._lvalue, $.lvalue)),
field("left", $._path_expression),
field(
"operator",
choice("+=", "-=", "*=", "/=", "%=", "&=", "|=", "^="),
Expand Down Expand Up @@ -468,20 +471,13 @@ module.exports = grammar({
",",
field("value", $.identifier),
"in",
field("map", alias($._lvalue, $.lvalue)),
field("map", $._expression),
")",
field("body", $.block_statement),
),

_lvalue: ($) =>
prec.right(
choice(
$.identifier,
seq($.identifier, ".", $._lvalue),
$.self,
seq($.self, ".", $._lvalue),
),
),
_path_expression: ($) =>
choice($.self, $.identifier, $.field_access_expression),

/* Expressions */

Expand Down Expand Up @@ -708,11 +704,9 @@ module.exports = grammar({

/* Identifiers */

func_identifier: ($) =>
seq($._func_identifier_letter, repeat($._func_identifier_part)),

_func_identifier_part: ($) => choice($._func_identifier_letter, /[0-9]/),
_func_identifier_letter: (_) => choice(/[a-zA-Z_'?!&]/, /::/),
func_identifier: ($) => choice($._func_plain_id, $._func_quoted_id),
_func_quoted_id: (_) => /[\.\~]?\`[^\n\`]+\`/,
_func_plain_id: (_) => /[\.\~]?[^\s\(\)\[\]\,\.\;\~]+/,

identifier: (_) => /[a-zA-Z_][a-zA-Z0-9_]*/,

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@
"singleQuote": false,
"semi": true
},
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
"packageManager": "[email protected]"
}
2 changes: 0 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@
(instance_argument
name: (identifier) @property)

(lvalue (_) (_) @property)

(field_access_expression
name: (identifier) @property)

Expand Down
3 changes: 2 additions & 1 deletion queries/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@

(value_expression (identifier) @local.reference)

(lvalue (identifier) @local.reference)
(field_access_expression
name: (identifier) @local.reference)
Loading

0 comments on commit f264041

Please sign in to comment.