diff --git a/lex.js b/lex.js index d24183c..c49c67d 100644 --- a/lex.js +++ b/lex.js @@ -122,7 +122,7 @@ line = i + 1; break; } - previousLinesLength += this.newlines[i] + 1; + previousLinesLength = this.newlines[i] + 1; } return {line:line, pos:pos - previousLinesLength + 1}; } diff --git a/lex.js b/lex.js index d24183c..c49c67d 100644 --- a/lex.js +++ b/lex.js @@ -122,7 +122,7 @@ line = i + 1; break; } - previousLinesLength += this.newlines[i] + 1; + previousLinesLength = this.newlines[i] + 1; } return {line:line, pos:pos - previousLinesLength + 1}; } diff --git a/parse.js b/parse.js index 3af758c..b5f3041 100644 --- a/parse.js +++ b/parse.js @@ -43,7 +43,7 @@ }); // all reserved keywords -const Keywords = Object.freeze([ "if" ]); +const Keywords = Object.freeze([ "if", "on", "wait", "for", "map", "in" ]); // the types of AST nodes const ASTNode = Object.freeze({ @@ -59,6 +59,10 @@ Block:10, // a set of statements in a { } block }); +const StatementsWithSemicolon = Object.freeze([ + ASTNode.ExprStatement, +]); + // all reserved words that represent literals const Literals = Object.freeze({ "true": {node:ASTNode.Literal, value:true}, @@ -80,12 +84,12 @@ if (openError) return this.getError(openError); let { ast:statements, error, numMatched } = this.attemptSubtree(this.statements); - if (error && numMatched > this.mustConsumeBeforeUsingError) return this.getError(this.error); + if (error && numMatched > this.mustConsumeBeforeUsingError) return this.getError(error); let { error:closeError } = this.tokenStream.consume(lex.TokenType.Op, "}"); if (closeError) return this.getError(closeError); - return { ast: { node: ASTNode.Block, statements: statements }, error: null }; + return { ast: { node: ASTNode.Block, statements: statements.statements }, error: null }; } statements() @@ -121,7 +125,7 @@ { return this.getError(error); } - else + else if (StatementsWithSemicolon.includes(stmt.node)) { if (error = this.tokenStream.consume(lex.TokenType.Op, ';').error) {