From b6307c8565f59bc5bbb4b62bfbdf042695e9d417 Mon Sep 17 00:00:00 2001 From: Samuel Sieg Date: Fri, 5 Jul 2024 13:16:24 +0200 Subject: [PATCH 1/2] Add support for `:` and `/` in css class names --- grammar.js | 5 +++-- src/grammar.json | 2 +- src/parser.c | 2 +- test/corpus/tags.txt | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/grammar.js b/grammar.js index cbc0ff0..50f62bc 100644 --- a/grammar.js +++ b/grammar.js @@ -193,8 +193,9 @@ module.exports = grammar({ _element_rest_text: $ => token(prec(-3, /[^ \t][^\n]*/)), // From css grammar https://github.com/tree-sitter/tree-sitter-css/blob/master/grammar.js - // Originally: /\A(#{keys}+)((?:\p{Word}|-|\/\d+|:(\w|-)+)*)/ - css_identifier: $ => /(--|-?[a-zA-Z_])[a-zA-Z0-9-_]*/, + // Originally from Slim: /\A(#{keys}+)((?:\p{Word}|-|\/\d+|:(\w|-)+)*)/ + // With added support for `:` and `/` + css_identifier: $ => /(--|-?[a-zA-Z_])[a-zA-Z0-9-_:\/]*/, // From doc, mostly unclear, which means which doctype: $ => seq( diff --git a/src/grammar.json b/src/grammar.json index 72cc4af..ce0265d 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -1086,7 +1086,7 @@ }, "css_identifier": { "type": "PATTERN", - "value": "(--|-?[a-zA-Z_])[a-zA-Z0-9-_]*" + "value": "(--|-?[a-zA-Z_])[a-zA-Z0-9-_:\\/]*" }, "doctype": { "type": "SEQ", diff --git a/src/parser.c b/src/parser.c index 2bd362f..ba48ae6 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2783,7 +2783,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 210: ACCEPT_TOKEN(sym_css_identifier); if (lookahead == '-' || - ('0' <= lookahead && lookahead <= '9') || + ('/' <= lookahead && lookahead <= ':') || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || ('a' <= lookahead && lookahead <= 'z')) ADVANCE(210); diff --git a/test/corpus/tags.txt b/test/corpus/tags.txt index 18dde80..8572d2d 100644 --- a/test/corpus/tags.txt +++ b/test/corpus/tags.txt @@ -15,6 +15,25 @@ span.menu.active (attr_shortcut_class (css_identifier))))) +================================ +Tag and css classes with : and / +================================ + +span.hidden.lg:block.w-1/2 + +--- + +(source_file + (element + (tag_name) + (attr_shortcuts + (attr_shortcut_class + (css_identifier)) + (attr_shortcut_class + (css_identifier)) + (attr_shortcut_class + (css_identifier))))) + =============================== Tag with traling space modifier =============================== From c097becdc88d3f7a92314654e0410b4aab4bd128 Mon Sep 17 00:00:00 2001 From: Samuel Sieg Date: Fri, 5 Jul 2024 14:30:26 +0200 Subject: [PATCH 2/2] Update parser.c --- src/parser.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/parser.c b/src/parser.c index 6220af2..535e0be 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2808,9 +2808,10 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 210: ACCEPT_TOKEN(sym_css_identifier); - if (lookahead == '0') ADVANCE(211); + if (lookahead == '/' || + lookahead == '0') ADVANCE(211); if (lookahead == '-' || - ('1' <= lookahead && lookahead <= '9') || + ('1' <= lookahead && lookahead <= ':') || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || ('a' <= lookahead && lookahead <= 'z')) ADVANCE(210); @@ -2818,7 +2819,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 211: ACCEPT_TOKEN(sym_css_identifier); if (lookahead == '-' || - ('0' <= lookahead && lookahead <= '9') || + ('/' <= lookahead && lookahead <= ':') || ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' || ('a' <= lookahead && lookahead <= 'z')) ADVANCE(211);