本文整理匯總了Golang中github.com/Dwarfartisan/goparsec.MemoryParseState函數的典型用法代碼示例。如果您正苦於以下問題:Golang MemoryParseState函數的具體用法?Golang MemoryParseState怎麽用?Golang MemoryParseState使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MemoryParseState函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestParsecBasic
func TestParsecBasic(t *testing.T) {
g := NewGispWith(
map[string]Toolbox{
"axiom": Axiom, "props": Propositions, "time": Time},
map[string]Toolbox{"time": Time, "p": Parsec})
digit := p.Bind(p.Many1(p.Digit), p.ReturnString)
data := "344932454094325"
state := p.MemoryParseState(data)
pre, err := digit(state)
if err != nil {
t.Fatalf("except \"%v\" pass test many1 digit but error:%v", data, err)
}
src := "(let ((st (p.state \"" + data + `")))
(var data ((p.many1 p.digit) st))
(p.s2str data))
`
gre, err := g.Parse(src)
if err != nil {
t.Fatalf("except \"%v\" pass gisp many1 digit but error:%v", src, err)
}
t.Logf("from gisp: %v", gre)
t.Logf("from parsec: %v", pre)
if !reflect.DeepEqual(pre, gre) {
t.Fatalf("except got \"%v\" from gisp equal \"%v\" from parsec", gre, pre)
}
}
示例2: TestParsecRune2
func TestParsecRune2(t *testing.T) {
g := NewGispWith(
map[string]Toolbox{
"axiom": Axiom, "props": Propositions, "time": Time},
map[string]Toolbox{"time": Time, "p": Parsec})
//data := "Here is a Rune : 'a' and a is't a rune. It is a word in sentence."
data := "'a' and a is't a rune. It is a word in sentence."
state := p.MemoryParseState(data)
pre, err := p.Between(p.Rune('\''), p.Rune('\''), p.AnyRune)(state)
if err != nil {
t.Fatalf("except found rune expr from \"%v\" but error:%v", data, err)
}
src := `
(let ((st (p.state "` + data + `")))
((p.rune '\'') st)
(var data (p.anyone st))
((p.rune '\'') st)
data)
`
//fmt.Println(src)
gre, err := g.Parse(src)
if err != nil {
t.Fatalf("except \"%v\" pass gisp '<rune>' but error:%v", src, err)
}
t.Logf("from gisp: %v", gre)
t.Logf("from parsec: %v", pre)
if !reflect.DeepEqual(pre, gre) {
t.Fatalf("except got \"%v\" from gisp equal \"%v\" from parsec", gre, pre)
}
}
示例3: TestIntParser3
func TestIntParser3(t *testing.T) {
data := "3.14"
st := p.MemoryParseState(data)
o, err := p.Bind_(IntParser, p.Eof)(st)
if err == nil {
t.Fatalf("except a Float parse error but got %v", o)
}
}
示例4: TestFloatParser5
func TestFloatParser5(t *testing.T) {
data := "234"
st := p.MemoryParseState(data)
o, err := FloatParser(st)
if err == nil {
t.Fatalf("except a Float parse error but got %v", o)
}
}
示例5: TestIntParser1
func TestIntParser1(t *testing.T) {
data := "i234"
st := p.MemoryParseState(data)
o, err := IntParser(st)
if err == nil {
t.Fatalf("except a Int parse error but got %v", o)
}
}
示例6: TestDotParser
func TestDotParser(t *testing.T) {
data := "now.Year"
st := p.MemoryParseState(data)
re, err := p.Bind(AtomParser, DotSuffixParser)(st)
if err != nil {
t.Fatalf("except a Dot but error %v", err)
}
t.Log(re)
}
示例7: atomNameParser
func atomNameParser(st p.ParseState) (interface{}, error) {
ret, err := p.Bind(p.Many1(p.NoneOf("'[]() \t\r\n\".:")),
p.ReturnString)(st)
if err != nil {
return nil, err
}
test := p.MemoryParseState(ret.(string))
_, err = p.Bind_(p.Many1(p.Digit), p.Eof)(test)
if err == nil {
return nil, fmt.Errorf("atom name can't be a int like %s", ret.(string))
}
return ret, nil
}
示例8: TestAtomParse0
func TestAtomParse0(t *testing.T) {
data := "x"
state := p.MemoryParseState(data)
a, err := AtomParser(state)
if err == nil {
test := Atom{"x", Type{ANY, false}}
if !reflect.DeepEqual(test, a) {
t.Fatalf("except Atom{\"x\", ANY} but %v", a)
}
} else {
t.Fatalf("except Atom{\"x\", ANY} but %v", err)
}
}
示例9: TestingBoolParse0
func TestingBoolParse0(t *testing.T) {
data := "true"
st := p.MemoryParseState(data)
o, err := BoolParser(st)
if err != nil {
t.Fatalf("except bool but error %v", err)
}
if b, ok := o.(Bool); ok {
if !b {
t.Fatalf("except bool true but %v", b)
}
} else {
t.Fatalf("excpet bool but %v", o)
}
}
示例10: TestFloatParser0
func TestFloatParser0(t *testing.T) {
data := "0.012"
st := p.MemoryParseState(data)
o, err := FloatParser(st)
if err != nil {
t.Fatalf("except a Float but error %v", err)
}
if f, ok := o.(Float); ok {
if f != Float(0.012) {
t.Fatalf("except a Float 0.012 but %v", f)
}
} else {
t.Fatalf("except Float but %v", o)
}
}
示例11: TestFloatParser1
func TestFloatParser1(t *testing.T) {
data := "3.1415926"
st := p.MemoryParseState(data)
o, err := FloatParser(st)
if err != nil {
t.Fatalf("except a Float but error %v", err)
}
if f, ok := o.(Float); ok {
if f != Float(3.1415926) {
t.Fatalf("except a Float 3.1415926 but %v", f)
}
} else {
t.Fatalf("except Float but %v", o)
}
}
示例12: TestIntParser0
func TestIntParser0(t *testing.T) {
data := "12"
st := p.MemoryParseState(data)
o, err := IntParser(st)
if err != nil {
t.Fatalf("except a Int but error %v", err)
}
if i, ok := o.(Int); ok {
if i != Int(12) {
t.Fatalf("except a Int 12 but %v", i)
}
} else {
t.Fatalf("except Int but %v", o)
}
}
示例13: Parse
// Parse 解釋執行一段文本
func (gisp *Gisp) Parse(code string) (interface{}, error) {
st := p.MemoryParseState(code)
var v interface{}
var e error
for {
Skip(st)
_, err := p.Eof(st)
if err == nil {
break
}
value, err := ValueParserExt(gisp)(st)
if err != nil {
return nil, err
}
switch lisp := value.(type) {
case Lisp:
v, e = lisp.Eval(gisp)
default:
v = lisp
e = nil
}
}
return v, e
}
示例14:
Meta: map[string]interface{}{
"name": "parsex",
"category": "package",
},
Content: map[string]interface{}{
"state": func(env Env, args ...interface{}) (Lisp, error) {
if len(args) != 1 {
return nil, ParsexSignErrorf("Parsex Arg Error:except args has 1 arg.")
}
param, err := Eval(env, args[0])
if err != nil {
return nil, err
}
switch data := param.(type) {
case string:
return Q(p.MemoryParseState(data)), nil
default:
return nil, fmt.Errorf("Parsex Error: Except create a state from a string or List but %v", data)
}
},
"s2str": func(env Env, args ...interface{}) (Lisp, error) {
if len(args) != 1 {
return nil, ParsexSignErrorf("Slice to string Arg Error:except args has 1 arg.")
}
param, err := Eval(env, args[0])
if err != nil {
return nil, err
}
var (
slice []interface{}
ok bool