Skip to content

Commit

Permalink
gojq: Update fq fork
Browse files Browse the repository at this point in the history
Rebase fq changes on latester gojq main.

Most notable change visiable to users is that gojq now allows queries
as object literal values. For example this now works: {a: 1+2+3}

From upstream:
083fb39 refactor code using built-in min and max functions
470db58 bump up to Go 1.23, drop support for Go 1.20
0607aa5 bump up version to 0.12.16
0709341 update CHANGELOG.md for v0.12.16
1324e6e update dependencies
01355e9 improve parser to allow binary operators as object values
a41a5f8 fix debug/1 function to be available only when debug/0 is defined
f694c1b fix a benchmark test BenchmarkCompile
f2559f6 remove private compare function
0cd3a66 improve compiler to abort with error if query is missing
422cc9d refactor stringify function declarations of query
1130c4e refactor program body, rename rules, remove empty actions in parser
8d7ccc9 add tests for immutability of arrays
375e90d remove useless receivers
1b5ce7f set correct offset for multibyte tokens
8874f53 fix tests of exp10 and atan2 failing on some platforms
  • Loading branch information
wader committed Aug 19, 2024
1 parent 56beac2 commit 824e51e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion format/json/jq.jq
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def from_jq:
( $v.term.object.key_vals // []
| map(
{ key: (.key // .key_string.str)
, value: (.val.queries[0] | _f)
, value: (.val | _f)
}
)
| from_entries
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/wader/fq
go 1.21

// fork of github.com/itchyny/gojq, see github.com/wader/gojq fq branch
require github.com/wader/gojq v0.12.1-0.20240401131232-6c6bc364201a
require github.com/wader/gojq v0.12.1-0.20240816124407-8e100b8bc5aa

require (
// bump: gomod-BurntSushi/toml /github\.com\/BurntSushi\/toml v(.*)/ https://github.com/BurntSushi/toml.git|^1
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
)

require (
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
golang.org/x/sys v0.23.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/gomarkdown/markdown v0.0.0-20240328165702-4d01890c35c0 h1:4gjrh/PN2Mu
github.com/gomarkdown/markdown v0.0.0-20240328165702-4d01890c35c0/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/gopacket/gopacket v1.2.0 h1:eXbzFad7f73P1n2EJHQlsKuvIMJjVXK5tXoSca78I3A=
github.com/gopacket/gopacket v1.2.0/go.mod h1:BrAKEy5EOGQ76LSqh7DMAr7z0NNPdczWm2GxCG7+I8M=
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8=
github.com/itchyny/timefmt-go v0.1.6 h1:ia3s54iciXDdzWzwaVKXZPbiXzxxnv1SPGFfM/myJ5Q=
github.com/itchyny/timefmt-go v0.1.6/go.mod h1:RRDZYC5s9ErkjQvTvvU7keJjxUYzIISJGxm9/mAERQg=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand All @@ -23,8 +23,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/wader/gojq v0.12.1-0.20240401131232-6c6bc364201a h1:P881Oecjt9FEXrwkGJ6UObJksxejJaF/fKq1ZfXpiVE=
github.com/wader/gojq v0.12.1-0.20240401131232-6c6bc364201a/go.mod h1:qVrzkUdnBtJvM4twyRQ6xdziPSnSp35dLm4s/DN2iP4=
github.com/wader/gojq v0.12.1-0.20240816124407-8e100b8bc5aa h1:rUMbYfXFY6JYJamXjS5HIAgBucoNeKFRR5rTqsqAyjw=
github.com/wader/gojq v0.12.1-0.20240816124407-8e100b8bc5aa/go.mod h1:EPKZhJLM6ILU40HkgFbhrsV7MHf5flxQDS5fSf/KNpE=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=
Expand Down
3 changes: 3 additions & 0 deletions pkg/interp/.jq-lsp.jq
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ def markdown: empty;
def _markdown_to_text($width; $header_depth): empty;
# used by funcs.jq iprint
def to_radix($base): empty;
def tobytes: empty;
def eval($s): empty;
def trim: empty;
9 changes: 8 additions & 1 deletion pkg/interp/eval.jq
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ def _eval_query_rewrite($opts):
| if $opts.catch_query then
# _query_query to get correct precedence and a valid query
# try (1+1) catch vs try 1 + 1 catch
_query_try(. | _query_query; $opts.catch_query)
_query_try(
( .
# TODO: error instead or assuming ident?
| if (.term or .op) | not then . + _query_ident end
| _query_query
);
$opts.catch_query
)
end
| if $opts.input_query then
_query_pipe($opts.input_query; .)
Expand Down
2 changes: 1 addition & 1 deletion pkg/interp/init.jq
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,4 @@ def _main:
)
)
end
);
);
7 changes: 3 additions & 4 deletions pkg/interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
//go:embed init.jq
var builtinFS embed.FS

var initSource = `include "@builtin/init";`
var initSource = `include "@builtin/init"; .`

func init() {
RegisterIter1("_readline", (*Interp)._readline)
Expand Down Expand Up @@ -882,9 +882,8 @@ func (i *Interp) Eval(ctx context.Context, c any, expr string, opts EvalOpts) (g
pos: p,
}
}

// not identity body means it returns something, threat as dynamic include
if q.Term == nil || q.Term.Type != gojq.TermTypeIdentity {
// has some root expression, threat as dynamic include
if q.Term != nil || q.Op != gojq.Operator(0) {
gc, err := gojq.Compile(q, funcCompilerOpts...)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/interp/query.jq
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _query_object:
( to_entries
| map(
{ key: .key
, val: {queries: [.value]}
, val: .value
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/interp/query.jq.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.[] | _query_fromstring | _query_pipe_last | _query_tostring
["", ".", "a", "1, 2", "1 | 2", "1 | 2 | 3", "(1 | 2) | 3", "1 | (2 | 3)", "1 as $_ | 2", "def f: 1; 1", "def f: 1; 1 | 2"]
"."
""
"."
"a"
"1, 2"
Expand Down

0 comments on commit 824e51e

Please sign in to comment.