From 276429290ba8c12dfd5dcf2592f561984a9bff4a Mon Sep 17 00:00:00 2001 From: susliko <1istoobig@gmail.com> Date: Mon, 18 Sep 2023 22:15:00 +0300 Subject: [PATCH 1/2] Fix `derives` clause on a new line Fixes #349 Now `automatic_semicolon` is not emmited when newline is followed by "derives" --- corpus/definitions.txt | 4 +++- grammar.js | 1 + src/scanner.c | 27 ++++++++++++++++++--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/corpus/definitions.txt b/corpus/definitions.txt index f57109f83..d573eaa95 100644 --- a/corpus/definitions.txt +++ b/corpus/definitions.txt @@ -502,7 +502,9 @@ class A ================================================================================ Class definitions (Scala 3) ================================================================================ -final case class C() extends A derives B, C.D +final case class C() + extends A + derives B, C.D -------------------------------------------------------------------------------- (compilation_unit diff --git a/grammar.js b/grammar.js index 260074d00..a7920883c 100644 --- a/grammar.js +++ b/grammar.js @@ -42,6 +42,7 @@ module.exports = grammar({ "catch", "finally", "extends", + "derives", "with", ], diff --git a/src/scanner.c b/src/scanner.c index 52a334fb4..b20bd0273 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -18,6 +18,7 @@ enum TokenType { CATCH, FINALLY, EXTENDS, + DERIVES, WITH, }; @@ -255,25 +256,33 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer, } if (valid_symbols[CATCH]) { - if (lexer->lookahead == 'c') { - return !scan_word(lexer, "catch"); - } - if (lexer->lookahead == 'f') { - return !scan_word(lexer, "finally"); + if (scan_word(lexer, "catch")) { + return false; } - return true; } if (valid_symbols[FINALLY]) { - return !scan_word(lexer, "finally"); + if (scan_word(lexer, "finally")) { + return false; + } } if (valid_symbols[EXTENDS]) { - return !scan_word(lexer, "extends"); + if (scan_word(lexer, "extends")) { + return false; + } } if (valid_symbols[WITH]) { - return !scan_word(lexer, "with"); + if (scan_word(lexer, "with")) { + return false; + } + } + + if (valid_symbols[DERIVES]) { + if (scan_word(lexer, "derives")) { + return false; + } } if (newline_count > 1) { From 6ada5ca0b85da72fdbe5deb75fc0cc76a1c941e4 Mon Sep 17 00:00:00 2001 From: susliko <1istoobig@gmail.com> Date: Mon, 18 Sep 2023 22:34:36 +0300 Subject: [PATCH 2/2] Raise syntax complexity ceiling to 1400 --- script/smoke_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/smoke_test.sh b/script/smoke_test.sh index 8e6fa08a6..663073adb 100755 --- a/script/smoke_test.sh +++ b/script/smoke_test.sh @@ -5,7 +5,7 @@ SCALA_SCALA_LIBRARY_EXPECTED=100 SCALA_SCALA_COMPILER_EXPECTED=96 DOTTY_COMPILER_EXPECTED=83 -SYNTAX_COMPLEXITY_CEILING=1300 +SYNTAX_COMPLEXITY_CEILING=1400 if [ ! -d "$SCALA_SCALA_DIR" ]; then echo "\$SCALA_SCALA_DIR must be set"