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 --- boot/lexer.ll | 1 + testsuite/compilable/comments.elna | 13 +++++++++++ testsuite/compilable/trailing_text.elna | 6 ------ testsuite/fail_compilation/case_type_mismatch.elna | 2 +- tools/tree-sitter/grammar.js | 5 ++++- tools/tree-sitter/test/corpus/comments.txt | 25 ++++++++++++++++++++++ tools/tree-sitter/test/corpus/trailing_text.txt | 16 -------------- 7 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 testsuite/compilable/comments.elna delete mode 100644 testsuite/compilable/trailing_text.elna create mode 100644 tools/tree-sitter/test/corpus/comments.txt delete mode 100644 tools/tree-sitter/test/corpus/trailing_text.txt diff --git a/boot/lexer.ll b/boot/lexer.ll index 4452956..c6a5498 100644 --- a/boot/lexer.ll +++ b/boot/lexer.ll @@ -76,6 +76,7 @@ EXPONENT [eE][+-]?[[:digit:]]+ return yy::parser::make_YYEOF(this->location); } } +--[^\n]* ; \(\* { this->comment_start = this->location; BEGIN(IN_COMMENT); diff --git a/testsuite/compilable/comments.elna b/testsuite/compilable/comments.elna new file mode 100644 index 0000000..502ac21 --- /dev/null +++ b/testsuite/compilable/comments.elna @@ -0,0 +1,13 @@ +module + +(* + This is multi-line + docblock +*) + +-- This is a single-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 diff --git a/testsuite/compilable/trailing_text.elna b/testsuite/compilable/trailing_text.elna deleted file mode 100644 index 0a95516..0000000 --- a/testsuite/compilable/trailing_text.elna +++ /dev/null @@ -1,6 +0,0 @@ -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 diff --git a/testsuite/fail_compilation/case_type_mismatch.elna b/testsuite/fail_compilation/case_type_mismatch.elna index f2db7e7..10e55ab 100644 --- a/testsuite/fail_compilation/case_type_mismatch.elna +++ b/testsuite/fail_compilation/case_type_mismatch.elna @@ -4,7 +4,7 @@ var begin case x of - 1: (* ok *) + 1: | true: (* @Error Invalid operands of type 'Int' and 'Bool' for operator = *) end end. 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