You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ginger/gg/grammar/grammar.go

27 lines
620 B

// 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")
}
}