meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lookbehind [2020/09/24 13:07] – [LOOKBEHIND] revusky | contextual_predicates [2023/03/03 14:23] (current) – revusky | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | The '' | + | A // |
- | It is best to just jump into some actual examples | + | The easiest way to describe this is with some actual examples. |
- | < | + | ==== Specifying that a production is non-reentrant ==== |
- | [ SCAN ~\...\Foo => Foo ] | + | Probably the most typical usage will be to guarantee that a production is not // |
+ | < | ||
+ | [ SCAN ~\...\Foo => Foo ] | ||
</ | </ | ||
+ | First of all, the tilde " | ||
- | First of all, the tilde " | + | The above sort of predicate |
- | The ellipsis "..." that follows the backslash means that there can be an arbitrary number of intervening productions in the call stack. If, for example, we wrote: | + | ==== Scanning Forward vs. Backward, Ellipsis and Wild-card |
- | < | + | Note that the elements in a // |
- | [ SCAN ~\.\Foo => Foo] | + | In the above example, the ellipsis "..." that follows the backslash means that there can be an arbitrary number of intervening productions in the call stack. The // |
+ | < | ||
+ | [ SCAN ~\.\Bar => Foo] | ||
</ | </ | ||
- | this would mean that we enter the '' | + | this would mean that we enter the '' |
Or alternatively, | Or alternatively, | ||
- | [ SCAN \.\Bar => Foo ] | + | < |
+ | [ SCAN \.\Bar => Foo ] | ||
+ | </ | ||
- | would mean that we enter the '' | + | would mean that we enter the '' |
+ | Now, consider the following predicate that uses a forward slash: | ||
+ | < | ||
+ | [ SCAN /Foo/Bar => Baz ] | ||
+ | </ | ||
- | ===== Example ===== | + | This means that we enter the Baz production only if the root production is a '' |
- | [ SCAN \Foo\Bar | + | ==== Optional Ending Slash ==== |
- | The above predicate means that we enter the Baz production only if the current production is a '' | + | If the predicate begins with a forward slash, it may end // |
- | A tilde " | + | < |
+ | [ SCAN /Root/.../Foo\ => Bar ] | ||
+ | </ | ||
- | [ SCAN ~\Foo\Bar => Baz ] | + | This means that we check whether the root production, our entry point, was '' |
- | So, there, we only enter the '' | + | < |
+ | [ SCAN /Root/.../Foo/...\ => Bar] | ||
+ | </ | ||
- | If we wrote: | + | and simply: |
- | [ SCAN \Foo\.\Bar => Baz] | + | < |
+ | [ SCAN /Root/.../ | ||
+ | </ | ||
- | This would mean that we enter the '' | + | ==== Summary ==== |
- | Probably the most typical usage of the //lookbehind | + | A //contextual |
- | [ SCAN ~\...\Foo => Foo ] | + | An ellipsis "..." means that we can have an arbitrary number (including zero) of intervening productions. A dot " |
- | The above condition means that we will enter a Foo //only if// we have not already entered a Foo production. | + | A //lookahead predicate// can be combined with other conditions in a '' |
+ | |||
+ | < | ||
+ | ( SCAN 2 ~\...\Foo => Foo )* | ||
+ | </ | ||
+ | |||
+ | The above would mean that we check that we aren't already inside | ||
+ | |||
+ | Or alternatively, | ||
+ | |||
+ | < | ||
+ | ( SCAN ~\...\Foo " | ||
+ | </ | ||
+ | In the above we specify that Foo must be // | ||
+ | NB. If you have a '' | ||
- | A '' | + | Note also that // |