Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

package core

import (
"strings"
)

// Use unexported type alias so we control the interface and prevent people doing arbirary things e.g. use negative ints.
type checkpoint int

Expand All @@ -22,6 +26,7 @@ type Input interface {
Take(n int) (string, bool)
Checkpoint() checkpoint
Restore(cp checkpoint)
Debug() string
}

type input struct {
Expand Down Expand Up @@ -66,3 +71,12 @@ func (i *input) Checkpoint() checkpoint {
func (i *input) Restore(cp checkpoint) {
i.index = int(cp)
}

// Outputs the full input string with a marker at the current parsing position
func (i *input) Debug() string {
var s strings.Builder
s.WriteString(i.s[:i.index])
s.WriteString("☝️")
s.WriteString(i.s[i.index:])
return s.String()
}
Loading