So I can announce a more optimistic alternative ending for advent Day 14 – The Little Match Girl: Building and Testing Big Grammars in Perl 6. The latest commit of the GH Grammar::Modelica repository parses everything in the Modelica Standard Library with no failures and all grammar module tests pass. It is commendably easy to match the Perl 6 grammars against the appendix B.2 Grammar from the Modelica Language Specification document.

There were some bumps on the road. When I started to look at the Standard Library failures Grammar::Tracer was crashing because of what turned out to be Grammar::Debugger issue 40 which has some workarounds. As I started to look closer at the grammars I started to wonder about all the <|w> tests and noticed that the <ws> rule matched 0 or more spaces in a way that could match between ‘a’ and ‘b’ in ‘ab’. One of the docs said something about “The default ws matches one or more … \s” so I tried a one or more match that didn’t quite work right either. Then I added my troubles to doc issue 1729 on “<.ws> poorly defined” and came up with something better as described there. Then there was a failure or two connected to a lookbehind bug subsequently reported as Rakudo issue 1659. Finally there were some cases of alternatives which didn’t try all possibilities because everything is a ratcheting rule and the existing coding required backtracking outside of the alternative. First I changed some rule(s) to regex(es) and then, with a better understanding of the problem, I filed doc issue 1962 and changed the regex(es) back to rule(s) with reordered alternatives.

I am happy with the final outcome which looks relatively simple and easy. The bumps along the way took some time and there is more work to do in making the creation of such a grammar as simple as it should be, both in terms of documentation and a fix for Grammar::Debugger issue 40.