From 61737cddac6f63188cf9ddeee1f961f7e66eca43 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Tue, 20 Oct 2020 12:00:34 -0700 Subject: [PATCH] Add colon (':') to list of lookahead tokens that disable automatic semicolon insertion. --- common/corpus/types.txt | 36 ++++++++++++++++++++++++++++++++++++ common/scanner.h | 1 + 2 files changed, 37 insertions(+) diff --git a/common/corpus/types.txt b/common/corpus/types.txt index 0e233e07..33beb919 100644 --- a/common/corpus/types.txt +++ b/common/corpus/types.txt @@ -123,6 +123,42 @@ type Something = { (predefined_type) (type_annotation (predefined_type)))))) +========================================================== +Automatic semicolon disabled before return type +========================================================== + +function f(): any { + 'a'; + 'b'; +} + +function +f +() + : + any { + 'a' + 'b' +} + +--- + +(program + (function_declaration + (identifier) + (formal_parameters) + (type_annotation (predefined_type)) + (statement_block + (expression_statement (string)) + (expression_statement (string)))) + (function_declaration + (identifier) + (formal_parameters) + (type_annotation (predefined_type)) + (statement_block + (expression_statement (string)) + (expression_statement (string))))) + ======================================= Array types ======================================= diff --git a/common/scanner.h b/common/scanner.h index f7758890..a1f53e32 100644 --- a/common/scanner.h +++ b/common/scanner.h @@ -98,6 +98,7 @@ static inline bool external_scanner_scan(void *payload, TSLexer *lexer, const bo case '|': case '&': case '/': + case ':': return false; // Don't insert a semicolon before a '[' or '(', unless we're parsing