Manual:Line-Aware Parsing and the Offside Rule:Offside Rule and Blocks

まんま

>>> from lepl import *
>>> introduce = ~Token(':')
>>> word = Token(Word(Lower()))
>>> statement = Delayed()
>>> simple = BLine(word[:])
>>> empty = Line(Empty())
>>> block = BLine(word[:] & introduce) & Block(statement[:])
>>> statement += (simple | empty | block) > list
>>> parser = statement[:].string_parser(LineAwareConfiguration(block_policy=2))
>>> parser('''
... abc def
... ghijk:
...   mno pqr:
...     stu
...   vwx yz
... '''
... )
[[], ['abc', 'def'], ['ghijk', ['mno', 'pqr', ['stu']], ['vwx', 'yz']]]

また、マニュアルでは最後の「)」が抜けていた