From e38f23a1bd6e0ee093655e1f241e524795f21fec Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 5 Oct 2026 23:57:38 +0200 Subject: Support single-line comments --- tools/tree-sitter/grammar.js | 5 ++++- tools/tree-sitter/test/corpus/comments.txt | 25 +++++++++++++++++++++++++ tools/tree-sitter/test/corpus/trailing_text.txt | 16 ---------------- 3 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 tools/tree-sitter/test/corpus/comments.txt delete mode 100644 tools/tree-sitter/test/corpus/trailing_text.txt (limited to 'tools/tree-sitter') diff --git a/tools/tree-sitter/grammar.js b/tools/tree-sitter/grammar.js index b7129df..a43c947 100644 --- a/tools/tree-sitter/grammar.js +++ b/tools/tree-sitter/grammar.js @@ -43,7 +43,10 @@ module.exports = grammar({ trailing_content: $ => token(seq(/[^\s]/, repeat(/[\s\S]/))), - comment: $ => token(seq('(*', /[^*]*\*+([^)*][^*]*\*+)*/, ')')), + comment: $ => token(choice( + seq('(*', /[^*]*\*+([^)*][^*]*\*+)*/, ')'), + seq('--', /[^\n]*/), + )), identifier: $ => /[A-Za-z_][A-Za-z0-9_]*/, diff --git a/tools/tree-sitter/test/corpus/comments.txt b/tools/tree-sitter/test/corpus/comments.txt new file mode 100644 index 0000000..8c933ea --- /dev/null +++ b/tools/tree-sitter/test/corpus/comments.txt @@ -0,0 +1,25 @@ +================== +comments +================== + +module + +(* + This is multi-line + dockblock +*) + +-- This is a one-line comment. + +end. + +Everything after the module terminator is ignored and is never scanned, so it +does not have to be Elna: proc 1 2 3 "unterminated + +--- + +(source_file + (module_declaration + (comment) + (comment)) + (trailing_content)) diff --git a/tools/tree-sitter/test/corpus/trailing_text.txt b/tools/tree-sitter/test/corpus/trailing_text.txt deleted file mode 100644 index bb39c86..0000000 --- a/tools/tree-sitter/test/corpus/trailing_text.txt +++ /dev/null @@ -1,16 +0,0 @@ -================== -trailing_text -================== - -module - -end. - -Everything after the module terminator is ignored and is never scanned, so it -does not have to be Elna: proc 1 2 3 "unterminated - ---- - -(source_file - (module_declaration) - (trailing_content)) -- cgit v1.2.3