go-parse 是一个 Go 语言的库实现类 Parsec 的解析。
示例代码:
func main() { in := new(StringVessel); in.SetInput(`< (>)( < )( >) < > > >`); ltgt := Any(Symbol("<"), Symbol(">")); parser := Many(Any(ltgt, Parens(ltgt))); out, parsed := parser(in); fmt.Printf("Matched: %#v\n", parsed); fmt.Printf("Matches: %v\n", out); fmt.Printf("Vessel: %+v\n", in); }
输出:
go-parse $ go parsec Matched: true Matches: [< > < > < > > >] Vessel: &{state:<nil> input:< (>)( < )( >) < > > > position:{Name: Line:0 Column:0 Offset:29}}