示例#1
0
func ParseConfiguration(data []byte) (*Configuration, error) {
	opts := &parse.Options{SkipWhite: func(str []byte, loc int) int {
		return parse.SkipAll(str, loc, parse.SkipShellComment, parse.SkipSpaces)
	}}
	cfg := new(Configuration)
	_, err := parse.Parse(cfg, data, opts)
	return cfg, err
}
示例#2
0
func ParseJSON(json []byte) (res map[string]interface{}, err error) {
	var obj Object
	_, err = parse.Parse(&obj, json, &parse.Options{PackratEnabled: false, SkipWhite: parse.SkipSpaces})
	if err != nil {
		return
	}

	return obj.values, nil
}
示例#3
0
// Function to calculate value of expression:
func calc(expr string) float64 {
	var e Expression
	nl, err := parse.Parse(&e, []byte(expr), nil)
	if err != nil {
		println("Error: ", err)
		return 0.0
	} else if nl < len(expr) {
		println("WARNING: '", expr[nl:], "' was not parsed!")
	}

	return e.Calc()
}