Parsed grouped expressions (that was easy!).
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
c417e90f36
commit
4acc09faf9
2 changed files with 31 additions and 0 deletions
|
|
@ -37,6 +37,7 @@ func New(l *lexer.Lexer) *Parser {
|
|||
p.registerPrefix(token.BANG, p.parsePrefixExpression)
|
||||
p.registerPrefix(token.TRUE, p.parseBoolean)
|
||||
p.registerPrefix(token.FALSE, p.parseBoolean)
|
||||
p.registerPrefix(token.LPAREN, p.parseGroupedExpression)
|
||||
// Infix registrations
|
||||
p.registerInfix(token.PLUS, p.parseInfixExpression)
|
||||
p.registerInfix(token.MINUS, p.parseInfixExpression)
|
||||
|
|
@ -176,6 +177,16 @@ func (p *Parser) parseInfixExpression(left ast.Expression) ast.Expression {
|
|||
return exp
|
||||
}
|
||||
|
||||
func (p *Parser) parseGroupedExpression() ast.Expression {
|
||||
p.nextToken()
|
||||
exp := p.parseExpression(LOWEST)
|
||||
if !p.expectPeek(token.RPAREN) {
|
||||
// TODO: Would probably be good to emit an error here?
|
||||
return nil
|
||||
}
|
||||
return exp
|
||||
}
|
||||
|
||||
func (p *Parser) curTokenIs(typ token.TokenType) bool {
|
||||
return p.curToken.Type == typ
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue