Skip to content

Commit 6964d67

Browse files
authored
Update User Guide.md
1 parent 91a36a8 commit 6964d67

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

User Guide.md

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* [Directives (`vkzfFuIZW`)](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#directives)
2222
* [Setting a custom JSON value into a namespace](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#setting-a-custom-JSON-value-into-a-namespace)
2323
* [Fail-safe and Forward-Stop directives (`<..>f`, `<..>F`)](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#fail-safe-and-forward-stop-directives)
24-
* [Examples sporting _fail-safe_ using namespaces and interpolation](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#-examples-sporting-fail-safe-using-namespaces-and-interpolation)
24+
* [Examples illustrating _fail-safe_ using namespaces and interpolation](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#-examples-illustrating-fail-safe-using-namespaces-and-interpolation)
2525
* [Uses of `Fn` directive with non-default quantifiers (`<>Fn`, `><Fn`)](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#-uses-of-fn-directive-with-non-default-quantifiers)
2626
* [RE generated namespaces (`$0`, `$1`, etc)](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#re-generated-namespaces)
2727
* [Search quantifiers (`n`,`+n`,`n:m:s`)](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#search-quantifiers)
@@ -573,6 +573,11 @@ All REGEX lexemes also support template/namespace
573573
[interpolation](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#interpolation). The ineterpolation is applied before
574574
regex search performed.
575575

576+
_NOTE: the namespace tokens usage in REGEX lexemes is restricted to alphabetical names only (e.g.: `{abc}`):
577+
\- numerical namespaces (e.g., `{123}` ) might be clashing with REGEXP quantifiers and hence not supported,
578+
\- the auto-tokens (e.g.: '$abc') are also unsupported, because at the time of walking the iterator is yet unresolved_
579+
580+
576581
#### Search suffixes
577582
This is the complete list of suffixes that control _search_ behavior:
578583
* `r`: default (could be omitted), fully matches _JSON string_ values (e.g.: `<CO>`, `<CO>r`)
@@ -609,7 +614,7 @@ This is the complete list of suffixes that control _search_ behavior:
609614

610615
Some search lexemes (and
611616
[directives](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#directives))
612-
require their content is set and be **non-empty** (`R`,`d`,`D`,`L`,`j`,`s`,`t`,`v`,`z`,`u`,`I`,`Z`,`W`), otherwise an exception
617+
require their content is set and be **non-empty** (`R`,`d`,`D`,`L`,`j`,`s`,`t`,`v`,`z`,`u`,`I`,`Z`,`W`,`S`), otherwise an exception
613618
_`walk_empty_lexeme`_ will be thrown
614619

615620
A few of search lexemes might be left empty, but then they cary a semantic of an **empty match** (`r`,`l`):
@@ -625,17 +630,8 @@ e.g.: `<array>i` - upon a match will preserve found _JSON array_ in the namespac
625630

626631
##### \* Cached Search
627632
`jtc` is super efficient searching recursively even huge JSONs structures - normally no exponential search decay will be observed
628-
(which is very typical for such kind of operations). The decay is avoided because `jtc` builds a cache for all searches (whenever
633+
(which is very typical for such kind of operations). The decay is avoided because `jtc` builds a cache for **_all_** searches (whenever
629634
cacheing is required, both recursive and non-recursive) and thus all subsequent matches are taken from the cache.
630-
Though, there're couple cases when search could not be _cached_ in principle - when the search lexeme is a _dynamic_ type, i.e., when
631-
resolution of the search is dependent on the _namespace_ value.
632-
Here's the list of such search types:
633-
* recursive `<..>s`,`<..>t`: the lexemes are using _namespaces_ when performing search and hence could not be cached
634-
* JSON match when the lexeme is a template, e.g.: `<{ "label": {{val}} }>j`: templates typically require _namespace_ for interpolation
635-
and hence are also non-cacheable, though `<..>j` searches with static JSONs will be cached - e.g.: `<{"label": "val" }>j` is cacheable)
636-
637-
\- all the above cases are exempt from cacheing and hence the exponential decay might become noticeable, so be aware when building a
638-
query for very large JSON structures (order of hundred thousands of nodes)
639635

640636

641637
#### Directives
@@ -653,7 +649,12 @@ for the currently walked JSON elements, these are _directives_:
653649
* `F`: Forward-Stop: behavior of the directive is dependent on spelling:
654650
* `<>F` - when the directive is reached, the currently walked path is skipped and silently proceeds to the next walk iteration
655651
without ending the walk (like _`continue`_ loop operator in some programming languages)
652+
* `<>FN`, where `N` is a non-zero quantifier - implements a _"jump"_ logic: it will skip over N lexemes
653+
starting with the `F` lexeme itself; thus `<>F1` just continues walk with the next lexeme, `<>F2` will skip over the next lexeme,
654+
etc.
656655
* `><F` - when the directive is reached, the walk successfully ends for the output processing (similar to _`break`_ loop operator)
656+
* `><FN`, where `N` is a non-zero quantifier - implements "_repeat"_ logic: repeats walked path N times, e.g.:
657+
`><F1` will produce 2 identical walk results (original one, and one repeated)
657658
* `u`: user evaluation of the walk-path: the lexeme is the _`shell cli`_ sequence which affects walking: if a returned result of the
658659
shell evaluation is `0` (success) then walk continues, otherwise the walk fails; the lexeme is subjected for template
659660
interpolation
@@ -663,10 +664,11 @@ for the currently walked JSON elements, these are _directives_:
663664
effects - the former calculates the entire JSON size, while the latter does only the number of children); with the quantifier of `1`
664665
(i.e., `<StrSize>Z1`) saves into the namespace a size of the currently walked _JSON string_, otherwise (if not a string) `-1`
665666
* `W` saves into the provided namespace a currently walked JSON's walk-path as a _JSON array_ (e.g.: `<wp>W`)
667+
* `S` restores the point of walk (if it can be restored) previously saved by `W` lexeme (e.g.: `<wp>S`)
666668

667669

668670
#### Setting a custom JSON value into a namespace
669-
There's a set of lexemes which may reference a name in the
671+
There's a set of lexemes (search lexemes and directives) which may reference a name in the
670672
[_namespace_](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#namespace) for capturing a currently walked JSON elements:
671673
`P`,`N`,`b`,`n`,`a`,`o`,`i`,`c`,`e`,`w`,`q`,`Q`,`g`,`G`,`v`,`k`,`f`,`F`.
672674
All of those lexemes also allow capturing a custom JSON value in lieu of currently walked JSON - if the lexeme's value is given in
@@ -683,10 +685,10 @@ into the _walk-path_. Let's break it down:
683685

684686
When directive `F` is paired with `<>f`, together they cover all cases of walk-paths branching:
685687
* ... `<>f` {if this path fails, then a walk ends reinstating the walk at `<>f` point}
686-
* ... `<>f` {if this path does not fail, then skip it} `<>F` {otherwise keep walking this path starting from `<>f` point} ...
687-
* ... `<>f` {if this path does not fail, then end walking} `><F` {otherwise walk this path} ...
688-
* ... `<>f` {if this path does not fail, then end walking} `><F <>F` # otherwise skip it (i.e., skip the failed path)
689-
* etc (there's unlimited number of times `<>f` and `<>F`/`><F` pairs could be present in the walk)
688+
* ... `<>f` {if this path succeeds, then skip the result} `<>F` {otherwise keep walking this path starting from `<>f` point} ...
689+
* ... `<>f` {if this path path succeeds, then end walking} `><F` {otherwise walk this path} ...
690+
* ... `<>f` {if this path succeeds, then end walking} `><F <>F` # otherwise skip it (i.e., skip the failed path/result)
691+
* etc. (there's unlimited number of times `<>f` and `<>F`/`><F` pairs could be present in the walk)
690692

691693
Say, we want to list all `mobile` phone records, let's do it along with names of phone holders:
692694
```bash
@@ -721,7 +723,7 @@ further walking fails, there:
721723
one to the failing point)
722724

723725

724-
##### \* Examples sporting _fail-safe_ using namespaces and interpolation:
726+
##### \* Examples illustrating _fail-safe_ using namespaces and interpolation:
725727
Say we want to list from the address book all the record holders and indicate whether they have any children or not in
726728
this format:
727729
`<Name> has children: true/false`
@@ -738,7 +740,7 @@ bash $ <ab.json jtc -w'[0][:][name]<N>v'
738740
"Jane"
739741
bash $
740742
```
741-
2. Now let's inspect a sibling record `children`:
743+
2. Now let's inspect a sibling record `children` (while memorizing `Name`):
742744
```bash
743745
bash $ <ab.json jtc -w'[0][:][name]<N>v [-1][children]' -r
744746
[ "Olivia" ]
@@ -789,7 +791,7 @@ bash $ <<<$jsn jtc -pw'<name>l:[-1]' -tc
789791
]
790792
bash $
791793
```
792-
But what if we want to walk entries rather than purging (e.g., for reason of template-interpolating the entries at the output)?
794+
But what if we want to walk entries rather than purge (e.g., for reason of template-interpolating the entries at the output)?
793795
The prior solution would require
794796
[chaining the output](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#Chaining-option-sets)
795797
to the next option set (which is quite a reasonable solution too, e.g.: `<<<$jsn jtc -pw'<name>l:[-1]' / -w[:] -tc`),
@@ -824,11 +826,12 @@ bash $
824826

825827
##### \* Uses of `Fn` directive with non-default quantifiers
826828
there are couple other uses for `Fn` lexeme with a non-zero (non-default) quantifiers:
827-
- `<>Fn` - that variant of the lexeme acts as a 'jump' instruction for the walk path - i.e., once walked, it will jump to the `n`th
828-
lexeme (from the lexeme `<>F`) and continues walking from there. E.g.: `<>F1` does not do anything - it continues walking from the 1st
829-
lexeme after `<>F1`, `<>F2` will jump over one lexeme and continues walking from the 2nd one, and so on and so forth.
829+
- `<>Fn` - that variant of the lexeme implements a **_jump_** logic for the walk path - i.e., once walked, it will jump to the `n`th
830+
lexeme (counting from the lexeme `<>F` itself) and continues walking from there.
831+
E.g.: `<>F1` does not do anything - it continues walking from the 1st lexeme after `<>F1`,
832+
`<>F2` will jump over the very next lexeme and continues walking from the 2nd one, and so on and so forth.
830833
- `><Fn` - this variant will repeat the same walk up to the lexeme additionally `n` times - that is useful when there's a need to
831-
replicate a path additionally `n` times
834+
_repeat_ the path additionally `n` times
832835

833836
For example, to duplicate all the found address records, use `<>Fn`:
834837
```
@@ -873,7 +876,7 @@ Optionally a quantifier may follow the search lexeme (if a lexeme has a suffix,
873876
Quantifiers in search lexemes allow selecting match instance (i.e., select first match, second one, etc, or a range of matches)
874877
Quantifiers exist in the following formats:
875878
- `n`, - a positive number - tells which instance of a match to pick. By default, a quantifier `0` is applied
876-
(i.e., first match is selected)
879+
(i.e., first match selected)
877880
- `+n` - selects all match instances starting from `n`th (zero based)
878881
- `n:m:s` - slice select: the notation rules for this quantifier the same as for
879882
[subscript slices](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#subscript-slice-notation)

0 commit comments

Comments
 (0)