func (e ErrorWithSourcePos) GetPosition() SourcePos {
	if e.Pos == nil {
		return SourcePos{Filename: "<input>"}
	}
	return *e.Pos
}
GetPosition implements the ErrorWithPos interface, supplying a location in
proto source that caused the error.
package protoparse
import (
	"errors"
	"fmt"
)
var ErrInvalidSource = errors.New("parse failed: invalid proto source")
var ErrNoSyntax = errors.New("no syntax specified; defaulting to proto2 syntax")
var ErrLookupImportAndProtoSet = errors.New("both LookupImport and LookupImportProto set")
type ErrorReporter func(err ErrorWithPos) error
type WarningReporter func(ErrorWithPos)
func defaultErrorReporter(err ErrorWithPos) error {
	return err
}
type errorHandler struct {
	errReporter  ErrorReporter
	errsReported int
	err          error
	warnReporter WarningReporter
}
func newErrorHandler(errRep ErrorReporter, warnRep WarningReporter) *errorHandler {
	if errRep == nil {
		errRep = defaultErrorReporter
	}
	return &errorHandler{
		errReporter:  errRep,
		warnReporter: warnRep,
	}
}
func (h *errorHandler) handleErrorWithPos(pos *SourcePos, format string, args ...interface{}) error {
	if h.err != nil {
		return h.err
	}
	h.errsReported++
	err := h.errReporter(errorWithPos(pos, format, args...))
	h.err = err
	return err
}
func (h *errorHandler) handleError(err error) error {
	if h.err != nil {
		return h.err
	}
	if ewp, ok := err.(ErrorWithPos); ok {
		h.errsReported++
		err = h.errReporter(ewp)
	}
	h.err = err
	return err
}
func (h *errorHandler) warn(pos *SourcePos, err error) {
	if h.warnReporter != nil {
		h.warnReporter(ErrorWithSourcePos{Pos: pos, Underlying: err})
	}
}
func (h *errorHandler) getError() error {
	if h.errsReported > 0 && h.err == nil {
		return ErrInvalidSource
	}
	return h.err
}
type ErrorWithPos interface {
	error
	GetPosition() SourcePos
	Unwrap() error
}
type ErrorWithSourcePos struct {
	Underlying error
	Pos        *SourcePos
}
func (e ErrorWithSourcePos) Error() string {
	sourcePos := e.GetPosition()
	return fmt.Sprintf("%s: %v", sourcePos, e.Underlying)
}