Skip to content

Commit e44bb47

Browse files
committed
change to semicolon handling
1 parent a1a282d commit e44bb47

4 files changed

Lines changed: 4 additions & 12 deletions

File tree

examples/factorial.pun

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ i32 factorial(i32 n) {
88
return result
99
}
1010

11-
println("Factorial of 5 is {}", factorial(5));
11+
println("Factorial of 5 is {}", factorial(5))

parser/function.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func (p *Parser) parseFunctionCall(function ast.Expression) (ast.Expression, err
129129
exp.Arguments, err = p.parseFunctionCallArguments()
130130

131131
p.trace("parsed function call after args", p.curToken.Literal, p.peekToken.Literal)
132+
132133
return exp, err
133134
}
134135

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

143144
if p.curTokenIs(token.RPAREN) {
144-
p.nextToken() // consume the closing parenthesis
145145
return args, nil
146146
}
147147

148+
p.trace("parseFunctionCallArguments before parse expression", p.curToken.Literal, p.peekToken.Literal)
148149
firstArg, err := p.parseExpression(LOWEST)
149150
if err != nil {
150151
return nil, err

parser/parser.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ func (p *Parser) parseExpression(precedence int) (ast.Expression, error) {
235235
return nil, err
236236
}
237237
p.trace("parsed identifier functioncall expression", p.curToken.Literal, p.peekToken.Literal)
238-
if p.curTokenIs(token.RPAREN) {
239-
p.nextToken()
240-
}
241238
return fnCall, nil
242239
}
243240

parser/parsers.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (p *Parser) parseVariableDeclarationOrAssignment() (ast.Statement, error) {
177177
return nil, p.error("expected '=' after identifier")
178178
}
179179

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

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

515-
if !p.curTokenIs(token.SEMICOLON) {
516-
return nil, p.error("expected ';' after for-init statement")
517-
}
518-
// Consume the ';'
519-
p.nextToken()
520-
521515
p.trace("current token", p.curToken.Literal)
522516
if !p.curTokenIs(token.SEMICOLON) {
523517
stmt.Condition, err = p.parseExpression(LOWEST)

0 commit comments

Comments
 (0)