diff --git a/grammar.js b/grammar.js index 47af69f..39340ed 100644 --- a/grammar.js +++ b/grammar.js @@ -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)), @@ -163,6 +164,7 @@ module.exports = grammar({ $._attr_value_ruby // TODO: many more ), + attr_boolean: $ => $.attr_name, element_text: $ => seq( optional($._space), diff --git a/src/grammar.json b/src/grammar.json index c02fcce..df8800e 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -614,6 +614,10 @@ } ] }, + { + "type": "SYMBOL", + "name": "attr_boolean" + }, { "type": "SEQ", "members": [ @@ -694,6 +698,10 @@ } ] }, + { + "type": "SYMBOL", + "name": "attr_boolean" + }, { "type": "SEQ", "members": [ @@ -774,6 +782,10 @@ } ] }, + { + "type": "SYMBOL", + "name": "attr_boolean" + }, { "type": "SEQ", "members": [ @@ -923,6 +935,10 @@ } ] }, + "attr_boolean": { + "type": "SYMBOL", + "name": "attr_name" + }, "element_text": { "type": "SEQ", "members": [ diff --git a/src/node-types.json b/src/node-types.json index 9ded81d..e6bbfd7 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -42,6 +42,10 @@ "multiple": false, "required": false, "types": [ + { + "type": "attr_boolean", + "named": true + }, { "type": "attr_splat", "named": true @@ -49,6 +53,21 @@ ] } }, + { + "type": "attr_boolean", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "attr_name", + "named": true + } + ] + } + }, { "type": "attr_name", "named": true, diff --git a/test/corpus/attributes.txt b/test/corpus/attributes.txt index 5427da3..3635fc9 100644 --- a/test/corpus/attributes.txt +++ b/test/corpus/attributes.txt @@ -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))))))