Skip to content

Commit

Permalink
Index / hash assignments gotchas, closes #315
Browse files Browse the repository at this point in the history
They were not properly handling the case where the final
character is a `;`, when they should "consume" it and move
forward. Instead, the parser would parse the assignment and
move onto the next block, which was a single `;`, causing it
to fail.

A better fix for this could be allowing `;` as valid blocks
that are simply ignore, which would also solve expressions
such as `x = 1;;;`, which are now erroring out.
  • Loading branch information
odino committed Feb 11, 2020
1 parent 0616905 commit a04f5c2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions parser/parser.go
Expand Up @@ -300,6 +300,11 @@ func (p *Parser) parseAssignStatement() ast.Statement {
stmt.Value = p.parseExpression(LOWEST)
// consume the IndexExpression
p.prevIndexExpression = nil

if p.peekTokenIs(token.SEMICOLON) {
p.nextToken()
}

return stmt
}
if p.prevPropertyExpression != nil {
Expand All @@ -309,6 +314,11 @@ func (p *Parser) parseAssignStatement() ast.Statement {
stmt.Value = p.parseExpression(LOWEST)
// consume the PropertyExpression
p.prevPropertyExpression = nil

if p.peekTokenIs(token.SEMICOLON) {
p.nextToken()
}

return stmt
}
}
Expand All @@ -326,6 +336,7 @@ func (p *Parser) parseAssignStatement() ast.Statement {
if p.peekTokenIs(token.SEMICOLON) {
p.nextToken()
}

return stmt
}

Expand Down

0 comments on commit a04f5c2

Please sign in to comment.