diff --git a/Cargo.toml b/Cargo.toml index de0516f..a055f94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tree-sitter-wing" description = "Wing grammar for tree-sitter" -version = "0.70.11" +version = "0.71.0" license = "MIT" readme = "README.md" keywords = ["incremental", "parsing", "tree-sitter", "wing"] diff --git a/Makefile b/Makefile index e72ec04..41fd9b1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 0.70.11 +VERSION := 0.71.0 LANGUAGE_NAME := tree-sitter-wing diff --git a/package.json b/package.json index d1b56ad..960d05f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@winglang/tree-sitter-wing", - "version": "0.70.11", + "version": "0.71.0", "description": "winglang grammar for tree-sitter", "main": "bindings/node", "types": "bindings/node", diff --git a/pyproject.toml b/pyproject.toml index 54df340..42a0652 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "tree-sitter-wing" description = "Wing grammar for tree-sitter" -version = "0.70.11" +version = "0.71.0" keywords = ["incremental", "parsing", "tree-sitter", "wing"] classifiers = [ "Intended Audience :: Developers", diff --git a/src/scanner.c b/src/scanner.c index 0ebcccc..1de7b4b 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -29,13 +29,35 @@ static void skip(TSLexer * lexer) { lexer -> advance(lexer, true); } +/** + * Skip through a strings until the end of the string or the end of the file. + * Handle any escaped \" + * Assumes all initial whitespace has been skipped already + */ +static void skip_strings(TSLexer * lexer) { + while (lexer -> lookahead == '"') { + skip(lexer); + while (lexer -> lookahead != 0) { + if (lexer -> lookahead == '\\') { + skip(lexer); + if (lexer -> lookahead == '"') { + skip(lexer); + } + } else if (lexer -> lookahead == '"') { + skip(lexer); + break; + } else { + skip(lexer); + } + } + } +} + /** * Skip through any whitespace or comments until * we've reached a non-whitespace/comment character - * - * @return true if we've reached a non-whitespace/comment character, false otherwise (comment is unterminated) */ -static bool scan_whitespace_and_comments(TSLexer * lexer) { +static void skip_whitespace_and_comments(TSLexer * lexer) { for (;;) { while (iswspace(lexer -> lookahead)) { skip(lexer); @@ -62,11 +84,9 @@ static bool scan_whitespace_and_comments(TSLexer * lexer) { skip(lexer); } } - } else { - return false; } } else { - return true; + break; } } } @@ -179,25 +199,22 @@ static bool scan_automatic_block(TSLexer * lexer) { lexer -> mark_end(lexer); for (;;) { - if (lexer -> lookahead == 0) - return true; - if (lexer -> lookahead == '}') - return false; - if (lexer -> is_at_included_range_start(lexer)) - return true; - if (!iswspace(lexer -> lookahead)) - return false; + skip_whitespace_and_comments(lexer); + skip_strings(lexer); + + switch (lexer -> lookahead) { + case '{': + return false; + case '}': + return true; + case ';': + return true; + case 0: + return true; + } skip(lexer); } - skip(lexer); - - if (!scan_whitespace_and_comments(lexer)) - return false; - - if (lexer -> lookahead != '{') - return false; - return true; }