Maintaining State in Perl 6 Grammars?

I've been curious how one would match the following with Perl 6 grammars/regexen (spaces represented by dots)?

    XXXX
    ..XXXX
    ....XXXX
    ....XXXX
    ......XXXX
    ..XXXX

In short, you can indent or unindent by a particular amount, with allowed indentation levels being multiples of the first indentation amount found. Each level of indentation must equal the previous or be one greater. You can unindent as much as you want so long as it's a multiple of that first indentation level. Seems like you need to have a recursive grammar that allows you to maintain state.

This is to play with the idea of matching a "YAMLish" document.

Side note: since Perl 6 is "Perl 6" and not "Perl6", it's awfully hard to search Google for.

1 Comment

I think it's technically "Perl 6", though I doubt this will help with google.

Leave a comment

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/