Skip to content

Commit

Permalink
handle broken InfixExpressions and print out line numbers for those
Browse files Browse the repository at this point in the history
cases
  • Loading branch information
markbates committed Dec 22, 2017
1 parent c2c634d commit f4d3d2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ast/infix_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func (oe *InfixExpression) String() string {
out.WriteString(oe.Left.String())
}
out.WriteString(" " + oe.Operator + " ")
out.WriteString(oe.Right.String())
if oe.Right != nil {
out.WriteString(oe.Right.String())
} else {
out.WriteString(" !!MISSING '%>'!!")
}
out.WriteString(")")

return out.String()
Expand Down
4 changes: 2 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ func (p *parser) expectPeek(t token.Type) bool {
}

func (p *parser) peekError(t token.Type) {
msg := fmt.Sprintf("expected next token to be %s, got %s instead [line: %d]", t, p.peekToken.Type, p.curToken.LineNumber)
msg := fmt.Sprintf("line %d: expected next token to be %s, got %s instead", p.curToken.LineNumber, t, p.peekToken.Type)
p.errors = append(p.errors, msg)
}

func (p *parser) noPrefixParseFnError(t token.Type) {
msg := fmt.Sprintf("no prefix parse function for %s found [line: %d]", t, p.curToken.LineNumber)
msg := fmt.Sprintf("line %d: no prefix parse function for %s found", p.curToken.LineNumber, t)
p.errors = append(p.errors, msg)
}

Expand Down

0 comments on commit f4d3d2e

Please sign in to comment.