Skip to content

Commit

Permalink
Fixed IF+Colon
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpo committed Feb 4, 2024
1 parent 0e2a375 commit 8a09eb0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,8 @@ export default class Parser {

let object = { kind: "IfStatement" } as IFStatement;

this.config.skipColonAction = true;

let condition = this.parseExpression();
object.test = condition;

Expand Down Expand Up @@ -1345,11 +1347,13 @@ export default class Parser {
this.expect(TokenType.Semicolon);
this.eat();

this.config.skipColonAction = true;

let increaseExpr = this.parseExpression();

object.increaser = increaseExpr;

if (!this.at() || this.at().type !== TokenType.OpenBrace) {
if (!this.at() || (this.at().type !== TokenType.Colon && this.at().type !== TokenType.OpenBrace)) {
throw Err(
"SyntaxError",
`Expected '{ or :' after 'for' statement${this.where()}`
Expand Down Expand Up @@ -1399,6 +1403,8 @@ export default class Parser {
this.expect(TokenType.WHILE);
this.eat();

this.config.skipColonAction = true;

let object = { kind: "WhileStatement" } as WhileStatement;

let condition = this.parseExpression();
Expand Down

0 comments on commit 8a09eb0

Please sign in to comment.