Пример #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)
	}
}
Пример #2
0
			}
			param, err := Eval(env, args[0])
			if err != nil {
				return nil, err
			}
			return ParsexBox(px.String(param.(string))), nil
		},
		"rune": func(env Env, args ...interface{}) (Lisp, error) {
			if len(args) != 1 {
				return nil, ParsexSignErrorf("Rune Arg Error:except args has 1 arg.")
			}
			param, err := Eval(env, args[0])
			if err != nil {
				return nil, err
			}
			return ParsexBox(px.Rune(rune(param.(Rune)))), nil
		},
		"anyrune":    ParsexBox(px.AnyRune),
		"anyintx":    ParsexBox(px.AnyInt),
		"anyfloatx":  ParsexBox(px.AnyFloat64),
		"anystringx": ParsexBox(px.StringVal),
		"anyint":     ParsexBox(px.AnyInt),
		"anyfloat":   ParsexBox(px.AnyFloat64),
		"aint":       ParsexBox(px.Int),
		"afloat":     ParsexBox(px.Float),
		"astring":    ParsexBox(px.StringVal),
		"string": func(env Env, args ...interface{}) (Lisp, error) {
			if len(args) != 1 {
				return nil, ParsexSignErrorf("string Arg Error:except args has 1 arg.")
			}
			param, err := Eval(env, args[0])