Skip to content

Commit c99a8e0

Browse files
authored
Merge pull request #993 from wader/gojq-update
gojq: Update fq fork
2 parents 56beac2 + 824e51e commit c99a8e0

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)