Skip to content
Permalink
Browse files

Closes #154. Parses casts.

  • Loading branch information...
AZHenley committed Oct 2, 2019
1 parent 5e881a1 commit 3657ae8b096a947918e818a01e6d429fd083e695
Showing with 21 additions and 2 deletions.
  1. +21 −2 parser/parser.go
@@ -568,20 +568,39 @@ func (p *Parser) logical() ast.Node {
}

func (p *Parser) equality() ast.Node {
var node = p.comparison()
var node = p.cast()
for p.curTokenIs(token.EQ) || p.curTokenIs(token.NOTEQ) {
var binaryNode ast.Node
binaryNode.Type = ast.BINARYOP
binaryNode.TokenStart = p.curToken

p.nextToken()
binaryNode.Children = append(binaryNode.Children, node)
binaryNode.Children = append(binaryNode.Children, p.comparison())
binaryNode.Children = append(binaryNode.Children, p.cast())
node = binaryNode
}
return node
}

func (p *Parser) cast() ast.Node {
var node = p.comparison()
for p.curTokenIs(token.AS) {
var castNode ast.Node
castNode.Type = ast.CAST
castNode.TokenStart = p.curToken

p.nextToken()
var identNode ast.Node
identNode.Type = ast.IDENT
identNode.TokenStart = p.curToken
p.consume(token.IDENT)

castNode.Children = append(castNode.Children, node)
castNode.Children = append(castNode.Children, identNode)
}
return node
}

func (p *Parser) comparison() ast.Node {
var node = p.addition()
for p.curTokenIs(token.GT) || p.curTokenIs(token.GTEQ) || p.curTokenIs(token.LT) || p.curTokenIs(token.LTEQ) {

0 comments on commit 3657ae8

Please sign in to comment.
You can’t perform that action at this time.