From 01dfab2a0fd7ec4b1cb26cb63174c934362dd8ea Mon Sep 17 00:00:00 2001 From: kolen Date: Sun, 18 Feb 2024 19:14:06 +0300 Subject: [PATCH] Use relaxed pattern for attributes --- grammar.js | 4 ++-- src/grammar.json | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/grammar.js b/grammar.js index 7c5cd63..2787a1e 100644 --- a/grammar.js +++ b/grammar.js @@ -156,7 +156,7 @@ module.exports = grammar({ ), ), attr_name: $ => $._attr_name, - _attr_name: $ => /[a-zA-Z0-9_-]+/, // TODO: very wrong + _attr_name: $ => token(prec(-2, /[^ \t\n\\0\"\'> /[ \t]*=[ \t]*/, attr_assignment_noescape: $ => /[ \t]*==[ \t]*/, attr_value: $ => choice( @@ -176,7 +176,7 @@ module.exports = grammar({ optional($._text_nested) ), - _element_rest_text: $ => token(prec(-2, /[^ \t][^\n]*/)), + _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|-)+)*)/ diff --git a/src/grammar.json b/src/grammar.json index cce6224..29128f9 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -914,8 +914,15 @@ "name": "_attr_name" }, "_attr_name": { - "type": "PATTERN", - "value": "[a-zA-Z0-9_-]+" + "type": "TOKEN", + "content": { + "type": "PREC", + "value": -2, + "content": { + "type": "PATTERN", + "value": "[^ \\t\\n\\\\0\\\"\\'>