Example #1
0
func compare(st px.ParsexState) (interface{}, error) {
	l, err := px.Bind(px.Choice(
		px.Bind(IntValue, LessThanNumber),
		px.Bind(NumberValue, LessThanFloat),
		px.Bind(px.StringVal, LessThanString),
		px.Bind(TimeValue, LessThanTime),
	), func(l interface{}) px.Parser {
		return func(st px.ParsexState) (interface{}, error) {
			_, err := px.Eof(st)
			if err != nil {
				return nil, ParsexSignErrorf("less args sign error: except eof")
			}
			return l, nil
		}
	})(st)
	if err == nil {
		return l, nil
	}
	return nil, ParsexSignErrorf("Except two lessable values compare but error %v", err)
}
Example #2
0
// return false, true or nil
func lessOption(env Env) px.Parser {
	return func(st px.ParsexState) (interface{}, error) {
		l, err := px.Bind(px.Choice(
			px.Try(px.Bind(IntValue, LessThanNumber)),
			px.Try(px.Bind(NumberValue, LessThanFloat)),
			px.Try(px.Bind(px.StringVal, LessThanString)),
			px.Try(px.Bind(TimeValue, LessThanTime)),
			px.Try(px.Bind(ListValue, LessThanListOption(env))),
			px.Bind(px.AnyOne, LessThanNil),
		), func(l interface{}) px.Parser {
			return func(st px.ParsexState) (interface{}, error) {
				_, err := px.Eof(st)
				if err != nil {
					return nil, ParsexSignErrorf("less args sign error: except eof")
				}
				return l, nil
			}
		})(st)
		if err == nil {
			return l, nil
		}
		return nil, ParsexSignErrorf("Except two lessable values or nil compare but error: %v", err)
	}
}