diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-09-14 22:22:41 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-09-14 22:22:41 +0200 |
commit | be988fbc200620bfff8657b7baf868234e899e13 (patch) | |
tree | 9089b4d1fd6aaaae08a69ac898dc6199bf164c87 /grammar.js | |
parent | 642d5264e0d7b3d3870d13c2cc4a04987ee65ab6 (diff) |
Lots of changes once again!
Diffstat (limited to 'grammar.js')
-rw-r--r-- | grammar.js | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -7,10 +7,18 @@ module.exports = grammar({ document: $ => repeat($._toplevel), _toplevel: $ => choice($.comment, $.node), - comment: $ => seq('/', $.node), - node: $ => seq($.node_name, optional($.attrs), $.node_body), + comment: $ => seq( + '/', + optional(field('name', $.ident)), + optional(field('attrs', $.attr_list)), + field('body', $.node_body), + ), + node: $ => seq( + field('name', $.ident), + optional(field('attrs', $.attr_list)), + field('body', $.node_body), + ), - node_name: $ => IDENT, node_body: $ => seq( '{', choice( @@ -20,19 +28,25 @@ module.exports = grammar({ '}', ), - attrs: $ => repeat1(choice( + attr_list: $ => repeat1(choice( $.attr, $.id_attr, $.class_attr, )), - attr: $ => seq(IDENT, '=', /"(\\["\\]|[^"\\])+"/), - id_attr: $ => seq('#', token.immediate(IDENT)), - class_attr: $ => seq('.', token.immediate(IDENT)), + attr: $ => seq( + field('name', $.ident), + '=', + field('value', $.string) + ), + id_attr: $ => seq('#', alias(token.immediate(IDENT), $.ident)), + class_attr: $ => seq('.', alias(token.immediate(IDENT), $.ident)), text: $ => repeat1(choice( /(\\[@}\\]|[^@}\\])+/, seq('@', $._toplevel), )), + ident: $ => IDENT, + string: $ => /"(\\["\\]|[^"\\])+"/, }, }) |