Commit Graph

47 Commits

Author SHA1 Message Date
Muh Muhten 130152a2ac Ensure limit(0; ...) is empty 2019-02-21 04:11:41 -05:00
Chance Zibolski 4f6045a94e Support "if" without "else" clause
Defaults the else clause to the identity filter "." if an else clause is
missing.

The following two jq programs are considered equivalent:

```
if .foo then
    .foo = "bar"
else
    .
end
```

```
if .foo then
    .foo = "bar"
end
```
2019-02-20 20:03:26 -06:00
Muh Muhten 1ef90acb38 Bind data imports properly when already resolved 2019-02-20 20:02:41 -06:00
Nicolas Williams 2660b04a73 Fix infinite loop in index("") (fix #1815) 2019-02-08 20:40:55 -06:00
David Haguenauer 63ba2b1637 Add tests for built-in function contains 2019-01-22 11:00:08 -06:00
Nicolas Williams 61cd6dbb3b contains should handle embedded NULs (fix #1732) 2019-01-18 22:33:46 -06:00
William Langford 0673dee1b3 Fix destructuring alternation
Attempting to use the existing FORK_OPT opcode resulted in difficulty
knowing when to pop an error message off the stack and when not to. This
commit makes DESTRUCTURE_ALT a real opcode that is identical to
FORK_OPT, except for never pushing the error message onto the stack when
continuing from an error backtrack.

Some small changes were necessary to the DUP/POP behavior surrounding
destructuring to accomodate this.
2018-08-17 23:15:48 -04:00
Nicolas Williams 9a4576e756 Revert "reduce: handle empty updates (fix #1313)"
This reverts commit e24af3c78e.

While the semantics are desirable, there is no way to implement them
efficiently.  The reason is that in order to handle backtracking (empty)
from the state update expression, we have to retain a reference to the
reduction state value in order to restore it upon backtracking.
Retaining a reference to the reduction state kills performance by
causing lots of additional memory allocations and garbage because the
input to the update expression will always have at least two references,
thus no changes to it can be done in-place, and all changes end up being
CoW changes.

Avoiding this is the very reason for the LOADVN instruction (leaving
`null` in the variable loaded from).
2017-12-11 11:20:16 -06:00
pkoppstein 4b4cf789e0 def isempty(g) # Testing 'isempty(empty)' at line number 1364 2017-04-15 16:45:00 -05:00
Nicolas Williams 7935d307f0 Allow . as {$a:$b} destructuring 2017-03-26 05:36:23 -05:00
Nicolas Williams 2421dfb843 Add more destructuring tests 2017-03-26 05:36:22 -05:00
William Langford c8a2a0acc2 Fix a tripped assertion when generating reduces
A noop body, while useless, should still compile successfully
2017-03-26 05:36:22 -05:00
Nicolas Williams b142d484d5 Conditional exprs are not path exprs (fix #1368)
The conditional expression in if-then-elif-else-end cannot contribute to
path expressions because it doesn't change the input to any of the then/
elif/else expressions.  These must be generated via gen_subexp().

See also #1366.
2017-03-15 01:07:37 -05:00
Nicolas Williams 9df19f53e4 Fix off-by-one bug in #1108 fix 2017-03-01 22:45:02 -06:00
Nicolas Williams 65cbaac344 Array slice overflows (fix #1108) 2017-03-01 17:48:45 -06:00
Nicolas Williams 2fcb257168 getpath/1 should be a path expression (fix #1358)
It needs to be possible to do something like

    getpath($paths[]) += 1

meaning: increment all the paths in . that are listed in $paths[].

In order to do this getpath() needs to update the jq->path and
jq->value_at_path as necessary.
2017-02-28 21:54:30 -06:00
Nicolas Williams 1a8a0ae0f5 Fix error message for undefined vars 2017-02-26 00:37:28 -06:00
Nicolas Williams 8cde328007 Allow var bindings in path expressions (#1347)
The expression in a variable binding is not and must not be seen as
being part of a path expression in which the variable binding appears.
2017-02-21 18:11:35 -06:00
Shaun Guth e0b784ac6d Add @base64d for decoding base64 #47 2017-02-12 16:03:59 -05:00
Nicolas Williams 7bdf3a39ad Add SQL-style operators (#1322) 2017-01-30 14:11:05 -06:00
Nicolas Williams 396543191c Make first(g) more efficient: extract only 1 value
first(g) was extracting two values, which, if g is slow, made first(g)
slow.  And if the second extraction were to throw an error, then
first(g) would throw that error, which is clearly not the right thing to
do.  Besides that, first(g) was allocating garbage, which it no longer
does.
2017-01-30 14:11:05 -06:00
Nicolas Williams e24af3c78e reduce: handle empty updates (fix #1313) 2017-01-30 14:11:05 -06:00
William Langford e84d17196c Handle cut-off UTF-8 sequences when reading files
Read additional bytes from the file to complete the UTF-8 sequence so the bytes
in it don't get converted to U+FFFD replacement characters.
2017-01-27 21:04:26 -05:00
Nicolas Williams 6c635998f8 Always test sort_by/group_by post-#1082 2016-01-18 12:17:58 -06:00
Nicolas Williams 062f86a625 Enable more tests on Windows; move sort_by tests
Use %%FAIL IGNORE MSG for error messages that differ on Windows, and
move the sort_by/group_by tests that fail qhen qsort() is not stable.

Now only tests/sorttest and tests/shtest are disabled on Windows.
2016-01-17 12:45:01 -06:00
David Tolnay e17ccf2297 Support numbers and boolean in join (fix #930) 2015-10-25 12:40:15 -07:00
David Tolnay 6c31850e86 If-then-else documentation for forking conditional (fix #942) 2015-10-17 21:15:24 -07:00
David Tolnay c8dc164566 Support lowercase name in from_entries (fix #990) 2015-10-17 20:50:40 -07:00
David Tolnay 4490d9d1f6 Support NaN in path expressions (fix #962) 2015-09-24 10:33:34 -07:00
David Tolnay 58f082d74f Delete negative indices in array (fix #954) 2015-09-21 20:33:06 -07:00
David Tolnay 154d0ee4a8 Fix assert fail if object literal key is not a string (fix #953) 2015-09-21 12:47:06 -07:00
Joel Nothman 83e8ec587f utf8bytelength: count UTF8 string bytelength
[Builtin name changed, and it only works on string inputs. -Nico]
2015-09-13 01:01:24 -05:00
David Tolnay b8f71d3659 Fix assert fail when delpaths is given non-array (fix #901) 2015-08-16 19:44:16 -07:00
David Tolnay 58a053d7de Fix memory leak in non-constant module declaration 2015-08-13 21:42:35 -07:00
David Tolnay 7b5c6a9224 Fix assert fail on invalid import path (fix #899) 2015-08-13 21:42:35 -07:00
David Tolnay 5479d7f2dc Fix assert fail on non-object import metadata (fix #900) 2015-08-13 21:42:35 -07:00
Nicolas Williams 9a3f802d20 Fix #896, double-free in setpath 2015-08-11 17:46:15 -05:00
David Tolnay a47b32999b Fix range(value;stream) (fix #886) 2015-08-06 23:05:03 -07:00
Santiago Lapresta 3d49fc59dd Implement flatten/0 in terms of flatten/1 2015-07-24 21:55:43 -07:00
David Tolnay 16e8d0b1ab detect invalid path expression (fix #862) 2015-07-24 20:23:07 -07:00
David Tolnay 66ef8e2c24 Resolve shift/reduce conflict of 'def' vs '|'
This was an important conflict. In the following expression:

    def a: 0; . | a

Bison needs to decide between these two equally valid
parses:

    (def a: 0; .) | a
    def a: 0; (. | a)

For jq we want the second one, because the first results in
"a/0 is not defined". In the current parser the first parse
is a reduce and the second parse is a shift. Since Bison
prefers to shift in shift/reduce conflicts, we accidentally
got the correct behavior.

This commit adds a precedence level FUNCDEF which is lower
precedence than '|', meaning we explicitly choose the
correct parse.

Of course many unit tests already cover this case, but I
added one specifically for it.
2015-07-19 09:42:01 -07:00
Nicolas Williams 579518c78d Use include for import into namespace 2015-07-10 10:19:33 -05:00
David Tolnay 6e27de4f74 strftime wrong day-of-week (fix #838) 2015-07-01 20:37:16 -07:00
Nicolas Williams fd4f4f2087 Make --run-tests' jv_test() quiet 2015-06-28 13:39:32 -05:00
Nicolas Williams 32c4759e6b Add more basic number tests 2015-06-27 23:15:16 -05:00
Nicolas Williams aaf305868c Restore import into caller's namespace 2015-06-26 23:40:37 -05:00
David Tolnay 1146b8b84a separate jq, oniguruma, sh, and man tests 2015-06-18 23:55:43 -05:00