Skip to content

Commit

Permalink
fix grammar breaking on parens
Browse files Browse the repository at this point in the history
  • Loading branch information
wrapperup committed Mar 7, 2024
1 parent 4522cd8 commit 0915d91
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 299 deletions.
20 changes: 11 additions & 9 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = grammar({
extras: $ => [/\s/],
rules: {
template: $ => repeat(choice(
$.content,
$.tag,
$.content
)),

content: $ => prec.right(/[^(\{\{)]+/),
content: () => prec.right(repeat1(/[^\{]+|\{/)),

tag: $ => seq(
choice("{{", "{{-"),
Expand All @@ -31,18 +31,20 @@ module.exports = grammar({
$.comment,
),

filter: $ => repeat1(seq(
"|>",
alias($._code, $.code)
)),

// General rule for keyword tags
// It just tries to match the first word in a tag block,
// plus any other special characters that might be present
keyword: $ => /[a-z>][a-zA-Z]*? |if|for|include|set|import|export|layout|function/,
keyword: () => /[a-z>][a-zA-Z]*? |if|for|include|set|import|export|layout|function/,

code_snippet: $ => seq(/[a-zA-Z>\.\(\)\!_\?]/, $._code),
close_keyword: $ => /\/([a-zA-Z]+|if|for|include|set|import|export|layout|function)/,

filter: $ => repeat1(seq(
"|>",
alias($._code, $.code)
)),
close_keyword: () => /\/([a-zA-Z]+|if|for|include|set|import|export|layout|function)/,

comment: $ => /#[^#]+#/,
comment: () => /#[^#]+#/,
}
});
12 changes: 7 additions & 5 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"members": [
{
"type": "SYMBOL",
"name": "tag"
"name": "content"
},
{
"type": "SYMBOL",
"name": "content"
"name": "tag"
}
]
}
Expand All @@ -21,8 +21,11 @@
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "PATTERN",
"value": "[^(\\{\\{)]+"
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[^\\{]+|\\{"
}
}
},
"tag": {
Expand Down Expand Up @@ -198,4 +201,3 @@
"inline": [],
"supertypes": []
}

Loading

0 comments on commit 0915d91

Please sign in to comment.