From 96d070c3700692858035f3524cc0ad944cef2594 Mon Sep 17 00:00:00 2001 From: Matthew Toohey Date: Sun, 21 Jan 2024 20:56:11 -0500 Subject: [PATCH] fix handling of trailing lambdas in matchexpr --- src/scanner.c | 18 ++++++++++- test/corpus/corpus.txt | 70 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/scanner.c b/src/scanner.c index d7ec06d..31658c4 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -14,6 +13,7 @@ enum TokenType { struct scanner { int close_braces_to_insert; + bool insert_open_brace; int semis_to_insert; bool no_final_semi_insert; bool eof_semi_inserted; @@ -25,6 +25,7 @@ struct scanner { void scanner_reset(struct scanner *scanner) { scanner->close_braces_to_insert = 0; + scanner->insert_open_brace = false; scanner->semis_to_insert = 0; scanner->no_final_semi_insert = false; scanner->eof_semi_inserted = false; @@ -191,6 +192,12 @@ bool tree_sitter_koka_external_scanner_scan(void *payload, TSLexer *lexer, lexer->result_symbol = Semi; return true; } + if (scanner->insert_open_brace) { + scanner->insert_open_brace = false; + if (valid_symbols[OpenBrace]) + lexer->result_symbol = OpenBrace; + return true; + } lexer->mark_end(lexer); @@ -302,6 +309,15 @@ bool tree_sitter_koka_external_scanner_scan(void *payload, TSLexer *lexer, scanner->no_final_semi_insert = true; } lexer->result_symbol = Semi; + + prev_indent_length = + scanner->stack_len != 0 ? scanner->stack[scanner->stack_len - 1] : 0; + if (prev_indent_length < indent_length) { + scanner->insert_open_brace = true; + scanner_push_indent(scanner, indent_length); + scanner->no_final_semi_insert = true; + } + return true; } } diff --git a/test/corpus/corpus.txt b/test/corpus/corpus.txt index f9e49fc..b4b7ab7 100644 --- a/test/corpus/corpus.txt +++ b/test/corpus/corpus.txt @@ -3074,3 +3074,73 @@ fun foo() (atom (literal (int)))))))))))))))))))))))) + +========================= +block argument with mask +========================= + +fun foo() { + match mask + baz + Quux -> 32 + +--- + +(program + (moduledecl) + (modulebody + (topdecl + (puredecl + (funid + (identifier + (varid + (id)))) + (funbody + (bodyexpr + (blockexpr + (expr + (block + (statements + (statement + (basicexpr + (matchexpr + (expr + (basicexpr + (opexpr + (prefixexpr + (appexpr + (appexpr + (atom + (mask + (tbasic + (typeapp + (typecon + (varid + (id)))))))) + (block + (statements + (statement + (basicexpr + (opexpr + (prefixexpr + (appexpr + (atom + (qidentifier + (identifier + (varid + (id))))))))))))))))) + (matchrules + (matchrule + (patterns + (pattern + (qconstructor + (conid)))) + (blockexpr + (expr + (basicexpr + (opexpr + (prefixexpr + (appexpr + (atom + (literal + (int))))))))))))))))))))))))