Skip to content

Commit 660e6c4

Browse files
committed
fix: handling of consecutive if/for/defer statements and their optionals
fix: consecutive if statements fix: consecutive for-statements fix: consecutive statements
1 parent 620f9f4 commit 660e6c4

File tree

12 files changed

+8422
-8421
lines changed

12 files changed

+8422
-8421
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "tree-sitter-angular"
33
description = "Angular grammar for tree-sitter"
4-
version = "0.4.0"
4+
version = "0.4.1"
55
keywords = ["incremental", "parsing", "angular"]
66
categories = ["parsing", "text-editors"]
77
repository = "https://github.com/tree-sitter/tree-sitter-angular"

grammar.js

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,23 @@ module.exports = grammar(HTML, {
4343

4444
// ---------- Statements ----------
4545
_any_statement: ($) =>
46-
choice($.if_statement, $.for_statement, $.defer_statement, $.switch_statement),
46+
choice(
47+
$.if_statement,
48+
$.for_statement,
49+
$.defer_statement,
50+
$.switch_statement,
51+
$._alternative_statement,
52+
),
53+
54+
_alternative_statement: ($) =>
55+
choice(
56+
field('alternative', $.else_statement),
57+
field('alternative_condition', $.else_if_statement),
58+
field('empty', $.empty_statement),
59+
field('placeholder', $.placeholder_statement),
60+
field('loading', $.loading_statement),
61+
field('error', $.error_statement),
62+
),
4763

4864
// ---------- Switch Statement ----------
4965

@@ -82,51 +98,32 @@ module.exports = grammar(HTML, {
8298
// ---------- Defer Statement ----------
8399

84100
defer_statement: ($) =>
85-
prec.right(
101+
prec.left(
86102
seq(
87103
alias($._control_flow_start, '@'),
88104
alias('defer', $.control_keyword),
89105
optional($.defer_trigger),
90106
field('body', $.statement_block),
91-
optional(
92-
choice(
93-
field('placeholder', $.placeholder_statement),
94-
field('loading', $.loading_statement),
95-
field('error', $.error_statement),
96-
),
97-
),
98107
),
99108
),
100109

101110
placeholder_statement: ($) =>
102-
prec.right(
111+
prec.left(
103112
seq(
104113
alias($._control_flow_start, '@'),
105114
alias('placeholder', $.control_keyword),
106115
optional($.placeholder_minimum),
107116
field('body', $.statement_block),
108-
optional(
109-
choice(
110-
field('loading', $.loading_statement),
111-
field('error', $.error_statement),
112-
),
113-
),
114117
),
115118
),
116119

117120
loading_statement: ($) =>
118-
prec.right(
121+
prec.left(
119122
seq(
120123
alias($._control_flow_start, '@'),
121124
alias('loading', $.control_keyword),
122125
optional($.loading_condition),
123126
field('body', $.statement_block),
124-
optional(
125-
choice(
126-
field('placeholder', $.placeholder_statement),
127-
field('error', $.error_statement),
128-
),
129-
),
130127
),
131128
),
132129

@@ -173,7 +170,7 @@ module.exports = grammar(HTML, {
173170

174171
// ---------- For Statement ----------
175172
for_statement: ($) =>
176-
prec.right(
173+
prec.left(
177174
seq(
178175
alias($._control_flow_start, '@'),
179176
alias('for', $.control_keyword),
@@ -182,7 +179,6 @@ module.exports = grammar(HTML, {
182179
optional(field('reference', $.for_reference)),
183180
')',
184181
field('body', $.statement_block),
185-
optional($.empty_statement),
186182
),
187183
),
188184

@@ -237,19 +233,13 @@ module.exports = grammar(HTML, {
237233
),
238234

239235
_if_body_expression: ($) =>
240-
prec.right(
236+
prec.left(
241237
seq(
242238
'(',
243239
field('condition', $.if_condition),
244240
optional(field('reference', $.if_reference)),
245241
')',
246242
field('consequence', $.statement_block),
247-
optional(
248-
choice(
249-
field('alternative', $.else_if_statement),
250-
field('alternative', $.else_statement),
251-
),
252-
),
253243
),
254244
),
255245

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tree-sitter-angular",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Tree-sitter grammar for the Angular framework",
55
"main": "bindings/node",
66
"types": "bindings/node",

0 commit comments

Comments
 (0)