Golang go/scanner.Error type examples

package go/scanner

In an ErrorList, an error is represented by an *Error. The position Pos, if valid, points to the beginning of the offending token, and the error condition is described by Msg.

Golang go/scanner.Error type usage examples

Example 1:

 func scanType(src []byte) (err *scanner.Error) {
 var s scanner.Scanner
 fset := token.NewFileSet()
 errMsg := ""
 pos, tok, lit := s.Scan()
 ...
 return &scanner.Error{
 fset.Position(pos),
 fmt.Sprintf("%s\n + %s, got %q\n", src, errMsg, lit),
 }

Example 2:

 switch x := x.(type) {
 case *scanner.Error:
 switch y := y.(type) {
 case *scanner.Error:
 return scanner.ErrorList{x, y}
  case scanner.ErrorList:
 return append(y, x)
  default:
 return scanner.ErrorList{x, scannerError(y)}
 }

Reference :

http://golang.org/pkg/go/scanner/#Error

Advertisement