Skip to content

Commit

Permalink
fix: handling of consecutive if/for/defer statements and their optionals
Browse files Browse the repository at this point in the history
fix: consecutive if statements

fix: consecutive for-statements

fix: consecutive statements
  • Loading branch information
dlvandenberg committed Aug 13, 2024
1 parent 620f9f4 commit 660e6c4
Show file tree
Hide file tree
Showing 12 changed files with 8,422 additions and 8,421 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-angular"
description = "Angular grammar for tree-sitter"
version = "0.4.0"
version = "0.4.1"
keywords = ["incremental", "parsing", "angular"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-angular"
Expand Down
54 changes: 22 additions & 32 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,23 @@ module.exports = grammar(HTML, {

// ---------- Statements ----------
_any_statement: ($) =>
choice($.if_statement, $.for_statement, $.defer_statement, $.switch_statement),
choice(
$.if_statement,
$.for_statement,
$.defer_statement,
$.switch_statement,
$._alternative_statement,
),

_alternative_statement: ($) =>
choice(
field('alternative', $.else_statement),
field('alternative_condition', $.else_if_statement),
field('empty', $.empty_statement),
field('placeholder', $.placeholder_statement),
field('loading', $.loading_statement),
field('error', $.error_statement),
),

// ---------- Switch Statement ----------

Expand Down Expand Up @@ -82,51 +98,32 @@ module.exports = grammar(HTML, {
// ---------- Defer Statement ----------

defer_statement: ($) =>
prec.right(
prec.left(
seq(
alias($._control_flow_start, '@'),
alias('defer', $.control_keyword),
optional($.defer_trigger),
field('body', $.statement_block),
optional(
choice(
field('placeholder', $.placeholder_statement),
field('loading', $.loading_statement),
field('error', $.error_statement),
),
),
),
),

placeholder_statement: ($) =>
prec.right(
prec.left(
seq(
alias($._control_flow_start, '@'),
alias('placeholder', $.control_keyword),
optional($.placeholder_minimum),
field('body', $.statement_block),
optional(
choice(
field('loading', $.loading_statement),
field('error', $.error_statement),
),
),
),
),

loading_statement: ($) =>
prec.right(
prec.left(
seq(
alias($._control_flow_start, '@'),
alias('loading', $.control_keyword),
optional($.loading_condition),
field('body', $.statement_block),
optional(
choice(
field('placeholder', $.placeholder_statement),
field('error', $.error_statement),
),
),
),
),

Expand Down Expand Up @@ -173,7 +170,7 @@ module.exports = grammar(HTML, {

// ---------- For Statement ----------
for_statement: ($) =>
prec.right(
prec.left(
seq(
alias($._control_flow_start, '@'),
alias('for', $.control_keyword),
Expand All @@ -182,7 +179,6 @@ module.exports = grammar(HTML, {
optional(field('reference', $.for_reference)),
')',
field('body', $.statement_block),
optional($.empty_statement),
),
),

Expand Down Expand Up @@ -237,19 +233,13 @@ module.exports = grammar(HTML, {
),

_if_body_expression: ($) =>
prec.right(
prec.left(
seq(
'(',
field('condition', $.if_condition),
optional(field('reference', $.if_reference)),
')',
field('consequence', $.statement_block),
optional(
choice(
field('alternative', $.else_if_statement),
field('alternative', $.else_statement),
),
),
),
),

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tree-sitter-angular",
"version": "0.4.0",
"version": "0.4.1",
"description": "Tree-sitter grammar for the Angular framework",
"main": "bindings/node",
"types": "bindings/node",
Expand Down
Loading

0 comments on commit 660e6c4

Please sign in to comment.