Skip to content

Commit

Permalink
Add precedence for embedded engine names
Browse files Browse the repository at this point in the history
  • Loading branch information
kolen committed Feb 17, 2024
1 parent 3591c61 commit 5886ed4
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 24 deletions.
16 changes: 14 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,23 @@ module.exports = grammar({
$.embedded_engine_name,
optional($.attrs),
':',
$._text_nested
optional($._space),
optional($._element_rest_text),
optional($._text_nested)
),

embedded_engine_name: $ => choice(
'markdown', 'textile', 'rdoc', 'coffee', 'less', 'sass', 'scss', 'javascript', 'css', 'ruby'
// These keywords are not supported as tag names for now
token(prec(1, 'markdown')),
token(prec(1, 'textile')),
token(prec(1, 'rdoc')),
token(prec(1, 'coffee')),
token(prec(1, 'less')),
token(prec(1, 'sass')),
token(prec(1, 'scss')),
token(prec(1, 'javascript')),
token(prec(1, 'css')),
token(prec(1, 'ruby'))
),

verbatim_text: $ => seq(
Expand Down
146 changes: 124 additions & 22 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1315,53 +1315,155 @@
"value": ":"
},
{
"type": "SYMBOL",
"name": "_text_nested"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_space"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_element_rest_text"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_text_nested"
},
{
"type": "BLANK"
}
]
}
]
},
"embedded_engine_name": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "markdown"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "markdown"
}
}
},
{
"type": "STRING",
"value": "textile"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "textile"
}
}
},
{
"type": "STRING",
"value": "rdoc"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "rdoc"
}
}
},
{
"type": "STRING",
"value": "coffee"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "coffee"
}
}
},
{
"type": "STRING",
"value": "less"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "less"
}
}
},
{
"type": "STRING",
"value": "sass"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "sass"
}
}
},
{
"type": "STRING",
"value": "scss"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "scss"
}
}
},
{
"type": "STRING",
"value": "javascript"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "javascript"
}
}
},
{
"type": "STRING",
"value": "css"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "css"
}
}
},
{
"type": "STRING",
"value": "ruby"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "ruby"
}
}
}
]
},
Expand Down
36 changes: 36 additions & 0 deletions test/corpus/embedded_engine.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,39 @@ javascript:
(source_file
(embedded_engine
(embedded_engine_name)))

===================================
Embedded engine with inline content
===================================

javascript: alert();

---

(source_file
(embedded_engine
(embedded_engine_name)))

=============================================
Embedded engine with inline content, no space
=============================================

javascript:alert();

---

(source_file
(embedded_engine
(embedded_engine_name)))

=====================
Empty embedded engine
=====================

javascript:

---

(source_file
(embedded_engine
(embedded_engine_name)))

0 comments on commit 5886ed4

Please sign in to comment.