/gist:4ecb7602b8e474a01c1e Secret
Last active
December 14, 2015 16:20
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use v6; | |
| grammar Goo { | |
| token ident { ^ ')'? 'A'+ $ } | |
| token qwert { <ident> | 'yuiop' } | |
| } | |
| test('ident', |< AA )A >); | |
| test('qwert', |< AA )A >); | |
| sub test (Str $top, *@egs) { | |
| for @egs -> $eg { | |
| say (Goo.parse( $eg, :rule($top) ) ?? "OK " !! "Fail") | |
| ~ " $eg - $top"; | |
| } | |
| } | |
| =begin Desc | |
| The above contrived program prints: | |
| OK AA - ident | |
| OK )A - ident | |
| OK AA - qwert | |
| Fail )A - qwert | |
| Any of the following modifications allows all tests to pass: | |
| - Replace 'ident' with something else, like 'glorp'. | |
| - Remove the 'yuiop' alternation from <qwert>. | |
| - Replace the ')' prefix with something like 'x' (in both the rule | |
| and the sample data). | |
| In each case, what's going on? | |
| (It turns out I was unsuccessfully using an equally non-predefined | |
| 'ident' in a grammar I'm designing. It took me a couple of hours to | |
| golf it down to this hopefully useful example.) | |
| =end Desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment