Fix docs YAML (introduced in #432)

This commit is contained in:
Nicolas Williams committed 2014-08-08 18:01:42 -05:00
1 parent a696c6b551
commit eb12f0358e
1 file changed
+91 -100
+91 -100
View File
@@ -712,7 +712,7 @@ sections:
output: ['[5,3,7]'] output: ['[5,3,7]']
- program: '.[] | select(.id == "second")' - program: '.[] | select(.id == "second")'
input: '[{"id": "first", "val": 1}, {"id": "second", "val": 2}]' input: '[{"id": "first", "val": 1}, {"id": "second", "val": 2}]'
output: '{"id": "second", "val": 2}' output: ['{"id": "second", "val": 2}']
- title: "`arrays`, `objects`, `iterables`, `booleans`, `numbers`, `strings`, `nulls`, `values`, `scalars`" - title: "`arrays`, `objects`, `iterables`, `booleans`, `numbers`, `strings`, `nulls`, `values`, `scalars`"
@@ -1613,7 +1613,7 @@ sections:
jq uses the Oniguruma regular expression library, as do php, jq uses the Oniguruma regular expression library, as do php,
ruby, TextMate, Sublime Text, etc, so the description here ruby, TextMate, Sublime Text, etc, so the description here
will focus on jq specifics. will focus on jq specifics.
The jq regex filters are defined so that they can be used using The jq regex filters are defined so that they can be used using
one of these patterns: one of these patterns:
@@ -1652,10 +1652,10 @@ sections:
entries: entries:
- title: "`test(val)`, `test(regex; flags)`" - title: "`test(val)`, `test(regex; flags)`"
body: | body: |
Like `match`, but does not return match objects, only `true` or `false` Like `match`, but does not return match objects, only `true` or `false`
for whether or not the regex matches the input. for whether or not the regex matches the input.
examples: examples:
- program: 'test("foo")' - program: 'test("foo")'
input: '"foo"' input: '"foo"'
@@ -1664,31 +1664,31 @@ sections:
input: '"xabcd" "ABC"' input: '"xabcd" "ABC"'
output: true output: true
true true
- title: "`match(val)`, `match(regex; flags)`" - title: "`match(val)`, `match(regex; flags)`"
body: | body: |
**match** outputs an object for each match it finds. Matches have **match** outputs an object for each match it finds. Matches have
the following fields: the following fields:
* `offset` - offset in UTF-8 codepoints from the beginning of the input * `offset` - offset in UTF-8 codepoints from the beginning of the input
* `length` - length in UTF-8 codepoints of the match * `length` - length in UTF-8 codepoints of the match
* `string` - the string that it matched * `string` - the string that it matched
* `captures` - an array of objects representing capturing groups. * `captures` - an array of objects representing capturing groups.
Capturing group objects have the following fields: Capturing group objects have the following fields:
* `offset` - offset in UTF-8 codepoints from the beginning of the input * `offset` - offset in UTF-8 codepoints from the beginning of the input
* `length` - length in UTF-8 codepoints of this capturing group * `length` - length in UTF-8 codepoints of this capturing group
* `string` - the string that was captured * `string` - the string that was captured
* `name` - the name of the capturing group (or `null` if it was unnamed) * `name` - the name of the capturing group (or `null` if it was unnamed)
Capturing groups that did not match anything return an offset of -1 Capturing groups that did not match anything return an offset of -1
examples: examples:
- program: 'match("(abc)+"; "g")' - program: 'match("(abc)+"; "g")'
input: '"abc abc"' input: '"abc abc"'
output: output:
- '{"offset": 0, "length": 3, "string": "abc", "captures": [{"offset": 0, "length": 3, "string": "abc", "name": null}]}' - '{"offset": 0, "length": 3, "string": "abc", "captures": [{"offset": 0, "length": 3, "string": "abc", "name": null}]}'
- '{"offset": 4, "length": 3, "string": "abc", "captures": [{"offset": 4, "length": 3, "string": "abc", "name": null}]}' - '{"offset": 4, "length": 3, "string": "abc", "captures": [{"offset": 4, "length": 3, "string": "abc", "name": null}]}'
- program: 'match("foo")' - program: 'match("foo")'
@@ -1696,7 +1696,7 @@ sections:
output: ['{"offset": 0, "length": 3, "string": "foo", "captures": []}'] output: ['{"offset": 0, "length": 3, "string": "foo", "captures": []}']
- program: 'match(["foo", "ig"])' - program: 'match(["foo", "ig"])'
input: '"foo bar FOO"' input: '"foo bar FOO"'
output: output:
- '{"offset": 0, "length": 3, "string": "foo", "captures": []}' - '{"offset": 0, "length": 3, "string": "foo", "captures": []}'
- '{"offset": 8, "length": 3, "string": "FOO", "captures": []}' - '{"offset": 8, "length": 3, "string": "FOO", "captures": []}'
- program: 'match("foo (?<bar123>bar)? foo"; "ig")' - program: 'match("foo (?<bar123>bar)? foo"; "ig")'
@@ -1704,109 +1704,100 @@ sections:
output: output:
- '{"offset": 0, "length": 11, "string": "foo bar foo", "captures": [{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]}' - '{"offset": 0, "length": 11, "string": "foo bar foo", "captures": [{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]}'
- '{"offset": 12, "length": 8, "string": "foo foo", "captures": [{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}' - '{"offset": 12, "length": 8, "string": "foo foo", "captures": [{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}'
- program: '[ match("."; "g")] | length' - program: '[ match("."; "g")] | length'
input: '"abc"' input: '"abc"'
output: 3 output: 3
- title: "`capture(val)`, `capture(regex; flags)`" - title: "`capture(val)`, `capture(regex; flags)`"
body: | body: |
Collects the named captures in a JSON object, with the name Collects the named captures in a JSON object, with the name
of each capture as the key, and the matched string as the of each capture as the key, and the matched string as the
corresponding value. corresponding value.
examples: examples:
- program: 'capture("(?<a>[a-z]+)-(?<n>[0-9]+)")' - program: 'capture("(?<a>[a-z]+)-(?<n>[0-9]+)")'
input: '"xyzzy-14"' input: '"xyzzy-14"'
output: '{ "a": "xyzzy", "n": "14" }'' output: ['{ "a": "xyzzy", "n": "14" }']
- title: "`scan(regex)`, `scan(regex; flags)`" - title: "`scan(regex)`, `scan(regex; flags)`"
body: | body: |
Emit a stream of the non-overlapping substrings of the input Emit a stream of the non-overlapping substrings of the input
that match the regex in accordance with the flags, if any that match the regex in accordance with the flags, if any
have been specified. If there is no match, the stream is empty. have been specified. If there is no match, the stream is empty.
To capture all the matches for each input string, use the idiom To capture all the matches for each input string, use the idiom
[ expr ], e.g. [ scan(regex) ]. `[ expr ]`, e.g. `[ scan(regex) ]`.
example: example:
- program: 'scan("c")' - program: 'scan("c")'
input: '"abcdefabc"' input: '"abcdefabc"'
output: '"c"' output: ['"c"', '"c"']
'"c"'
- program: 'scan("b")'
- program: 'scan("b")' input: ("", "")
input: ("", "") output: ['[]', '[]']
output: '[]'
'[]"' - title: "`split(regex)`, `split(regex; flags)`"
body: |
- title: "`split(regex)`, split(regex; flags)`"
body: | For backwards compatibility, `split` emits an array of the strings
corresponding to the successive segments of the input string after it
For backwards compatibility, `split` emits an array of the strings has been split at the boundaries defined by the regex and any
corresponding to the successive segments of the input string after it specified flags. The substrings corresponding to the boundaries
has been split at the boundaries defined by the regex and any themselves are excluded. If regex is the empty string, then the first
specified flags. The substrings corresponding to the boundaries match will be the empty string.
themselves are excluded. If regex is the empty string, then the first
match will be the empty string. `split(regex)` can be thought of as a wrapper around `splits(regex)`,
and similarly for `split(regex; flags)`.
`split(regex)` can be thought of as a wrapper around `splits(regex)`,
and similarly for `split(regex; flags)`. example:
- program: 'split(", *")'
example: input: '"ab,cd, ef"'
- program: 'split(", *")' output: ['"ab","cd","ef"']
input: '"ab,cd, ef"`
output: '["ab","cd","ef"]'
- title: "`splits(regex)`, splits(regex; flags)`" - title: "`splits(regex)`, splits(regex; flags)`"
body: | body: |
These provide the same results as their `split` counterparts, These provide the same results as their `split` counterparts,
but as a stream instead of an array. but as a stream instead of an array.
example: example:
- program: 'splits(", *")' - program: 'splits(", *")'
input: '("ab,cd", "ef, gh")` input: '("ab,cd", "ef, gh")'
output: output: ['"ab"', '"cd"', '"ef"', '"gh"']
'"ab"'
'"cd"'
'"ef"'
'"gh"'
- title: "`sub(regex; tostring)`" - title: "`sub(regex; tostring)`"
body: |
body: |
Emit the string obtained by replacing the first match of regex in the
Emit the string obtained by replacing the first match of regex in the input string with `tostring`, after interpolation. `tostring` should
input string with `tostring`, after interpolation. `tostring` should be a jq string, and may contain references to named captures. The
be a jq string, and may contain references to named captures. The named captures are, in effect, presented as a JSON object (as
named captures are, in effect, presented as a JSON object (as constructed by `capture`) to `tostring`, so a reference to a captured
constructed by `capture`) to `tostring`, so a reference to a captured variable named "x" would take the form: "\(.x)".
variable named "x" would take the form: "\(.x)".
example:
example: - program: 'sub("^[^a-z]*(?<x>[a-z]*).*")'
- program: 'sub("^[^a-z]*(?<x>[a-z]*).*")' input: '"123abc456"'
input: '"123abc456"' output: '"ZabcZabc"'
output: '"ZabcZabc"'
- title: "`gsub(regex; string)`" - title: "`gsub(regex; string)`"
body: |
body: |
`gsub` is like `sub` but all the non-overlapping occurrences of the regex are
`gsub` is like `sub` but all the non-overlapping occurrences of the regex are replaced by the string, after interpolation.
replaced by the string, after interpolation.
example:
example: - program: 'gsub("(?<x>.)[^a]*"; "+\(.x)-")'
- program: 'gsub("(?<x>.)[^a]*"; "+\(.x)-")' input: '"Abcabc"'
output: '"+A-+a-"'
input: '"Abcabc"'
output: '"+A-+a-"'
- title: Advanced features - title: Advanced features
body: | body: |
Variables are an absolute necessity in most programming languages, but Variables are an absolute necessity in most programming languages, but