Skip to content

Commit

Permalink
add parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Dec 4, 2018
1 parent 247ba3d commit 55633c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions pkg/tsl/error_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
package tsl

import (
"fmt"
"strconv"

"github.com/antlr/antlr4/runtime/Go/antlr"
)

Expand All @@ -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}
}
11 changes: 11 additions & 0 deletions pkg/tsl/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 55633c7

Please sign in to comment.