From 0dc37ae5bc10cc0669f88ab9febbc039a28f23d1 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Sun, 13 Aug 2017 16:56:12 +1000 Subject: Remove a few allocs from Run --- errors.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 errors.go (limited to 'errors.go') diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..3f8787c --- /dev/null +++ b/errors.go @@ -0,0 +1,26 @@ +package goparsify + +import "fmt" + +// Error represents a parse error. These will often be set, the parser will back up a little and +// find another viable path. In general when combining errors the longest error should be returned. +type Error struct { + pos int + expected string +} + +// Pos is the offset into the document the error was found +func (e *Error) Pos() int { return e.pos } + +// Error satisfies the golang error interface +func (e *Error) Error() string { return fmt.Sprintf("offset %d: expected %s", e.pos, e.expected) } + +// UnparsedInputError is returned by Run when not all of the input was consumed. There may still be a valid result +type UnparsedInputError struct { + remaining string +} + +// Error satisfies the golang error interface +func (e UnparsedInputError) Error() string { + return "left unparsed: " + e.remaining +} -- cgit v1.2.3