Permalink
Browse files

ParseExpr also returns ErrVimlParser

  • Loading branch information...
1 parent cc6667c commit ec01290bf90ab8f717e3c742dd34007b0e839180 @haya14busa committed Sep 17, 2016
Showing with 15 additions and 1 deletion.
  1. +10 −1 vimlparser.go
  2. +5 −0 vimlparser_test.go
View
@@ -66,7 +66,16 @@ func ParseExpr(r io.Reader) (node ast.Expr, err error) {
defer func() {
if r := recover(); r != nil {
node = nil
- err = fmt.Errorf("%v", r)
+ if e, ok := r.(*internal.ParseError); ok {
+ err = &ErrVimlParser{
+ Offset: e.Offset,
+ Line: e.Line,
+ Column: e.Column,
+ Msg: e.Msg,
+ }
+ } else {
+ err = fmt.Errorf("%v", r)
+ }
// log.Printf("%s", debug.Stack())
}
}()
View
@@ -76,6 +76,11 @@ func TestParseExpr_Parser_err(t *testing.T) {
want := "vimlparser: unexpected token: /: line 1 col 4"
_, err := ParseExpr(strings.NewReader("1 // 2"))
if err != nil {
+
+ if er, ok := err.(*ErrVimlParser); !ok {
+ t.Errorf("Error type is %T, want %T", er, &ErrVimlParser{})
+ }
+
if got := err.Error(); want != got {
t.Errorf("ParseExpr(\"1 // 2\") = %v, want %v", got, want)
}

0 comments on commit ec01290

Please sign in to comment.