fix if/then errors
This commit is contained in:
parent
8a8801f1c0
commit
29044dc74c
@ -157,7 +157,18 @@ func (p *Parser) parseIfStatement() *IfStatement {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
p.nextToken() // move past condition
|
// Optional 'then' keyword
|
||||||
|
if p.peekTokenIs(THEN) {
|
||||||
|
p.nextToken()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.nextToken() // move past condition (and optional 'then')
|
||||||
|
|
||||||
|
// Check if we immediately hit END (missing body)
|
||||||
|
if p.curTokenIs(END) {
|
||||||
|
p.addError("expected 'end' to close if statement")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Parse if body
|
// Parse if body
|
||||||
stmt.Body = p.parseBlockStatements(ELSEIF, ELSE, END)
|
stmt.Body = p.parseBlockStatements(ELSEIF, ELSE, END)
|
||||||
@ -174,7 +185,12 @@ func (p *Parser) parseIfStatement() *IfStatement {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
p.nextToken() // move past condition
|
// Optional 'then' keyword
|
||||||
|
if p.peekTokenIs(THEN) {
|
||||||
|
p.nextToken()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.nextToken() // move past condition (and optional 'then')
|
||||||
|
|
||||||
elseif.Body = p.parseBlockStatements(ELSEIF, ELSE, END)
|
elseif.Body = p.parseBlockStatements(ELSEIF, ELSE, END)
|
||||||
stmt.ElseIfs = append(stmt.ElseIfs, elseif)
|
stmt.ElseIfs = append(stmt.ElseIfs, elseif)
|
||||||
@ -563,6 +579,8 @@ func tokenTypeString(t TokenType) string {
|
|||||||
return "var"
|
return "var"
|
||||||
case IF:
|
case IF:
|
||||||
return "if"
|
return "if"
|
||||||
|
case THEN:
|
||||||
|
return "then"
|
||||||
case ELSEIF:
|
case ELSEIF:
|
||||||
return "elseif"
|
return "elseif"
|
||||||
case ELSE:
|
case ELSE:
|
||||||
|
@ -29,6 +29,7 @@ const (
|
|||||||
// Keywords
|
// Keywords
|
||||||
VAR
|
VAR
|
||||||
IF
|
IF
|
||||||
|
THEN
|
||||||
ELSEIF
|
ELSEIF
|
||||||
ELSE
|
ELSE
|
||||||
END
|
END
|
||||||
@ -74,6 +75,7 @@ func lookupIdent(ident string) TokenType {
|
|||||||
"false": FALSE,
|
"false": FALSE,
|
||||||
"nil": NIL,
|
"nil": NIL,
|
||||||
"if": IF,
|
"if": IF,
|
||||||
|
"then": THEN,
|
||||||
"elseif": ELSEIF,
|
"elseif": ELSEIF,
|
||||||
"else": ELSE,
|
"else": ELSE,
|
||||||
"end": END,
|
"end": END,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user