def-gthill / lexurgy

A high-powered sound change applier
GNU General Public License v3.0
44 stars 5 forks source link

Optional Argument in Environment not matching #31

Closed mosel00 closed 3 years ago

mosel00 commented 3 years ago

Minimal reproducible example:

label:
 a => c / a b b? _

Input:

aba
abba

Output

aba => abc
abba => abba

Bug: abba should get changed to abbc, but instead is unaffected by the change.

def-gthill commented 3 years ago

Thanks for reporting! This has to do with a current limitation of optionals, where they refuse to consume elements that also match the next element in sequence. Before the underscore, the rule is evaluated right to left, so the next element after b? is b. Since anything that b? could consume also matches b, this optional will never consume anything.

I'm planning to implement proper backtracking at some point to make this easier on the user, and the more complaints I get about it, the higher a priority it will be!

For now, there are a couple possible workarounds, depending on the details that you've taken out to create the minimal reproducible example.

You can use parentheses to group the b with the previous element:

label:
 a => c / (a b) b? _

Now there's no overlap between what b? can match and what the next element, (a b), can match.

Or you can switch the order of the b and b?:

label:
 a => c / a b? b _

Again, this removes the overlap with the next element, which is now a.

Hope this helps!