Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert and longest match #132

Open
arademaker opened this issue Aug 12, 2021 · 1 comment
Open

revert and longest match #132

arademaker opened this issue Aug 12, 2021 · 1 comment

Comments

@arademaker
Copy link

Following the video https://youtu.be/F8F422GldwY, I could reproduce the same behaviour but I really didn't understand why the reverse of the Alphabet worked in the InsertBrackets rule.

For instance, if I got it right, the InsertBrackets will be looking for the sequence hg in angha? I suppose there is some hidden interaction between the @-> and the .r operator not described in the video.. Am I missing something?

define Alphabet [ {a} | {g} | {n} | {ng} | {gh} ];
define InsertBrackets [ Alphabet.r @-> %} ... %{ ].r;
 foma[1]: down ana
{a}{n}{a}
foma[1]: down angha
{a}{n}{gh}{a}
@mhulden
Copy link
Owner

mhulden commented Aug 12, 2021

No hidden interaction. The rule is compiled as left-to-right, then the resulting transducer is reversed (yielding right-to-left longest-match). The alphabet transducer is also reversed to make it all work. The alphabet could have been defined explicitly like the below (without reversal):

def Alphabet [a | g | n | {gn} | {hg}];
def InsertBrackets [ Alphabet @-> %} ... %{  ].r;

yielding the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants