Skip to content

Instantly share code, notes, and snippets.

@KrisShannon
Created January 11, 2012 12:30
Show Gist options
  • Save KrisShannon/1594445 to your computer and use it in GitHub Desktop.
Save KrisShannon/1594445 to your computer and use it in GitHub Desktop.
Perl6 LTM Semantics
L.T.M.P. = Longest Term Matching Prefix
P.P. = Partially procedural (the L.T.M.P. cannot extend beyond this construct)
L.T.M.P. will match the whole construct of anything which is not P.P.
FOO BAR
P.P. if either FOO or BAR are P.P.
if FOO is not P.P. then the L.T.M.P is FOO followed by the L.T.M.P of BAR
otherwise the L.T.M.P is the L.T.M.P of FOO
FOO | BAR
P.P. if either FOO or BAR are P.P.
L.T.M.P is the alternation of the L.T.M.P's of FOO and BAR
FOO & BAR
P.P. if either FOO or BAR are P.P.
L.T.M.P is the conjuction of the L.T.M.P's of FOO and BAR
i.e. for a given target the L.T.M.P. is the shorter match
against the L.T.M.P's of FOO and BAR
( FOO )
[ FOO ]
P.P. if FOO is P.P.
L.T.M.P. is the L.T.M.P. of FOO
{ CODE }
FOO || BAR
FOO && BAR
P.P.
L.T.M.P. is empty
**** S05 disagrees **** P.P. and L.T.M.P. are the same as FOO for || and &&
FOO ~~ BAR
FOO !~~ BAR
P.P.
L.T.M.P. is the L.T.M.P. of FOO
FOO ~ BAR BAZ
P.P. if any of FOO, BAR or BAZ are P.P.
if neither FOO nor BAZ are P.P. then the L.T.M.P. is FOO followed by BAZ followed by the L.T.M.P. of BAR
otherwise unless FOO is P.P. then the L.T.M.P is FOO followed by the L.T.M.P of BAZ
otherwise the L.T.M.P is the L.T.M.P of FOO
FOO QUANTIFIER
FOO QUANTIFIER % SEP
P.P. if FOO (or SEP) is P.P. or if QUANT is not greedy
L.T.M.P is emtpy if QUANT is not greedy and has minimum repetitions of 0
otherwise if SEP is P.P. but FOO isn't then the L.T.M.P. is FOO followed by the L.T.M.P of SEP
otherwise the L.T.M.P is the L.T.M.P of FOO
**** S05 DISAGREES *** eager (non-greedy) quantifiers are P.P. and always have an empty L.T.M.P.
::
:::
P.P.
L.T.M.P. is empty
<?>
<?FOO>
<!>
<!FOO>
Not P.P.
L.T.M.P is empty
SPECIAL CASE - LTM does not have to worry about this for correctness as long as LTM backtracking
works properly, then any longest term which chooses this path but the assertion fails should
just backtrack to the next longest term.
<SUBRULE>
<.SUBRULE>
If a subrules definition is still P.P. while assuming all subrule calls within it are not,
then the subrule invocation is P.P.
Otherwise the subrule has a list of dependent subrules which if any are P.P. then the subrule
invocation is also.
L.T.M.P is the L.T.M.P of the subrule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment