diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-10-05 23:57:38 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-10-05 23:57:59 +0200 |
| commit | e38f23a1bd6e0ee093655e1f241e524795f21fec (patch) | |
| tree | 5a5dd8223f6a01dd4ea2ec37a399b76a7519b6e3 | |
| parent | a9f6cfb6a8b6d38057faca067c015da1f72cf62d (diff) | |
| download | elna-e38f23a1bd6e0ee093655e1f241e524795f21fec.tar.gz | |
Support single-line comments
| -rw-r--r-- | boot/lexer.ll | 1 | ||||
| -rw-r--r-- | testsuite/compilable/comments.elna (renamed from testsuite/compilable/trailing_text.elna) | 7 | ||||
| -rw-r--r-- | testsuite/fail_compilation/case_type_mismatch.elna | 2 | ||||
| -rw-r--r-- | tools/tree-sitter/grammar.js | 5 | ||||
| -rw-r--r-- | tools/tree-sitter/test/corpus/comments.txt (renamed from tools/tree-sitter/test/corpus/trailing_text.txt) | 13 |
5 files changed, 24 insertions, 4 deletions
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/trailing_text.elna b/testsuite/compilable/comments.elna index 0a95516..502ac21 100644 --- a/testsuite/compilable/trailing_text.elna +++ b/testsuite/compilable/comments.elna @@ -1,5 +1,12 @@ 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 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/trailing_text.txt b/tools/tree-sitter/test/corpus/comments.txt index bb39c86..8c933ea 100644 --- a/tools/tree-sitter/test/corpus/trailing_text.txt +++ b/tools/tree-sitter/test/corpus/comments.txt @@ -1,9 +1,16 @@ ================== -trailing_text +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 @@ -12,5 +19,7 @@ does not have to be Elna: proc 1 2 3 "unterminated --- (source_file - (module_declaration) + (module_declaration + (comment) + (comment)) (trailing_content)) |
