Example #1
0
func TestParsexRune(t *testing.T) {
	g := NewGispWith(
		map[string]Toolbox{
			"axiom": Axiom, "props": Propositions, "time": Time},
		map[string]Toolbox{"time": Time, "px": Parsex})
	//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 := NewStringState(data)
	pre, err := px.Between(px.Rune('\''), px.Rune('\''), px.AnyRune)(state)
	if err != nil {
		t.Fatalf("except found rune expr from \"%v\" but error:%v", data, err)
	}
	src := `
	(let ((st (px.state "` + data + `")))
		((px.between (px.rune '\'') (px.rune '\'') px.anyone) st))
	`

	//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)
	}
}
Example #2
0
			return ParsexBox(px.OneOf(params...)), nil
		},
		"noneof": func(env Env, args ...interface{}) (Lisp, error) {
			params, err := Evals(env, args...)
			if err != nil {
				return nil, err
			}
			return ParsexBox(px.NoneOf(params)), nil
		},
		"between": func(env Env, args ...interface{}) (Lisp, error) {
			ptype := reflect.TypeOf((*Parsexer)(nil)).Elem()
			params, err := GetArgs(env, px.UnionAll(TypeAs(ptype), TypeAs(ptype), TypeAs(ptype), px.Eof), args)
			if err != nil {
				return nil, err
			}
			return ParsexBox(px.Between(params[0].(Parsexer).Parser, params[1].(Parsexer).Parser, params[2].(Parsexer).Parser)), nil
		},
		"bind": func(env Env, args ...interface{}) (Lisp, error) {
			if len(args) != 2 {
				return nil, ParsexSignErrorf("Bind Args Error:except 2 args.")
			}
			prs, err := Eval(env, args[0])
			if err != nil {
				return nil, err
			}
			var parser Parsexer
			var ok bool
			if parser, ok = prs.(Parsexer); !ok {
				return nil, ParsexSignErrorf("Bind Args Error:except first arg is a parsexer.")
			}
			f, err := Eval(env, args[1])