Started better error output by adding line and column number. Need to

get rid of panic.
This commit is contained in:
Marvin Blum
2015-10-31 16:49:33 +01:00
parent 6c55846e9f
commit 67e950b41d
2 changed files with 17 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package parser
import (
"strconv"
"tokenizer"
)
@@ -37,7 +38,7 @@ func (c *Compiler) accept(token string) bool {
// Throws if current token does not match expected one.
func (c *Compiler) expect(token string) {
if !c.tokenEqual(token, c.get()) {
panic("Parse error, expected '" + token + "' but was '" + c.get().Token + "'")
panic("Parse error, expected '" + token + "' but was '" + c.get().Token + "' in line "+strconv.Itoa(c.get().Line)+" at "+strconv.Itoa(c.get().Column))
}
c.next()