Documentation ¶
Index ¶
- func AsFloat32(state State) (interface{}, error)
- func AsFloat64(state State) (interface{}, error)
- func AsInt(state State) (interface{}, error)
- func AsRune(state State) (interface{}, error)
- func AsString(state State) (interface{}, error)
- func Crlf(state State) (interface{}, error)
- func Digit(state State) (interface{}, error)
- func EOF(state State) (interface{}, error)
- func EndOfLine(state State) (interface{}, error)
- func Env(fn func() interface{}) (re interface{}, err error)
- func Float(state State) (interface{}, error)
- func Int(state State) (interface{}, error)
- func Letter(state State) (interface{}, error)
- func Newline(state State) (interface{}, error)
- func Nil(state State) (interface{}, error)
- func Number(state State) (interface{}, error)
- func One(state State) (interface{}, error)
- func Space(state State) (interface{}, error)
- func ToInterfaces(input string) []interface{}
- func ToString(input interface{}) string
- func UFloat(state State) (interface{}, error)
- func UInt(state State) (interface{}, error)
- func Whitespace(state State) (interface{}, error)
- type BasicState
- func (state *BasicState) Begin() int
- func (state *BasicState) Commit(tran int)
- func (state *BasicState) Next() (interface{}, error)
- func (state *BasicState) Pos() int
- func (state *BasicState) Rollback(tran int)
- func (state *BasicState) SeekTo(pos int) bool
- func (state *BasicState) Trap(message string, args ...interface{}) error
- type Error
- type P
- func AtLeast(x int, psc P) P
- func AtMost(x int, psc P) P
- func Between(open, close, psc P) P
- func Byte(val byte) P
- func ByteNone(str string) P
- func ByteOf(str string) P
- func ByteP(name string, pred func(r byte) bool) P
- func Bytes(str string) P
- func Choice(Ps ...P) P
- func Chr(val rune) P
- func Do(fn func(State) interface{}) P
- func Eq(val interface{}) P
- func Fail(message string, args ...interface{}) P
- func FailIf(psc P) P
- func InRange(x, y int, psc P) P
- func Many(psc P) P
- func Many1(psc P) P
- func ManyTill(p, e P) P
- func Maybe(p P) P
- func NByte(val byte) P
- func NChr(val rune) P
- func Ne(val interface{}) P
- func NoneOf(args ...interface{}) P
- func OneOf(args ...interface{}) P
- func Option(v interface{}, x P) P
- func Repeat(x, y int, psc P) P
- func Return(val interface{}) P
- func ReturnString(input interface{}) P
- func RuneNone(str string) P
- func RuneOf(str string) P
- func RuneP(name string, pred func(r rune) bool) P
- func SepBy(p, sep P) P
- func SepBy1(p, sep P) P
- func Skip(p P) P
- func Skip1(p P) P
- func Str(str string) P
- func Times(x int, psc P) P
- func Try(psc P) P
- func Union(parsers ...P) P
- func UnionAll(parsers ...P) P
- func UpTo(x int, psc P) P
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Env ¶
func Env(fn func() interface{}) (re interface{}, err error)
Env 函数与 P 算子的 Exec 方法对应,将其抛出的 error 还原为无 panic 的流程,用于模拟 Haskell Monad Do 。需要注意的是,捕获的非 error 类型的panic会重新抛出。
func ToInterfaces ¶
func ToInterfaces(input string) []interface{}
ToInterfaces 将string 转为 []interface{} ,如果输入数据与前面提到的规范不符,会 panic
Types ¶
type BasicState ¶
type BasicState struct {
// contains filtered or unexported fields
}
BasicState 实现最基本的 State 操作
func BasicStateFromText ¶
func BasicStateFromText(str string) BasicState
BasicStateFromText 构造一个新的 BasicState
func NewBasicState ¶
func NewBasicState(data []interface{}) BasicState
NewBasicState 构造一个新的 BasicState
func (*BasicState) Begin ¶
func (state *BasicState) Begin() int
Begin 开始一个事务并返回事务号,State 的 Begin 总是记录比较靠后的位置。
func (*BasicState) Commit ¶
func (state *BasicState) Commit(tran int)
Commit 提交一个事务,将其从注册状态中删除,将事务位置保存为比较靠前的位置
func (*BasicState) Rollback ¶
func (state *BasicState) Rollback(tran int)
Rollback 取消一个事务,将 pos 移动到 该位置,将事务位置保存为比较靠前的位置
func (*BasicState) Trap ¶
func (state *BasicState) Trap(message string, args ...interface{}) error
Trap 是构造错误信息的辅助函数,它传递错误的位置,并提供字符串格式化功能
type P ¶
P 是算子的公共抽象类型,实现 Monad 和解析逻辑
func Do ¶
Do 构造一个算子,其内部类似 Monad Do Environment ,将 Exec 形式恢复成 Parse 形式。 需要注意的是,捕获的非 error 类型的panic会重新抛出。
func ReturnString ¶
func ReturnString(input interface{}) P
ReturnString 用 Return 包装 ToString,使其适用于组合子表达式。
Source Files ¶
Click to show internal directories.
Click to hide internal directories.