gojq

package module
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 21 Imported by: 472

README

gojq CI Status

Pure Go implementation of jq.

Usage

 $ echo '{"foo": 128}' | gojq '.foo'
128
 $ echo '{"a": {"b": 42}}' | gojq '.a.b'
42
 $ echo '{"id": "sample", "10": {"b": 42}}' | gojq '{(.id): .["10"].b}'
{
  "sample": 42
}
 $ echo '[{"id":1},{"id":2},{"id":3}]' | gojq '.[] | .id'
1
2
3
 $ echo '{"a":1,"b":2}' | gojq '.a += 1 | .b *= 2'
{
  "a": 2,
  "b": 4
}
 $ echo '{"a":1} [2] 3' | gojq '. as {$a} ?// [$a] ?// $a | $a'
1
2
3
 $ echo '{"foo": 4722366482869645213696}' | gojq .foo
4722366482869645213696  # keeps the precision of number while jq does not
 $ gojq -n 'def fact($n): if $n < 1 then 1 else $n * fact($n - 1) end; fact(50)'
30414093201713378043612608166064768844377641568960512000000000000 # arbitrary-precision integer calculation

Nice error messages.

 $ echo '[1,2,3]' | gojq  '.foo & .bar'
gojq: invalid query: .foo & .bar
    .foo & .bar
         ^  unexpected token "&"
 $ echo '{"foo": { bar: [] } }' | gojq '.'
gojq: invalid json: <stdin>
    {"foo": { bar: [] } }
              ^  invalid character 'b' looking for beginning of object key string

Installation

Homebrew
brew install itchyny/tap/gojq
Build from source
go get -u github.com/itchyny/gojq/cmd/gojq

Difference to jq

  • gojq is purely implemented with Go language and is completely portable. jq depends on the C standard library so the availability of math functions depends on the library. jq also depends on the regular expression library and it makes build scripts complex.
  • gojq implements nice error messages for invalid query and JSON input. The error message of jq is sometimes difficult to tell where to fix the query.
  • gojq does not keep the order of object keys. I understand this might cause problems for some scripts but basically we should not rely on the order of object keys. I would implement when ordered map is implemented in the standard library of Go but I'm less motivated.
  • gojq supports arbitrary-precision integer calculation while jq does not. This is important to keeping the precision of numeric IDs or nanosecond values. You can use gojq to solve some mathematical problems which require big integers.
  • gojq supports reading from YAML input while jq does not. gojq also supports YAML output.

Usage as a library

You can use the gojq parser and interpreter from your Go products.

package main

import (
	"fmt"
	"log"

	"github.com/itchyny/gojq"
)

func main() {
	query, err := gojq.Parse(".foo | ..")
	if err != nil {
		log.Fatalln(err)
	}
	input := map[string]interface{}{"foo": []interface{}{1, 2, 3}}
	iter := query.Run(input) // or query.RunWithContext
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			log.Fatalln(err)
		}
		fmt.Printf("%#v\n", v)
	}
}
  • Firstly, use gojq.Parse(string) (*Query, error) to get the query from a string.
  • Secondly, get the result iterator
    • using query.Run or query.RunWithContext
    • or alternatively, compile the query using gojq.Compile and then code.Run or code.RunWithContext. You can reuse the *Code against multiple inputs to avoid compiling the same query.
    • In either case, the query input should have type []interface{} for an array and map[string]interface{} for a map (just like decoded to an interface{} using the encoding/json package). You can't use []int or map[string]string, for example.
  • Thirdly, iterate through the results using iter.Next() (interface{}, bool). The iterater can emit an error so make sure to handle it. Termination is notified by the second returned value of Next().

gojq.Compile allows to configure the following compiler options.

  • gojq.WithModuleLoader allows to load modules. By default, the module feature is disabled.
  • gojq.WithEnvironLoader allows to configure the environment variables referenced by env and $ENV. By default, OS environment variables are not accessible due to security reason. You can use gojq.WithEnvironLoader(os.Environ) if you want.
  • gojq.WithVariables allows to configure the variables which can be used in the query. Pass the values of the variables to code.Run in the same order.
  • gojq.WithInputIter allows to use input and inputs functions. By default, these functions are disabled.

Bug Tracker

Report bug at Issues・itchyny/gojq - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

Documentation

Overview

Package gojq provides the parser and interpreter of gojq.

Please refer to https://github.com/itchyny/gojq#usage-as-a-library for introduction of the usage as a library.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alt added in v0.2.0

type Alt struct {
	Left  *Expr      `@@`
	Right []AltRight `@@*`
}

Alt ...

func (*Alt) String added in v0.4.0

func (e *Alt) String() string

type AltRight added in v0.4.0

type AltRight struct {
	Op    Operator `@"//"`
	Right *Expr    `@@`
}

AltRight ...

func (AltRight) String added in v0.4.0

func (e AltRight) String() string

type AndExpr added in v0.1.0

type AndExpr struct {
	Left  *Compare       `@@`
	Right []AndExprRight `@@*`
}

AndExpr ...

func (*AndExpr) String added in v0.4.0

func (e *AndExpr) String() string

type AndExprRight added in v0.4.0

type AndExprRight struct {
	Op    Operator `@"and"`
	Right *Compare `@@`
}

AndExprRight ...

func (AndExprRight) String added in v0.4.0

func (e AndExprRight) String() string

type Arith added in v0.1.0

type Arith struct {
	Left  *Factor      `@@`
	Right []ArithRight `@@*`
}

Arith ...

func (*Arith) String added in v0.4.0

func (e *Arith) String() string

type ArithRight added in v0.4.0

type ArithRight struct {
	Op    Operator `@("+" | "-")`
	Right *Factor  `@@`
}

ArithRight ...

func (ArithRight) String added in v0.4.0

func (e ArithRight) String() string

type Array

type Array struct {
	Query *Query `"[" @@? "]"`
}

Array ...

func (*Array) String added in v0.4.0

func (e *Array) String() string

type Bind added in v0.5.0

type Bind struct {
	Patterns []*Pattern `"as" @@ ("?//" @@)*`
	Body     *Query     `"|" @@`
}

Bind ...

func (*Bind) String added in v0.5.0

func (e *Bind) String() string

type Code added in v0.8.0

type Code struct {
	// contains filtered or unexported fields
}

Code is a compiled jq query.

func Compile added in v0.8.0

func Compile(q *Query, options ...CompilerOption) (*Code, error)

Compile compiles a query.

Example
package main

import (
	"fmt"
	"log"

	"github.com/itchyny/gojq"
)

func main() {
	query, err := gojq.Parse(".foo")
	if err != nil {
		log.Fatalln(err)
	}
	code, err := gojq.Compile(query)
	if err != nil {
		log.Fatalln(err)
	}
	inputs := []interface{}{
		nil,
		"string",
		42,
		[]interface{}{"foo"},
		map[string]interface{}{"foo": 42},
	}
	for _, input := range inputs {
		iter := code.Run(input)
		for {
			v, ok := iter.Next()
			if !ok {
				break
			}
			if err, ok := v.(error); ok {
				fmt.Printf("%s\n", err)
				break
			}
			fmt.Printf("%#v\n", v)
		}
	}

}
Output:

<nil>
expected an object but got: string ("string")
expected an object but got: number (42)
expected an object but got: array (["foo"])
42

func (*Code) Run added in v0.8.0

func (c *Code) Run(v interface{}, values ...interface{}) Iter

Run runs the code with the variable values (which should be in the same order as the given variables using WithVariables) and returns a result iterator.

Example
package main

import (
	"fmt"
	"log"

	"github.com/itchyny/gojq"
)

func main() {
	query, err := gojq.Parse(".foo")
	if err != nil {
		log.Fatalln(err)
	}
	code, err := gojq.Compile(query)
	if err != nil {
		log.Fatalln(err)
	}
	input := map[string]interface{}{"foo": 42}
	iter := code.Run(input)
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			log.Fatalln(err)
		}
		fmt.Printf("%#v\n", v)
	}

}
Output:

42

func (*Code) RunWithContext added in v0.8.0

func (c *Code) RunWithContext(ctx context.Context, v interface{}, values ...interface{}) Iter

RunWithContext runs the code with context.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/itchyny/gojq"
)

func main() {
	query, err := gojq.Parse("def f: f; f")
	if err != nil {
		log.Fatalln(err)
	}
	code, err := gojq.Compile(query)
	if err != nil {
		log.Fatalln(err)
	}
	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
	defer cancel()
	iter := code.RunWithContext(ctx, nil)
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			fmt.Printf("%s\n", err)
			return
		}
		_ = v
	}

}
Output:

context deadline exceeded

type Comma

type Comma struct {
	Filters []*Filter `@@ ("," @@)*`
}

Comma ...

func (*Comma) String added in v0.4.0

func (e *Comma) String() string

type Compare added in v0.1.0

type Compare struct {
	Left  *Arith        `@@`
	Right *CompareRight `@@?`
}

Compare ...

func (*Compare) String added in v0.4.0

func (e *Compare) String() string

type CompareRight added in v0.4.0

type CompareRight struct {
	Op    Operator `@CompareOp`
	Right *Arith   `@@`
}

CompareRight ...

func (*CompareRight) String added in v0.4.0

func (e *CompareRight) String() string

type CompilerOption added in v0.8.0

type CompilerOption func(*compiler)

CompilerOption ...

func WithEnvironLoader added in v0.9.0

func WithEnvironLoader(environLoader func() []string) CompilerOption

WithEnvironLoader is a compiler option for environment variables loader. The OS environment variables are not accessible by default due to security reason. You can pass os.Environ if you allow to access it.

Example
package main

import (
	"fmt"
	"log"

	"github.com/itchyny/gojq"
)

func main() {
	query, err := gojq.Parse("env | keys[]")
	if err != nil {
		log.Fatalln(err)
	}
	code, err := gojq.Compile(
		query,
		gojq.WithEnvironLoader(func() []string {
			return []string{"foo=42", "bar=128"}
		}),
	)
	if err != nil {
		log.Fatalln(err)
	}
	iter := code.Run(nil)
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			log.Fatalln(err)
		}
		fmt.Printf("%#v\n", v)
	}

}
Output:

"bar"
"foo"

func WithInputIter added in v0.10.0

func WithInputIter(inputIter Iter) CompilerOption

WithInputIter is a compiler option for input iterator used by input(s)/0. Note that input and inputs functions are not allowed by default. We have to distinguish the query input and the values for input(s) functions. For example, consider using inputs with --null-input. If you want to allow input(s) functions, create an Iter and use WithInputIter option.

Example
package main

import (
	"encoding/json"
	"fmt"
	"io"
	"log"
	"strings"

	"github.com/itchyny/gojq"
)

type testInputIter struct {
	dec *json.Decoder
}

func newTestInputIter(r io.Reader) *testInputIter {
	dec := json.NewDecoder(r)
	dec.UseNumber()
	return &testInputIter{dec: dec}
}

func (i *testInputIter) Next() (interface{}, bool) {
	var v interface{}
	if err := i.dec.Decode(&v); err != nil {
		if err == io.EOF {
			return nil, false
		}
		return err, true
	}
	return v, true
}

func main() {
	query, err := gojq.Parse("reduce inputs as $x (0; . + $x)")
	if err != nil {
		log.Fatalln(err)
	}
	code, err := gojq.Compile(
		query,
		gojq.WithInputIter(
			newTestInputIter(strings.NewReader("1 2 3 4 5")),
		),
	)
	if err != nil {
		log.Fatalln(err)
	}
	iter := code.Run(nil)
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			log.Fatalln(err)
		}
		fmt.Printf("%#v\n", v)
	}

}
Output:

15

func WithModuleLoader added in v0.8.0

func WithModuleLoader(moduleLoader ModuleLoader) CompilerOption

WithModuleLoader is a compiler option for module loader.

Example
package main

import (
	"fmt"
	"log"

	"github.com/itchyny/gojq"
)

type moduleLoader struct{}

func (*moduleLoader) LoadModule(name string) (*gojq.Module, error) {
	switch name {
	case "module1":
		return gojq.ParseModule(`
			module { name: "module1", test: 42 };
			import "module2" as foo;
			def f: foo::f;
		`)
	case "module2":
		return gojq.ParseModule(`
			def f: .foo;
		`)
	}
	return nil, fmt.Errorf("module not found: %q", name)
}

func main() {
	query, err := gojq.Parse(`
		import "module1" as m;
		m::f
	`)
	if err != nil {
		log.Fatalln(err)
	}
	code, err := gojq.Compile(
		query,
		gojq.WithModuleLoader(&moduleLoader{}),
	)
	if err != nil {
		log.Fatalln(err)
	}
	input := map[string]interface{}{"foo": 42}
	iter := code.Run(input)
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			log.Fatalln(err)
		}
		fmt.Printf("%#v\n", v)
	}

}
Output:

42

func WithVariables added in v0.8.0

func WithVariables(variables []string) CompilerOption

WithVariables is a compiler option for variable names. The variables can be used in the query. You have to give the values to query.Run or code.Run in the same order.

Example
package main

import (
	"fmt"
	"log"

	"github.com/itchyny/gojq"
)

func main() {
	query, err := gojq.Parse("$x * 100 + $y, $z")
	if err != nil {
		log.Fatalln(err)
	}
	code, err := gojq.Compile(
		query,
		gojq.WithVariables([]string{
			"$x", "$y", "$z",
		}),
	)
	if err != nil {
		log.Fatalln(err)
	}
	iter := code.Run(nil, 12, 42, 128)
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			log.Fatalln(err)
		}
		fmt.Printf("%#v\n", v)
	}

}
Output:

1242
128

type ConstArray added in v0.8.0

type ConstArray struct {
	Elems []*ConstTerm `"[" (@@ ("," @@)*)? "]"`
}

ConstArray ...

func (*ConstArray) String added in v0.8.0

func (e *ConstArray) String() string

type ConstObject added in v0.8.0

type ConstObject struct {
	KeyVals []ConstObjectKeyVal `"{" (@@ ("," @@)*)? "}"`
}

ConstObject ...

func (*ConstObject) String added in v0.8.0

func (e *ConstObject) String() string

func (*ConstObject) ToValue added in v0.10.0

func (e *ConstObject) ToValue() map[string]interface{}

ToValue converts the object to map[string]interface{}.

type ConstObjectKeyVal added in v0.8.0

type ConstObjectKeyVal struct {
	Key       string     `( @Ident | @Keyword`
	KeyString string     `| @String ) ":"`
	Val       *ConstTerm `@@`
}

ConstObjectKeyVal ...

func (*ConstObjectKeyVal) String added in v0.8.0

func (e *ConstObjectKeyVal) String() string

type ConstTerm added in v0.8.0

type ConstTerm struct {
	Object *ConstObject `  @@`
	Array  *ConstArray  `| @@`
	Number string       `| @Number`
	Str    string       `| @String`
	Null   bool         `| @"null"`
	True   bool         `| @"true"`
	False  bool         `| @"false"`
}

ConstTerm ...

func (*ConstTerm) String added in v0.8.0

func (e *ConstTerm) String() string

type Expr added in v0.1.0

type Expr struct {
	Logic    *Logic   `@@`
	UpdateOp Operator `( ( @UpdateOp | @UpdateAltOp )`
	Update   *Alt     `  @@`
	Bind     *Bind    `| @@ )?`
	Label    *Label   `| @@`
}

Expr ...

func (*Expr) String added in v0.4.0

func (e *Expr) String() string

type Factor added in v0.1.0

type Factor struct {
	Left  *Term         `@@`
	Right []FactorRight `@@*`
}

Factor ...

func (*Factor) String added in v0.4.0

func (e *Factor) String() string

type FactorRight added in v0.4.0

type FactorRight struct {
	Op    Operator `@("*" | "/" | "%")`
	Right *Term    `@@`
}

FactorRight ...

func (FactorRight) String added in v0.4.0

func (e FactorRight) String() string

type Filter added in v0.5.0

type Filter struct {
	FuncDefs []*FuncDef `@@*`
	Alt      *Alt       `@@`
}

Filter ...

func (*Filter) String added in v0.5.0

func (e *Filter) String() string

type Foreach added in v0.3.0

type Foreach struct {
	Term    *Term    `"foreach" @@`
	Pattern *Pattern `"as" @@`
	Start   *Query   `"(" @@`
	Update  *Query   `";" @@`
	Extract *Query   `(";" @@)? ")"`
}

Foreach ...

func (*Foreach) String added in v0.4.0

func (e *Foreach) String() string

type Func added in v0.1.0

type Func struct {
	Name string   `( @Ident | @Variable | @ModuleIdent )`
	Args []*Query `( "(" @@ (";" @@)* ")" )?`
}

Func ...

func (*Func) String added in v0.4.0

func (e *Func) String() string

type FuncDef added in v0.1.0

type FuncDef struct {
	Name string   `"def" @Ident`
	Args []string `("(" ( @Ident | @Variable ) (";" ( @Ident | @Variable ))* ")")? ":"`
	Body *Query   `@@ ";"`
}

FuncDef ...

func (*FuncDef) String added in v0.4.0

func (e *FuncDef) String() string

type If added in v0.1.0

type If struct {
	Cond *Query   `"if" @@`
	Then *Query   `"then" @@`
	Elif []IfElif `@@*`
	Else *Query   `("else" @@)? "end"`
}

If ...

func (*If) String added in v0.4.0

func (e *If) String() string

type IfElif added in v0.4.0

type IfElif struct {
	Cond *Query `"elif" @@`
	Then *Query `"then" @@`
}

IfElif ...

func (*IfElif) String added in v0.4.0

func (e *IfElif) String() string

type Import added in v0.8.0

type Import struct {
	ImportPath  string       `( "import" @String`
	ImportAlias string       `  "as" ( @Ident | @Variable )`
	IncludePath string       `| "include" @String )`
	Meta        *ConstObject `@@? ";"`
}

Import ...

func (*Import) String added in v0.8.0

func (e *Import) String() string

type Index added in v0.2.0

type Index struct {
	Name    string `@Index`
	Str     string `| "." ( @String`
	Start   *Query `| "[" ( @@`
	IsSlice bool   `( @":"`
	End     *Query `@@? )? | ":" @@ ) "]" )`
}

Index ...

func (*Index) String added in v0.3.0

func (e *Index) String() string

type Iter added in v0.4.0

type Iter interface {
	Next() (interface{}, bool)
}

Iter is an interface for an iterator.

type Label added in v0.3.0

type Label struct {
	Ident string `"label" @Variable`
	Body  *Query `"|" @@`
}

Label ...

func (*Label) String added in v0.4.0

func (e *Label) String() string

type Logic added in v0.1.0

type Logic struct {
	Left  *AndExpr     `@@`
	Right []LogicRight `@@*`
}

Logic ...

func (*Logic) String added in v0.4.0

func (e *Logic) String() string

type LogicRight added in v0.4.0

type LogicRight struct {
	Op    Operator `@"or"`
	Right *AndExpr `@@`
}

LogicRight ...

func (LogicRight) String added in v0.4.0

func (e LogicRight) String() string

type Module added in v0.8.0

type Module struct {
	Meta     *ConstObject `( "module" @@ ";" )?`
	Imports  []*Import    `@@*`
	FuncDefs []*FuncDef   `@@*`
}

Module ...

func ParseModule added in v0.8.0

func ParseModule(src string) (*Module, error)

ParseModule parses a module.

func (*Module) String added in v0.8.0

func (e *Module) String() string

type ModuleLoader added in v0.8.0

type ModuleLoader interface {
	LoadModule(string) (*Module, error)
}

ModuleLoader is an interface for loading modules.

type Object

type Object struct {
	KeyVals []ObjectKeyVal `"{" (@@ ("," @@)*)? "}"`
}

Object ...

func (*Object) String added in v0.4.0

func (e *Object) String() string

type ObjectKeyVal added in v0.4.0

type ObjectKeyVal struct {
	Key           string     `( ( ( @Ident | @Variable | @Keyword )`
	KeyString     string     `  | @String )`
	Query         *Query     `| "(" @@ ")" ) ":"`
	Val           *ObjectVal `@@`
	KeyOnly       *string    `| @Ident | @Variable`
	KeyOnlyString string     `| @String`
}

ObjectKeyVal ...

func (*ObjectKeyVal) String added in v0.4.0

func (e *ObjectKeyVal) String() string

type ObjectVal added in v0.7.0

type ObjectVal struct {
	Alts []*Alt `@@ ("|" @@)*`
}

ObjectVal ...

func (*ObjectVal) String added in v0.7.0

func (e *ObjectVal) String() string

type Operator added in v0.1.0

type Operator int

Operator ...

const (
	OpAdd Operator = iota
	OpSub
	OpMul
	OpDiv
	OpMod
	OpEq
	OpNe
	OpGt
	OpLt
	OpGe
	OpLe
	OpAnd
	OpOr
	OpAlt
	OpAssign
	OpModify
	OpUpdateAdd
	OpUpdateSub
	OpUpdateMul
	OpUpdateDiv
	OpUpdateMod
	OpUpdateAlt
)

Operators ...

func (*Operator) Capture added in v0.1.0

func (op *Operator) Capture(s []string) error

Capture implements participle.Capture.

func (Operator) GoString added in v0.4.0

func (op Operator) GoString() string

GoString implements GoStringer.

func (Operator) String added in v0.1.0

func (op Operator) String() string

String implements Stringer.

type Pattern added in v0.3.0

type Pattern struct {
	Name   string          `  @Variable`
	Array  []*Pattern      `| "[" @@ ("," @@)* "]"`
	Object []PatternObject `| "{" @@ ("," @@)* "}"`
}

Pattern ...

func (*Pattern) String added in v0.4.0

func (e *Pattern) String() string

type PatternObject added in v0.4.0

type PatternObject struct {
	Key       string   `( ( @Ident | @Variable | @Keyword )`
	KeyString string   `  | @String`
	Query     *Query   `  | "(" @@ ")" ) ":"`
	Val       *Pattern `@@`
	KeyOnly   string   `| @Variable`
}

PatternObject ...

func (*PatternObject) String added in v0.4.0

func (e *PatternObject) String() string

type Query

type Query struct {
	Imports []*Import `@@*`
	Commas  []*Comma  `@@ ("|" @@)*`
}

Query ...

func Parse added in v0.1.0

func Parse(src string) (*Query, error)

Parse parses a query.

func (*Query) Run added in v0.1.0

func (e *Query) Run(v interface{}) Iter

Run query.

Example
package main

import (
	"fmt"
	"log"

	"github.com/itchyny/gojq"
)

func main() {
	query, err := gojq.Parse(".foo | ..")
	if err != nil {
		log.Fatalln(err)
	}
	input := map[string]interface{}{"foo": []interface{}{1, 2, 3}}
	iter := query.Run(input)
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			log.Fatalln(err)
		}
		fmt.Printf("%#v\n", v)
	}

}
Output:

[]interface {}{1, 2, 3}
1
2
3

func (*Query) RunWithContext added in v0.8.0

func (e *Query) RunWithContext(ctx context.Context, v interface{}) Iter

RunWithContext query.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/itchyny/gojq"
)

func main() {
	query, err := gojq.Parse("def f: f; f")
	if err != nil {
		log.Fatalln(err)
	}
	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
	defer cancel()
	iter := query.RunWithContext(ctx, nil)
	for {
		v, ok := iter.Next()
		if !ok {
			break
		}
		if err, ok := v.(error); ok {
			fmt.Printf("%s\n", err)
			return
		}
		_ = v
	}

}
Output:

context deadline exceeded

func (*Query) String added in v0.4.0

func (e *Query) String() string

type Reduce added in v0.3.0

type Reduce struct {
	Term    *Term    `"reduce" @@`
	Pattern *Pattern `"as" @@`
	Start   *Query   `"(" @@`
	Update  *Query   `";" @@ ")"`
}

Reduce ...

func (*Reduce) String added in v0.4.0

func (e *Reduce) String() string

type Suffix

type Suffix struct {
	Index       *Index       `  @@`
	SuffixIndex *SuffixIndex `| @@`
	Iter        bool         `| @("[" "]")`
	Optional    bool         `| @"?"`
}

Suffix ...

func (*Suffix) String added in v0.4.0

func (e *Suffix) String() string

type SuffixIndex added in v0.2.0

type SuffixIndex struct {
	Start   *Query `"[" ( @@`
	IsSlice bool   `( @":"`
	End     *Query `@@? )? | ":" @@ ) "]"`
}

SuffixIndex ...

func (*SuffixIndex) String added in v0.4.0

func (e *SuffixIndex) String() string

type Term

type Term struct {
	Index      *Index    `( @@`
	Identity   bool      `| @"."`
	Recurse    bool      `| @".."`
	Null       bool      `| @"null"`
	True       bool      `| @"true"`
	False      bool      `| @"false"`
	Func       *Func     `| @@`
	Object     *Object   `| @@`
	Array      *Array    `| @@`
	Number     string    `| @Number`
	Unary      *Unary    `| @@`
	Format     string    `| ( @Format`
	FormatStr  string    `    @String? )`
	Str        string    `| @String`
	RawStr     string    `| @" "` // never matches, used in compiler
	If         *If       `| @@`
	Try        *Try      `| @@`
	Reduce     *Reduce   `| @@`
	Foreach    *Foreach  `| @@`
	Break      string    `| "break" @Variable`
	Query      *Query    `| "(" @@ ")" )`
	SuffixList []*Suffix `@@*`
}

Term ...

func (*Term) String added in v0.1.0

func (e *Term) String() string

type Try added in v0.2.0

type Try struct {
	Body  *Query `"try" @@`
	Catch *Term  `("catch" @@)?`
}

Try ...

func (*Try) String added in v0.4.0

func (e *Try) String() string

type Unary added in v0.4.0

type Unary struct {
	Op   Operator `@("+" | "-")`
	Term *Term    `@@`
}

Unary ...

func (*Unary) String added in v0.4.0

func (e *Unary) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL