mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 06:45:27 +00:00
Peg captures get stack-like behavior (#18369)
* Implements reverse capture indexing. * Now works for modified backrefs too. * Changed reverse indexing syntax prefix for back-references to '$^'.
This commit is contained in:
@@ -27,7 +27,10 @@ notation meaning
|
||||
``{E}`` Capture: Apply expression `E` and store the substring
|
||||
that matched `E` into a *capture* that can be accessed
|
||||
after the matching process.
|
||||
``$i`` Back reference to the ``i``th capture. ``i`` counts from 1.
|
||||
``{}`` Empty capture: Delete the last capture. No character
|
||||
is consumed.
|
||||
``$i`` Back reference to the ``i``th capture. ``i`` counts forwards
|
||||
from 1 or backwards (last capture to first) from ^1.
|
||||
``$`` Anchor: Matches at the end of the input. No character
|
||||
is consumed. Same as ``!.``.
|
||||
``^`` Anchor: Matches at the start of the input. No character
|
||||
@@ -149,14 +152,15 @@ The PEG parser implements this grammar (written in PEG syntax)::
|
||||
rule <- identifier \s* "<-" expr ig
|
||||
identNoArrow <- identifier !(\s* "<-")
|
||||
prefixOpr <- ig '&' / ig '!' / ig '@' / ig '{@}' / ig '@@'
|
||||
literal <- ig identifier? '$' [0-9]+ / '$' / '^' /
|
||||
literal <- ig identifier? '$' '^'? [0-9]+ / '$' / '^' /
|
||||
ig identNoArrow /
|
||||
ig charset /
|
||||
ig stringlit /
|
||||
ig builtin /
|
||||
ig '.' /
|
||||
ig '_' /
|
||||
(ig "(" expr ig ")")
|
||||
(ig "(" expr ig ")") /
|
||||
(ig "{" expr? ig "}")
|
||||
postfixOpr <- ig '?' / ig '*' / ig '+'
|
||||
primary <- prefixOpr* (literal postfixOpr*)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user