diff --git a/tree-sitter-tako/grammar.js b/tree-sitter-tako/grammar.js index fafd1fd1..08981c21 100644 --- a/tree-sitter-tako/grammar.js +++ b/tree-sitter-tako/grammar.js @@ -64,7 +64,7 @@ module.exports = grammar({ extras: ($) => [$.nesting_comment, $.single_line_comment, "\r", "\n", "\t", " "], rules: { // TODO: add the actual grammar rules - source_file: ($) => seq(optional($.shebang), optional($._non_empty_body)), + source_file: ($) => seq(optional($.shebang), separated_one(optional($._non_empty_body), $.heading)), _non_empty_body: ($) => separated_one($._statement, ';'), _statement: ($) => choice( $.block, @@ -146,6 +146,7 @@ module.exports = grammar({ // TODO: Add semver. shebang: (_) => seq('#!', /[^\n\r]*/), single_line_comment: (_) => seq('//', /.*/), + heading: (_) => /====*[^='"]*====*/, ...operators_gen(), } }); diff --git a/tree-sitter-tako/playground.sh b/tree-sitter-tako/playground.sh new file mode 100755 index 00000000..46103bde --- /dev/null +++ b/tree-sitter-tako/playground.sh @@ -0,0 +1 @@ +tree-sitter generate && tree-sitter build --wasm && tree-sitter playground diff --git a/tree-sitter-tako/src/grammar.json b/tree-sitter-tako/src/grammar.json index d151b6f4..2380a414 100644 --- a/tree-sitter-tako/src/grammar.json +++ b/tree-sitter-tako/src/grammar.json @@ -18,14 +18,43 @@ ] }, { - "type": "CHOICE", + "type": "SEQ", "members": [ { - "type": "SYMBOL", - "name": "_non_empty_body" + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_non_empty_body" + }, + { + "type": "BLANK" + } + ] }, { - "type": "BLANK" + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "heading" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_non_empty_body" + }, + { + "type": "BLANK" + } + ] + } + ] + } } ] } @@ -498,6 +527,10 @@ } ] }, + "heading": { + "type": "PATTERN", + "value": "====*[^='\"]*====*" + }, "comma": { "type": "PREC_LEFT", "value": -1, diff --git a/tree-sitter-tako/src/node-types.json b/tree-sitter-tako/src/node-types.json index 44a36905..0de4f021 100644 --- a/tree-sitter-tako/src/node-types.json +++ b/tree-sitter-tako/src/node-types.json @@ -2661,6 +2661,10 @@ "type": "has_type", "named": true }, + { + "type": "heading", + "named": true + }, { "type": "hex_literal", "named": true @@ -2835,6 +2839,10 @@ "type": "float_literal", "named": true }, + { + "type": "heading", + "named": true + }, { "type": "ident", "named": true