summaryrefslogtreecommitdiff
path: root/state.go
diff options
context:
space:
mode:
Diffstat (limited to 'state.go')
-rw-r--r--state.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/state.go b/state.go
index 3c7de43..384eb32 100644
--- a/state.go
+++ b/state.go
@@ -25,6 +25,8 @@ type State struct {
Input string
// An offset into the string, pointing to the current tip
Pos int
+ // Do not backtrack past this point
+ Cut int
// Error is a secondary return channel from parsers, but used so heavily
// in backtracking that it has been inlined to avoid allocations.
Error Error
@@ -88,6 +90,18 @@ func (s *State) Get() string {
return s.Input[s.Pos:]
}
+// Preview of the the next x characters
+func (s *State) Preview(x int) string {
+ if s.Pos > len(s.Input) {
+ return ""
+ }
+ if len(s.Input)-s.Pos >= x {
+ return s.Input[s.Pos : s.Pos+x]
+ }
+
+ return s.Input[s.Pos:]
+}
+
// ErrorHere raises an error at the current position.
func (s *State) ErrorHere(expected string) {
s.Error.pos = s.Pos