Skip to content

Commit

Permalink
Sync with winglang/wing (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: MarkMcCulloh <[email protected]>
  • Loading branch information
github-actions[bot] and MarkMcCulloh authored Apr 19, 2024
1 parent d66dd90 commit bd1d35c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
61 changes: 39 additions & 22 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -62,11 +84,9 @@ static bool scan_whitespace_and_comments(TSLexer * lexer) {
skip(lexer);
}
}
} else {
return false;
}
} else {
return true;
break;
}
}
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit bd1d35c

Please sign in to comment.