Beispiel #1
0
// compileJq compiles a program into the jq interpreter
func compileJq(jq *C.jq_state, src string) error {
	var msg *C.char
	C.set_err_cb(jq, &msg)
	defer C.set_err_cb(jq, nil)
	csrc := C.CString(src)
	defer C.free(unsafe.Pointer(csrc))
	// TODO: use a SyntaxError type to split up Error from Expr
	if C.jq_compile(jq, csrc) == 0 {
		return errors.New(C.GoString(msg))
	}
	return nil
}
Beispiel #2
0
Datei: jq.go Projekt: vantroy/jq
// NewJq returns an initialized state with a compiled program
// program should be a valid jq program/filter
// see http://stedolan.github.io/jq/manual/#Basicfilters for more info
func newJqExecutor(program string) (*jqExecutor, error) {
	jq := &jqExecutor{
		state: C.jq_init(),
	}

	if jq.state == nil {
		return nil, errJqStateNil
	}

	pgm := C.CString(program)
	defer C.free(unsafe.Pointer(pgm))

	// Compiles a program into jq_state.
	if ok := C.jq_compile(jq.state, pgm); ok != 1 {
		jq.free()
		return nil, errInvalidProgram
	}

	return jq, nil
}
Beispiel #3
0
func (jq *JQ) compile(program string) error {
	_ = C.jq_compile(jq.state, C.CString(program))
	return nil
}