Skip to content

Commit

Permalink
Fix parsing (1+2)-3
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-duncan committed Aug 29, 2024
1 parent 793f8a0 commit 1ae7719
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/wgsl_scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ export class WgslScanner {
}
const ti = this._tokens.length - 1;
const isIdentOrLiteral = TokenTypes.literal_or_ident.indexOf(this._tokens[ti].type) != -1;
if (isIdentOrLiteral && nextLexeme != ">") {
if ((isIdentOrLiteral || this._tokens[ti].type == TokenTypes.tokens.paren_right) && nextLexeme != ">") {
this._addToken(matchedType);
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions test/tests/test_scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { test, group } from "../test.js";
import { WgslScanner, TokenTypes } from "../../../wgsl_reflect.module.js";

group("Scanner", function () {
test("(1+2)-3;", function (test) {
const scanner = new WgslScanner("(1+2)-3;");
const tokens = scanner.scanTokens();
test.equals(tokens.length, 9);
test.equals(tokens[5].type, TokenTypes.tokens.minus);
});
test("bar--;", function (test) {
const scanner = new WgslScanner("bar--;");
const tokens = scanner.scanTokens();
Expand Down
2 changes: 1 addition & 1 deletion wgsl_reflect.module.js

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

2 changes: 1 addition & 1 deletion wgsl_reflect.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wgsl_reflect.node.js

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

2 changes: 1 addition & 1 deletion wgsl_reflect.node.js.map

Large diffs are not rendered by default.

0 comments on commit 1ae7719

Please sign in to comment.