21
21
* [Directives (`vkzfFuIZW`)](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#directives)
22
22
* [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)
23
23
* [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)
25
25
* [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)
26
26
* [RE generated namespaces (`$0`, `$1`, etc)](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#re-generated-namespaces)
27
27
* [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
573
573
[interpolation](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#interpolation). The ineterpolation is applied before
574
574
regex search performed.
575
575
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
+
576
581
#### Search suffixes
577
582
This is the complete list of suffixes that control _search_ behavior:
578
583
* `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:
609
614
610
615
Some search lexemes (and
611
616
[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
613
618
_`walk_empty_lexeme`_ will be thrown
614
619
615
620
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
625
630
626
631
##### \* Cached Search
627
632
`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
629
634
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)
639
635
640
636
641
637
#### Directives
@@ -653,7 +649,12 @@ for the currently walked JSON elements, these are _directives_:
653
649
* `F`: Forward-Stop: behavior of the directive is dependent on spelling:
654
650
* `<>F` - when the directive is reached, the currently walked path is skipped and silently proceeds to the next walk iteration
655
651
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.
656
655
* `><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)
657
658
* `u`: user evaluation of the walk-path: the lexeme is the _`shell cli`_ sequence which affects walking: if a returned result of the
658
659
shell evaluation is `0` (success) then walk continues, otherwise the walk fails; the lexeme is subjected for template
659
660
interpolation
@@ -663,10 +664,11 @@ for the currently walked JSON elements, these are _directives_:
663
664
effects - the former calculates the entire JSON size, while the latter does only the number of children); with the quantifier of `1`
664
665
(i.e., `<StrSize>Z1`) saves into the namespace a size of the currently walked _JSON string_, otherwise (if not a string) `-1`
665
666
* `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`)
666
668
667
669
668
670
#### 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
670
672
[_namespace_](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#namespace) for capturing a currently walked JSON elements:
671
673
`P`,`N`,`b`,`n`,`a`,`o`,`i`,`c`,`e`,`w`,`q`,`Q`,`g`,`G`,`v`,`k`,`f`,`F`.
672
674
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:
683
685
684
686
When directive `F` is paired with `<>f`, together they cover all cases of walk-paths branching:
685
687
* ... `<>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)
690
692
691
693
Say, we want to list all `mobile` phone records, let's do it along with names of phone holders:
692
694
```bash
@@ -721,7 +723,7 @@ further walking fails, there:
721
723
one to the failing point)
722
724
723
725
724
- ##### \* Examples sporting _fail-safe_ using namespaces and interpolation:
726
+ ##### \* Examples illustrating _fail-safe_ using namespaces and interpolation:
725
727
Say we want to list from the address book all the record holders and indicate whether they have any children or not in
726
728
this format:
727
729
`<Name> has children: true/false`
@@ -738,7 +740,7 @@ bash $ <ab.json jtc -w'[0][:][name]<N>v'
738
740
"Jane"
739
741
bash $
740
742
```
741
- 2. Now let's inspect a sibling record `children`:
743
+ 2. Now let's inspect a sibling record `children` (while memorizing `Name`) :
742
744
```bash
743
745
bash $ <ab.json jtc -w'[0][:][name]<N>v [-1][children]' -r
744
746
[ "Olivia" ]
@@ -789,7 +791,7 @@ bash $ <<<$jsn jtc -pw'<name>l:[-1]' -tc
789
791
]
790
792
bash $
791
793
```
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)?
793
795
The prior solution would require
794
796
[chaining the output](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#Chaining-option-sets)
795
797
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 $
824
826
825
827
##### \* Uses of `Fn` directive with non-default quantifiers
826
828
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.
830
833
- `><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
832
835
833
836
For example, to duplicate all the found address records, use `<>Fn`:
834
837
```
@@ -873,7 +876,7 @@ Optionally a quantifier may follow the search lexeme (if a lexeme has a suffix,
873
876
Quantifiers in search lexemes allow selecting match instance (i.e., select first match, second one, etc, or a range of matches)
874
877
Quantifiers exist in the following formats:
875
878
- `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)
877
880
- `+n` - selects all match instances starting from `n`th (zero based)
878
881
- `n:m:s` - slice select: the notation rules for this quantifier the same as for
879
882
[subscript slices](https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md#subscript-slice-notation)
0 commit comments