sighingnow/parsec.py

Stateful parser

thebabush opened this issue · 2 comments

Let's say I would like to implement something like python-style indentation-based nesting.
I would need to keep track of the current indentation level. Is there a simple way to do it in parsec.py?

I think add an class attribute to Parser and corresponding getter/setter/mapper would be enough for your problem.

I will push a patch for this feature (as well as examples) later.

Thanks for the answer. For the time being, I'm doing like:

def parse_block(indent):
    @generate
    def pb():
        whatever(indent)
    return pb

Btw, thank you very much for the project. I like Parsec and being able to do something similar in python is pretty cool.