Attieh Sadeghi Givi. Layout Sensitive Parsing in Petit Parser Framework. Bachelor’s thesis, University of Bern, October 2012. Details.
Most parser frameworks can parse a context-free language generated by different context-free grammars. However, many languages are not context-free. One important class of such languages is layout-sensitive languages (eg Python, Haskell), in which the structure of code depends on indentation and whitespace. The parsers (and lexers) of this kind of languages are not declaratively specified but hand-tuned to account for layout-sensitivity. To support parsing of layout-sensitive languages, we propose an extension of parsing expression grammars in which a user is able to declare layout-sensitive specifications. For example, a user can declare a consisting block of statements to be aligned and arbitrary positioned. We have implemented our extension in a Petit Parser framework. We evaluate the correctness and performance of our parser by parsing Python- and Haskell-like grammars.