mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
Bind libraries backward for consistent shadowing
This commit is contained in:
committed by
Nico Williams
parent
141bb78e96
commit
abed751e96
@@ -176,6 +176,7 @@ EXTRA_DIST = $(DOC_FILES) $(man_MANS) $(TESTS) $(TEST_LOG_COMPILER) \
|
||||
tests/modules/c/d.jq tests/modules/data.json \
|
||||
tests/modules/home1/.jq tests/modules/home2/.jq/g.jq \
|
||||
tests/modules/lib/jq/e/e.jq tests/modules/lib/jq/f.jq \
|
||||
tests/modules/shadow1.jq tests/modules/shadow2.jq \
|
||||
tests/modules/syntaxerror/syntaxerror.jq \
|
||||
tests/modules/test_bind_order.jq \
|
||||
tests/modules/test_bind_order0.jq \
|
||||
|
||||
+1
-1
@@ -400,7 +400,7 @@ block block_bind_library(block binder, block body, int bindflags, const char *li
|
||||
matchlen += 2;
|
||||
}
|
||||
assert(block_has_only_binders(binder, bindflags));
|
||||
for (inst *curr = binder.first; curr; curr = curr->next) {
|
||||
for (inst *curr = binder.last; curr; curr = curr->prev) {
|
||||
int bindflags2 = bindflags;
|
||||
char* cname = curr->symbol;
|
||||
char* tname = jv_mem_alloc(strlen(curr->symbol)+matchlen+1);
|
||||
|
||||
+5
-1
@@ -240,7 +240,11 @@ static int process_dependencies(jq_state *jq, jv jq_origin, jv lib_origin, block
|
||||
block bk = *src_block;
|
||||
int nerrors = 0;
|
||||
|
||||
jv_array_foreach(deps, i, dep) {
|
||||
// XXX This is a backward jv_array_foreach because bindings go in reverse
|
||||
for (int i = jv_array_length(jv_copy(deps)); i > 0; ) {
|
||||
i--;
|
||||
jv dep = jv_array_get(jv_copy(deps), i);
|
||||
|
||||
const char *as_str = NULL;
|
||||
int is_data = jv_get_kind(jv_object_get(jv_copy(dep), jv_string("is_data"))) == JV_KIND_TRUE;
|
||||
int raw = 0;
|
||||
|
||||
@@ -604,6 +604,10 @@ def f(a;b;c;d;e;f): [a+1,b,c,d,e,f]; f(.[0];.[1];.[0];.[0];.[0];.[0])
|
||||
[1,2]
|
||||
[2,2,1,1,1,1]
|
||||
|
||||
def f: 1; def g: f, def f: 2; def g: 3; f, def f: g; f, g; def f: 4; [f, def f: g; def g: 5; f, g]+[f,g]
|
||||
null
|
||||
[4,1,2,3,3,5,4,1,2,3,3]
|
||||
|
||||
# Test precedence of 'def' vs '|'
|
||||
def a: 0; . | a
|
||||
null
|
||||
@@ -1464,6 +1468,18 @@ import "data" as $e; import "data" as $d; [$d[].this,$e[].that,$d::d[].this,$e::
|
||||
null
|
||||
"is a test;is too;is a test;is too"
|
||||
|
||||
include "shadow1"; e
|
||||
null
|
||||
2
|
||||
|
||||
include "shadow1"; include "shadow2"; e
|
||||
null
|
||||
3
|
||||
|
||||
import "shadow1" as f; import "shadow2" as f; import "shadow1" as e; [e::e, f::e]
|
||||
null
|
||||
[2,3]
|
||||
|
||||
%%FAIL
|
||||
module (.+1); 0
|
||||
jq: error: Module metadata must be constant at <top-level>, line 1:
|
||||
@@ -1488,6 +1504,10 @@ modulemeta
|
||||
"c"
|
||||
{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}]}
|
||||
|
||||
modulemeta | .deps |= length
|
||||
"c"
|
||||
{"whatever":null,"deps":6}
|
||||
|
||||
%%FAIL IGNORE MSG
|
||||
import "syntaxerror" as e; .
|
||||
jq: error: syntax error, unexpected ';', expecting $end (Unix shell quoting issues?) at /home/nico/ws/jq/tests/modules/syntaxerror/syntaxerror.jq, line 1:
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def e: 1;
|
||||
def e: 2;
|
||||
@@ -0,0 +1 @@
|
||||
def e: 3;
|
||||
@@ -1 +1,2 @@
|
||||
def sym0: 0;
|
||||
def sym1: 0;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
def sym0: 1;
|
||||
def sym1: 1;
|
||||
def sym2: 1;
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
def sym1: 2;
|
||||
def sym2: 2;
|
||||
|
||||
Reference in New Issue
Block a user