From 55633c704ec6836b8d1a5f6a554e2811fe53b697 Mon Sep 17 00:00:00 2001 From: yaacov Date: Wed, 5 Dec 2018 00:20:32 +0200 Subject: [PATCH] add parse error --- pkg/tsl/error_listener.go | 5 +---- pkg/tsl/errors.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/tsl/error_listener.go b/pkg/tsl/error_listener.go index 29f42d1..1c4af57 100644 --- a/pkg/tsl/error_listener.go +++ b/pkg/tsl/error_listener.go @@ -16,9 +16,6 @@ package tsl import ( - "fmt" - "strconv" - "github.com/antlr/antlr4/runtime/Go/antlr" ) @@ -41,5 +38,5 @@ func (d *ErrorListener) SyntaxError( msg string, e antlr.RecognitionException) { - d.Err = fmt.Errorf("line " + strconv.Itoa(line) + ":" + strconv.Itoa(column) + " " + msg) + d.Err = ParseError{line: line, column: column, msg: msg} } diff --git a/pkg/tsl/errors.go b/pkg/tsl/errors.go index 8f6a160..733cafb 100644 --- a/pkg/tsl/errors.go +++ b/pkg/tsl/errors.go @@ -44,3 +44,14 @@ type StackError struct{} func (e StackError) Error() string { return fmt.Sprintf("unexpected operator stack") } + +// ParseError is raised on parser error. +type ParseError struct { + line int + column int + msg string +} + +func (e ParseError) Error() string { + return fmt.Sprintf("parse error [%d:%d]: %s", e.line, e.column, e.msg) +}