From be988fbc200620bfff8657b7baf868234e899e13 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 14 Sep 2024 22:22:41 +0200 Subject: Lots of changes once again! --- grammar.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'grammar.js') diff --git a/grammar.js b/grammar.js index a18091c..3cf8ca3 100644 --- a/grammar.js +++ b/grammar.js @@ -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: $ => /"(\\["\\]|[^"\\])+"/, }, }) -- cgit v1.2.3