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 Have Perl; Will Travel. Freelance Perl/Testing/Agile consultant. Photo by http://www.circle23.com/. Warning: that site is not safe for work. The photographer is a good friend of mine, though, and it's appropriate to credit his work.