Skip to content

Commit 824e51e

Browse files
committed
gojq: Update fq fork
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
1 parent 56beac2 commit 824e51e

File tree

9 files changed

+24
-15
lines changed

9 files changed

+24
-15
lines changed

format/json/jq.jq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def from_jq:
8181
( $v.term.object.key_vals // []
8282
| map(
8383
{ key: (.key // .key_string.str)
84-
, value: (.val.queries[0] | _f)
84+
, value: (.val | _f)
8585
}
8686
)
8787
| from_entries

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/wader/fq
33
go 1.21
44

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

88
require (
99
// bump: gomod-BurntSushi/toml /github\.com\/BurntSushi\/toml v(.*)/ https://github.com/BurntSushi/toml.git|^1
@@ -76,7 +76,7 @@ require (
7676
)
7777

7878
require (
79-
github.com/itchyny/timefmt-go v0.1.5 // indirect
79+
github.com/itchyny/timefmt-go v0.1.6 // indirect
8080
github.com/mitchellh/reflectwalk v1.0.2 // indirect
8181
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
8282
golang.org/x/sys v0.23.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ github.com/gomarkdown/markdown v0.0.0-20240328165702-4d01890c35c0 h1:4gjrh/PN2Mu
1010
github.com/gomarkdown/markdown v0.0.0-20240328165702-4d01890c35c0/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
1111
github.com/gopacket/gopacket v1.2.0 h1:eXbzFad7f73P1n2EJHQlsKuvIMJjVXK5tXoSca78I3A=
1212
github.com/gopacket/gopacket v1.2.0/go.mod h1:BrAKEy5EOGQ76LSqh7DMAr7z0NNPdczWm2GxCG7+I8M=
13-
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
14-
github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8=
13+
github.com/itchyny/timefmt-go v0.1.6 h1:ia3s54iciXDdzWzwaVKXZPbiXzxxnv1SPGFfM/myJ5Q=
14+
github.com/itchyny/timefmt-go v0.1.6/go.mod h1:RRDZYC5s9ErkjQvTvvU7keJjxUYzIISJGxm9/mAERQg=
1515
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1616
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
1717
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
@@ -23,8 +23,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
2323
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
2424
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
2525
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
26-
github.com/wader/gojq v0.12.1-0.20240401131232-6c6bc364201a h1:P881Oecjt9FEXrwkGJ6UObJksxejJaF/fKq1ZfXpiVE=
27-
github.com/wader/gojq v0.12.1-0.20240401131232-6c6bc364201a/go.mod h1:qVrzkUdnBtJvM4twyRQ6xdziPSnSp35dLm4s/DN2iP4=
26+
github.com/wader/gojq v0.12.1-0.20240816124407-8e100b8bc5aa h1:rUMbYfXFY6JYJamXjS5HIAgBucoNeKFRR5rTqsqAyjw=
27+
github.com/wader/gojq v0.12.1-0.20240816124407-8e100b8bc5aa/go.mod h1:EPKZhJLM6ILU40HkgFbhrsV7MHf5flxQDS5fSf/KNpE=
2828
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
2929
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
3030
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=

pkg/interp/.jq-lsp.jq

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ def markdown: empty;
3333
def _markdown_to_text($width; $header_depth): empty;
3434
# used by funcs.jq iprint
3535
def to_radix($base): empty;
36+
def tobytes: empty;
37+
def eval($s): empty;
38+
def trim: empty;

pkg/interp/eval.jq

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ def _eval_query_rewrite($opts):
4141
| if $opts.catch_query then
4242
# _query_query to get correct precedence and a valid query
4343
# try (1+1) catch vs try 1 + 1 catch
44-
_query_try(. | _query_query; $opts.catch_query)
44+
_query_try(
45+
( .
46+
# TODO: error instead or assuming ident?
47+
| if (.term or .op) | not then . + _query_ident end
48+
| _query_query
49+
);
50+
$opts.catch_query
51+
)
4552
end
4653
| if $opts.input_query then
4754
_query_pipe($opts.input_query; .)

pkg/interp/init.jq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,4 @@ def _main:
277277
)
278278
)
279279
end
280-
);
280+
);

pkg/interp/interp.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import (
5151
//go:embed init.jq
5252
var builtinFS embed.FS
5353

54-
var initSource = `include "@builtin/init";`
54+
var initSource = `include "@builtin/init"; .`
5555

5656
func init() {
5757
RegisterIter1("_readline", (*Interp)._readline)
@@ -882,9 +882,8 @@ func (i *Interp) Eval(ctx context.Context, c any, expr string, opts EvalOpts) (g
882882
pos: p,
883883
}
884884
}
885-
886-
// not identity body means it returns something, threat as dynamic include
887-
if q.Term == nil || q.Term.Type != gojq.TermTypeIdentity {
885+
// has some root expression, threat as dynamic include
886+
if q.Term != nil || q.Op != gojq.Operator(0) {
888887
gc, err := gojq.Compile(q, funcCompilerOpts...)
889888
if err != nil {
890889
return nil, err

pkg/interp/query.jq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _query_object:
8383
( to_entries
8484
| map(
8585
{ key: .key
86-
, val: {queries: [.value]}
86+
, val: .value
8787
}
8888
)
8989
)

pkg/interp/query.jq.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.[] | _query_fromstring | _query_pipe_last | _query_tostring
22
["", ".", "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"]
3-
"."
3+
""
44
"."
55
"a"
66
"1, 2"

0 commit comments

Comments
 (0)