Skip to content

Commit bd1d35c

Browse files
Sync with winglang/wing (#5)
Co-authored-by: MarkMcCulloh <[email protected]>
1 parent d66dd90 commit bd1d35c

File tree

5 files changed

+43
-26
lines changed

5 files changed

+43
-26
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "tree-sitter-wing"
33
description = "Wing grammar for tree-sitter"
4-
version = "0.70.11"
4+
version = "0.71.0"
55
license = "MIT"
66
readme = "README.md"
77
keywords = ["incremental", "parsing", "tree-sitter", "wing"]

Makefile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@winglang/tree-sitter-wing",
3-
"version": "0.70.11",
3+
"version": "0.71.0",
44
"description": "winglang grammar for tree-sitter",
55
"main": "bindings/node",
66
"types": "bindings/node",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "tree-sitter-wing"
77
description = "Wing grammar for tree-sitter"
8-
version = "0.70.11"
8+
version = "0.71.0"
99
keywords = ["incremental", "parsing", "tree-sitter", "wing"]
1010
classifiers = [
1111
"Intended Audience :: Developers",

src/scanner.c

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,35 @@ static void skip(TSLexer * lexer) {
2929
lexer -> advance(lexer, true);
3030
}
3131

32+
/**
33+
* Skip through a strings until the end of the string or the end of the file.
34+
* Handle any escaped \"
35+
* Assumes all initial whitespace has been skipped already
36+
*/
37+
static void skip_strings(TSLexer * lexer) {
38+
while (lexer -> lookahead == '"') {
39+
skip(lexer);
40+
while (lexer -> lookahead != 0) {
41+
if (lexer -> lookahead == '\\') {
42+
skip(lexer);
43+
if (lexer -> lookahead == '"') {
44+
skip(lexer);
45+
}
46+
} else if (lexer -> lookahead == '"') {
47+
skip(lexer);
48+
break;
49+
} else {
50+
skip(lexer);
51+
}
52+
}
53+
}
54+
}
55+
3256
/**
3357
* Skip through any whitespace or comments until
3458
* we've reached a non-whitespace/comment character
35-
*
36-
* @return true if we've reached a non-whitespace/comment character, false otherwise (comment is unterminated)
3759
*/
38-
static bool scan_whitespace_and_comments(TSLexer * lexer) {
60+
static void skip_whitespace_and_comments(TSLexer * lexer) {
3961
for (;;) {
4062
while (iswspace(lexer -> lookahead)) {
4163
skip(lexer);
@@ -62,11 +84,9 @@ static bool scan_whitespace_and_comments(TSLexer * lexer) {
6284
skip(lexer);
6385
}
6486
}
65-
} else {
66-
return false;
6787
}
6888
} else {
69-
return true;
89+
break;
7090
}
7191
}
7292
}
@@ -179,25 +199,22 @@ static bool scan_automatic_block(TSLexer * lexer) {
179199
lexer -> mark_end(lexer);
180200

181201
for (;;) {
182-
if (lexer -> lookahead == 0)
183-
return true;
184-
if (lexer -> lookahead == '}')
185-
return false;
186-
if (lexer -> is_at_included_range_start(lexer))
187-
return true;
188-
if (!iswspace(lexer -> lookahead))
189-
return false;
202+
skip_whitespace_and_comments(lexer);
203+
skip_strings(lexer);
204+
205+
switch (lexer -> lookahead) {
206+
case '{':
207+
return false;
208+
case '}':
209+
return true;
210+
case ';':
211+
return true;
212+
case 0:
213+
return true;
214+
}
190215
skip(lexer);
191216
}
192217

193-
skip(lexer);
194-
195-
if (!scan_whitespace_and_comments(lexer))
196-
return false;
197-
198-
if (lexer -> lookahead != '{')
199-
return false;
200-
201218
return true;
202219
}
203220

0 commit comments

Comments
 (0)