summaryrefslogtreecommitdiff
path: root/state.go
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-10 21:04:14 +1000
committerAdam Scarr <adam@vektah.net>2017-08-10 21:08:18 +1000
commitaf542eff9e1e51561a9efa37685ee07b1d01b53e (patch)
treec700bdca58b4f9bbeb89ba1b102b2a779c88f7f3 /state.go
parentb64fcfaa6115eb4a5f65c12d37f95d842136ae35 (diff)
Add parse logging
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