meta data for this page
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
scan_statement [2020/07/24 11:14] – created revusky | scan_statement [2021/02/08 18:16] – revusky | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== The new SCAN construct | + | ===== The new SCAN Statement |
- | JavaCC 21 introduces a new '' | + | JavaCC 21 introduces a new '' |
- | Note that all the older syntax still works and will work for the foreseeable feature. Here is a rundown of the differences between '' | + | Note, however, |
+ | Here is a rundown of the differences between '' | ||
==== The parameters of SCAN (assuming there are any) are not enclosed in parentheses. ==== | ==== The parameters of SCAN (assuming there are any) are not enclosed in parentheses. ==== | ||
Thus, where you previously wrote: | Thus, where you previously wrote: | ||
- | |||
< | < | ||
Line 14: | Line 14: | ||
</ | </ | ||
- | you can now write: | + | you would now write: |
< | < | ||
Line 23: | Line 23: | ||
< | < | ||
- | LOOKAHEAD(Foo()) Foo() Bar() | + | LOOKAHEAD(" |
- | </ | + | |
- | + | ||
- | < | + | |
- | LOOKAHEAD | + | |
</ | </ | ||
Line 33: | Line 29: | ||
< | < | ||
- | SCAN Foo => Foo Bar | + | SCAN " |
</ | </ | ||
Note that the arrow is necessary in the above to separate the lookahead expansion from the expansion to be parsed. You can also write: | Note that the arrow is necessary in the above to separate the lookahead expansion from the expansion to be parsed. You can also write: | ||
- | |||
< | < | ||
SCAN 3 => Foo | SCAN 3 => Foo | ||
</ | </ | ||
- | |||
but the arrow is optional because it is not necessary to disambiguate anything. | but the arrow is optional because it is not necessary to disambiguate anything. | ||
- | |||
Line 54: | Line 47: | ||
< | < | ||
- | LOOKAHEAD(Foo() {someCondition()}) FooBar() | + | LOOKAHEAD(Foo(), {someCondition()}) FooBar() |
</ | </ | ||
you now write: | you now write: | ||
- | |||
< | < | ||
Line 97: | Line 89: | ||
< | < | ||
- | SCAN 0 {someCondition} Foo | + | SCAN 0 {someCondition} |
</ | </ | ||
- | In the legacy lookahead, if you only have semantic lookahead, the number of tokens to be scanned is assumed to be zero, i.e. if the condition | + | In the legacy lookahead, if you only have semantic lookahead, the number of tokens to be scanned is assumed to be zero, i.e. if the condition |
- | On consideration, | + | ==== The SCAN construct also you to use contextual predicates. ==== |
+ | The [[contextual_predicates]] construct allows you to express conditions based on scanning backwards in the lookahead/ | ||
+ | You can find more information [[contextual_predicates|here]]. | ||
- | ==== The SCAN construct also allows the newer LOOKBEHIND construct. ==== | + | ==== Addendum: the SCAN-less SCAN? ==== |
- | + | ||
- | This is outlined separately. | + | |
- | + | ||
- | ===== Addendum: the SCAN-less SCAN? ===== | + | |
Even the newer SCAN construct has some redundancies. There is no obvious reason to oblige anybody write even: | Even the newer SCAN construct has some redundancies. There is no obvious reason to oblige anybody write even: | ||
Line 169: | Line 159: | ||
</ | </ | ||
- | In this case, because I think it is so common, we decided to allow this. And, in fact, you can see that this is already used in internal development, | + | In this case, because I think it is so common, we decided to allow this. And, in fact, you can see that this is already used in internal development, |
+ | |||
+ | |||
+ | ==== Recap ==== | ||
+ | |||
+ | The new '' | ||
+ | * // | ||
+ | * [[semantic lookahead]], | ||
+ | * a [[contextual_predicates]] predicate | ||
+ | * [[syntactic lookahead]] | ||
+ | |||
+ | Caveats: | ||
+ | * The '' | ||
+ | * If no numerical or syntactic lookahead is specified, the generated code will scan ahead an // | ||
+ | |||
+ | Note that an empty SCAN statement can be simply written alternatively with a lone arrow, i.e. '' | ||
- | ===== The newer SCAN construct allows you to use the newer " | ||
- | This is documented separately. | ||