Skip to content

Commit

Permalink
Make normal attribute not show up in the syntax tree
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvandenberg committed Dec 8, 2023
1 parent 1f9b65c commit de27404
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 66 deletions.
Binary file not shown.
Binary file modified build/Release/tree_sitter_angular_binding.node
Binary file not shown.
2 changes: 0 additions & 2 deletions corpus/property-binding.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,10 @@ Regular attribute
(self_closing_tag
(tag_name)
(attribute
(normal_attribute
(attribute_name)
(quoted_attribute_value
(attribute_value)
)
)
)
)
)
Expand Down
4 changes: 1 addition & 3 deletions corpus/structural-directives.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ NgIf else
(start_tag
(tag_name)
(attribute
(normal_attribute
(attribute_name)
)
(attribute_name)
)
)
(interpolation
Expand Down
4 changes: 2 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ module.exports = grammar(HTML, {
prec(1, $.two_way_binding),
prec(1, $.event_binding),
prec(1, $.structural_directive),
$.normal_attribute,
$._normal_attribute,
),

// ---------- Structural Directives ---------
Expand Down Expand Up @@ -361,7 +361,7 @@ module.exports = grammar(HTML, {

binding_name: ($) => choice($.identifier, $.member_expression),

normal_attribute: ($) =>
_normal_attribute: ($) =>
seq(
$.attribute_name,
optional(seq('=', choice($.attribute_value, $.quoted_attribute_value))),
Expand Down
4 changes: 2 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
},
{
"type": "SYMBOL",
"name": "normal_attribute"
"name": "_normal_attribute"
}
]
},
Expand Down Expand Up @@ -2229,7 +2229,7 @@
}
]
},
"normal_attribute": {
"_normal_attribute": {
"type": "SEQ",
"members": [
{
Expand Down
37 changes: 11 additions & 26 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,29 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": "event_binding",
"type": "attribute_name",
"named": true
},
{
"type": "normal_attribute",
"type": "attribute_value",
"named": true
},
{
"type": "event_binding",
"named": true
},
{
"type": "property_binding",
"named": true
},
{
"type": "quoted_attribute_value",
"named": true
},
{
"type": "structural_directive",
"named": true
Expand Down Expand Up @@ -2038,29 +2046,6 @@
}
}
},
{
"type": "normal_attribute",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "attribute_name",
"named": true
},
{
"type": "attribute_value",
"named": true
},
{
"type": "quoted_attribute_value",
"named": true
}
]
}
},
{
"type": "object",
"named": true,
Expand Down
44 changes: 22 additions & 22 deletions src/parser.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tree_sitter/parser.h"
#include <tree_sitter/parser.h>

#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
Expand Down Expand Up @@ -170,7 +170,7 @@ enum {
sym_two_way_binding = 151,
sym__binding_assignment = 152,
sym_binding_name = 153,
sym_normal_attribute = 154,
sym__normal_attribute = 154,
sym_expression = 155,
sym_unary_expression = 156,
sym_binary_expression = 157,
Expand Down Expand Up @@ -364,7 +364,7 @@ static const char * const ts_symbol_names[] = {
[sym_two_way_binding] = "two_way_binding",
[sym__binding_assignment] = "_binding_assignment",
[sym_binding_name] = "binding_name",
[sym_normal_attribute] = "normal_attribute",
[sym__normal_attribute] = "_normal_attribute",
[sym_expression] = "expression",
[sym_unary_expression] = "unary_expression",
[sym_binary_expression] = "binary_expression",
Expand Down Expand Up @@ -558,7 +558,7 @@ static const TSSymbol ts_symbol_map[] = {
[sym_two_way_binding] = sym_two_way_binding,
[sym__binding_assignment] = sym__binding_assignment,
[sym_binding_name] = sym_binding_name,
[sym_normal_attribute] = sym_normal_attribute,
[sym__normal_attribute] = sym__normal_attribute,
[sym_expression] = sym_expression,
[sym_unary_expression] = sym_unary_expression,
[sym_binary_expression] = sym_binary_expression,
Expand Down Expand Up @@ -1214,8 +1214,8 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.visible = true,
.named = true,
},
[sym_normal_attribute] = {
.visible = true,
[sym__normal_attribute] = {
.visible = false,
.named = true,
},
[sym_expression] = {
Expand Down Expand Up @@ -10987,7 +10987,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(437), 1,
anon_sym_LBRACK_LPAREN,
STATE(363), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(161), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand Down Expand Up @@ -11037,7 +11037,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(441), 1,
anon_sym_SLASH_GT,
STATE(363), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(165), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand All @@ -11064,7 +11064,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(443), 1,
anon_sym_SLASH_GT,
STATE(363), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(163), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand All @@ -11091,7 +11091,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(445), 1,
anon_sym_SLASH_GT,
STATE(363), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(165), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand All @@ -11118,7 +11118,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(447), 1,
anon_sym_SLASH_GT,
STATE(363), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(165), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand All @@ -11141,7 +11141,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(463), 1,
anon_sym_LBRACK_LPAREN,
STATE(363), 1,
sym_normal_attribute,
sym__normal_attribute,
ACTIONS(449), 2,
anon_sym_GT,
anon_sym_SLASH_GT,
Expand Down Expand Up @@ -11171,7 +11171,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(466), 1,
anon_sym_SLASH_GT,
STATE(363), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(164), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand Down Expand Up @@ -11218,7 +11218,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(478), 1,
anon_sym_LBRACK_LPAREN,
STATE(392), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(170), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand All @@ -11243,7 +11243,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(492), 1,
anon_sym_LBRACK_LPAREN,
STATE(392), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(169), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand All @@ -11268,7 +11268,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(495), 1,
anon_sym_GT,
STATE(392), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(169), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand All @@ -11293,7 +11293,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(497), 1,
anon_sym_GT,
STATE(392), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(169), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand Down Expand Up @@ -11358,7 +11358,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(509), 1,
anon_sym_GT,
STATE(392), 1,
sym_normal_attribute,
sym__normal_attribute,
STATE(171), 2,
sym_attribute,
aux_sym_start_tag_repeat1,
Expand Down Expand Up @@ -17385,8 +17385,8 @@ static const TSParseActionEntry ts_parse_actions[] = {
[802] = {.entry = {.count = 1, .reusable = true}}, SHIFT(285),
[804] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_start_tag, 3),
[806] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_start_tag, 3),
[808] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_normal_attribute, 1),
[810] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_normal_attribute, 1),
[808] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__normal_attribute, 1),
[810] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__normal_attribute, 1),
[812] = {.entry = {.count = 1, .reusable = true}}, SHIFT(410),
[814] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_empty_expression, 3),
[816] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_empty_expression, 3),
Expand Down Expand Up @@ -17420,8 +17420,8 @@ static const TSParseActionEntry ts_parse_actions[] = {
[873] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_property_binding, 4),
[875] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_property_binding, 4),
[877] = {.entry = {.count = 1, .reusable = true}}, SHIFT(446),
[879] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_normal_attribute, 3),
[881] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_normal_attribute, 3),
[879] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__normal_attribute, 3),
[881] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__normal_attribute, 3),
[883] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_two_way_binding, 4),
[885] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_two_way_binding, 4),
[887] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_quoted_attribute_value, 3),
Expand Down
13 changes: 4 additions & 9 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,6 @@ static bool scan_raw_text(Scanner *scanner, TSLexer *lexer) {
return false;
}

if (VEC_BACK(scanner->tags).type != SCRIPT &&
VEC_BACK(scanner->tags).type != STYLE) {
return false;
}

lexer->mark_end(lexer);

const char *end_delimiter =
Expand Down Expand Up @@ -373,15 +368,15 @@ static bool scan_self_closing_tag_delimiter(Scanner *scanner, TSLexer *lexer) {
}

static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
while (iswspace(lexer->lookahead)) {
lexer->advance(lexer, true);
}

if (valid_symbols[RAW_TEXT] && !valid_symbols[START_TAG_NAME] &&
!valid_symbols[END_TAG_NAME]) {
return scan_raw_text(scanner, lexer);
}

while (iswspace(lexer->lookahead)) {
lexer->advance(lexer, true);
}

switch (lexer->lookahead) {
case '<':
lexer->mark_end(lexer);
Expand Down

0 comments on commit de27404

Please sign in to comment.