Skip to content

Commit

Permalink
Add boolean attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kolen committed Feb 17, 2024
1 parent 5886ed4 commit d71f7ac
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const make_attr_delimited = (token_suffix) => {
return ($) => choice(
seq('*', alias($[`_attr_value_ruby_${token_suffix}`], $.attr_splat)),
$.attr_boolean,
seq(
field('name', $.attr_name),
field('assignment', choice($.attr_assignment, $.attr_assignment_noescape)),
Expand Down Expand Up @@ -163,6 +164,7 @@ module.exports = grammar({
$._attr_value_ruby
// TODO: many more
),
attr_boolean: $ => $.attr_name,

element_text: $ => seq(
optional($._space),
Expand Down
16 changes: 16 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@
}
]
},
{
"type": "SYMBOL",
"name": "attr_boolean"
},
{
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -694,6 +698,10 @@
}
]
},
{
"type": "SYMBOL",
"name": "attr_boolean"
},
{
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -774,6 +782,10 @@
}
]
},
{
"type": "SYMBOL",
"name": "attr_boolean"
},
{
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -923,6 +935,10 @@
}
]
},
"attr_boolean": {
"type": "SYMBOL",
"name": "attr_name"
},
"element_text": {
"type": "SEQ",
"members": [
Expand Down
19 changes: 19 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,32 @@
"multiple": false,
"required": false,
"types": [
{
"type": "attr_boolean",
"named": true
},
{
"type": "attr_splat",
"named": true
}
]
}
},
{
"type": "attr_boolean",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "attr_name",
"named": true
}
]
}
},
{
"type": "attr_name",
"named": true,
Expand Down
16 changes: 16 additions & 0 deletions test/corpus/attributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,19 @@ a[*attrs]
(attrs
(attr
(attr_splat)))))

==================
Boolean attributes
==================

button[disabled]

-----

(source_file
(element
(tag_name)
(attrs
(attr
(attr_boolean
(attr_name))))))

0 comments on commit d71f7ac

Please sign in to comment.