ginger/gg/grammar/grammar.go

28 lines
620 B
Go
Raw Normal View History

// Package grammar is used for parsing a stream of runes according to a set of
// grammatical rules. This package only supports context-free grammars.
package grammar
import "fmt"
// Stringer is a convenience tool for working with fmt.Stringer. Exactly one of
// the fields must be set, and will be used to implement the fmt.Stringer
// interface.
type Stringer struct {
I fmt.Stringer
F func() string
S string
}
func (s Stringer) String() string {
switch {
case s.I != nil:
return s.I.String()
case s.F != nil:
return s.F()
case s.S != "":
return s.S
default:
panic("no fields set on Stringer")
}
}