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] 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) {