Skip to content

Commit

Permalink
change to semicolon handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dfirebaugh committed Jan 6, 2025
1 parent a1a282d commit e44bb47
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/factorial.pun
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ i32 factorial(i32 n) {
return result
}

println("Factorial of 5 is {}", factorial(5));
println("Factorial of 5 is {}", factorial(5))
3 changes: 2 additions & 1 deletion parser/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (p *Parser) parseFunctionCall(function ast.Expression) (ast.Expression, err
exp.Arguments, err = p.parseFunctionCallArguments()

p.trace("parsed function call after args", p.curToken.Literal, p.peekToken.Literal)

return exp, err
}

Expand All @@ -141,10 +142,10 @@ func (p *Parser) parseFunctionCallArguments() ([]ast.Expression, error) {
}

if p.curTokenIs(token.RPAREN) {
p.nextToken() // consume the closing parenthesis
return args, nil
}

p.trace("parseFunctionCallArguments before parse expression", p.curToken.Literal, p.peekToken.Literal)
firstArg, err := p.parseExpression(LOWEST)
if err != nil {
return nil, err
Expand Down
3 changes: 0 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ func (p *Parser) parseExpression(precedence int) (ast.Expression, error) {
return nil, err
}
p.trace("parsed identifier functioncall expression", p.curToken.Literal, p.peekToken.Literal)
if p.curTokenIs(token.RPAREN) {
p.nextToken()
}
return fnCall, nil
}

Expand Down
8 changes: 1 addition & 7 deletions parser/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (p *Parser) parseVariableDeclarationOrAssignment() (ast.Statement, error) {
return nil, p.error("expected '=' after identifier")
}

p.nextToken()
p.nextToken() // consume assign operator
value, err := p.parseExpression(LOWEST)
if err != nil {
return nil, err
Expand Down Expand Up @@ -512,12 +512,6 @@ func (p *Parser) parseForStatement() (*ast.ForStatement, error) {

p.trace("current token", p.curToken.Literal)

if !p.curTokenIs(token.SEMICOLON) {
return nil, p.error("expected ';' after for-init statement")
}
// Consume the ';'
p.nextToken()

p.trace("current token", p.curToken.Literal)
if !p.curTokenIs(token.SEMICOLON) {
stmt.Condition, err = p.parseExpression(LOWEST)
Expand Down

0 comments on commit e44bb47

Please sign in to comment.