fix(grammar): make brace and keyword separately queryable
This commit is contained in:
+12
-6
@@ -26,20 +26,27 @@ export default grammar({
|
||||
content: _ => token(prec(-1, /([^{]|\{[^A-Za-z/])+/)),
|
||||
|
||||
block_open: $ => seq(
|
||||
$._block_open_start,
|
||||
"{",
|
||||
$.block_keyword,
|
||||
":",
|
||||
$.block_name,
|
||||
optional($.attributes),
|
||||
"}",
|
||||
),
|
||||
|
||||
block_close: $ => seq(
|
||||
$._block_close_start,
|
||||
"{",
|
||||
"/",
|
||||
$.block_keyword,
|
||||
":",
|
||||
$.block_name,
|
||||
"}",
|
||||
),
|
||||
|
||||
lang_tag: $ => seq(
|
||||
$._lang_start,
|
||||
"{",
|
||||
$.lang_keyword,
|
||||
":",
|
||||
$.lang_text,
|
||||
"}",
|
||||
),
|
||||
@@ -65,9 +72,8 @@ export default grammar({
|
||||
prefix_argument: _ => /[A-Za-z][A-Za-z0-9 _-]*/,
|
||||
lang_text: _ => /[^}]+/,
|
||||
|
||||
_block_open_start: _ => /\{[Bb][Ll][Oo][Cc][Kk]:/,
|
||||
_block_close_start: _ => /\{\/[Bb][Ll][Oo][Cc][Kk]:/,
|
||||
_lang_start: _ => /\{[Ll][Aa][Nn][Gg]:/,
|
||||
block_keyword: _ => token(prec(1, /[Bb][Ll][Oo][Cc][Kk]/)),
|
||||
lang_keyword: _ => token(prec(1, /[Ll][Aa][Nn][Gg]/)),
|
||||
_space: _ => /[ \t]+/,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
; Punctuation
|
||||
"{" @punctuation.bracket
|
||||
"}" @punctuation.bracket
|
||||
|
||||
; Keywords that introduce a tag form. The grammar exposes the opening
|
||||
; sequence as a hidden node, so capture the parent and let the editor
|
||||
; colour the leading {block:, {/block:, {lang: literally via the
|
||||
; tokenizer. The colon delimiter inside a variable_prefix tag is captured
|
||||
; below.
|
||||
":" @punctuation.delimiter
|
||||
"-" @punctuation.delimiter
|
||||
"/" @punctuation.delimiter
|
||||
"=" @operator
|
||||
|
||||
; Block and lang keywords inside their tags: the literal "block" / "lang".
|
||||
(block_keyword) @keyword.directive
|
||||
(lang_keyword) @keyword.directive
|
||||
|
||||
; Block names. Known data-block names get @function.builtin; If/IfNot
|
||||
; toggles get @keyword.conditional (theme authors may define arbitrary
|
||||
; If* / IfNot* names via <meta name="if:..."> so we match by prefix).
|
||||
|
||||
Generated
+51
-13
@@ -48,9 +48,17 @@
|
||||
"block_open": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_block_open_start"
|
||||
"name": "block_keyword"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
@@ -77,9 +85,21 @@
|
||||
"block_close": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "/"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_block_close_start"
|
||||
"name": "block_keyword"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
@@ -94,9 +114,17 @@
|
||||
"lang_tag": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_lang_start"
|
||||
"name": "lang_keyword"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
@@ -250,17 +278,27 @@
|
||||
"type": "PATTERN",
|
||||
"value": "[^}]+"
|
||||
},
|
||||
"_block_open_start": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\{[Bb][Ll][Oo][Cc][Kk]:"
|
||||
"block_keyword": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[Bb][Ll][Oo][Cc][Kk]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"_block_close_start": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\{\\/[Bb][Ll][Oo][Cc][Kk]:"
|
||||
},
|
||||
"_lang_start": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\{[Ll][Aa][Nn][Gg]:"
|
||||
"lang_keyword": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[Ll][Aa][Nn][Gg]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"_space": {
|
||||
"type": "PATTERN",
|
||||
|
||||
Generated
+26
-2
@@ -38,9 +38,13 @@
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block_keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_name",
|
||||
"named": true
|
||||
@@ -60,6 +64,10 @@
|
||||
"type": "attributes",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_name",
|
||||
"named": true
|
||||
@@ -72,9 +80,13 @@
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "lang_keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "lang_text",
|
||||
"named": true
|
||||
@@ -150,6 +162,10 @@
|
||||
"type": "-",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "/",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ":",
|
||||
"named": false
|
||||
@@ -166,6 +182,10 @@
|
||||
"type": "attribute_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_name",
|
||||
"named": true
|
||||
@@ -186,6 +206,10 @@
|
||||
"type": "image",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "lang_keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "lang_text",
|
||||
"named": true
|
||||
|
||||
Generated
+602
-495
File diff suppressed because it is too large
Load Diff
@@ -9,8 +9,10 @@ Simple block
|
||||
(template
|
||||
(content)
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content))
|
||||
|
||||
@@ -25,12 +27,14 @@ Block with content
|
||||
(template
|
||||
(content)
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content)
|
||||
(variable
|
||||
(variable_name))
|
||||
(content)
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content))
|
||||
|
||||
@@ -45,14 +49,18 @@ Nested blocks
|
||||
(template
|
||||
(content)
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(variable
|
||||
(variable_name))
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content))
|
||||
|
||||
@@ -67,6 +75,7 @@ Block with one attribute
|
||||
(template
|
||||
(content)
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name)
|
||||
(attributes
|
||||
(attribute
|
||||
@@ -75,6 +84,7 @@ Block with one attribute
|
||||
(variable
|
||||
(variable_name))
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content))
|
||||
|
||||
@@ -89,6 +99,7 @@ Block with multiple attributes
|
||||
(template
|
||||
(content)
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name)
|
||||
(attributes
|
||||
(attribute
|
||||
@@ -98,6 +109,7 @@ Block with multiple attributes
|
||||
(attribute_name)
|
||||
(attribute_value))))
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content))
|
||||
|
||||
@@ -112,8 +124,10 @@ Case insensitive block keyword
|
||||
(template
|
||||
(content)
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content))
|
||||
|
||||
@@ -128,12 +142,16 @@ Conditional block
|
||||
(template
|
||||
(content)
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(block_open
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content)
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(block_close
|
||||
(block_keyword)
|
||||
(block_name))
|
||||
(content))
|
||||
|
||||
@@ -9,6 +9,7 @@ Simple lang tag
|
||||
(template
|
||||
(content)
|
||||
(lang_tag
|
||||
(lang_keyword)
|
||||
(lang_text))
|
||||
(content))
|
||||
|
||||
@@ -23,5 +24,6 @@ Lang tag with spaces and punctuation
|
||||
(template
|
||||
(content)
|
||||
(lang_tag
|
||||
(lang_keyword)
|
||||
(lang_text))
|
||||
(content))
|
||||
|
||||
Reference in New Issue
Block a user