The Blocker
The Blocker is the first stage in the compilation pipeline. Functional programs are generally laid out in terms of simple statements with nested statements below them in "blocks".
Unlike other languages such as Miranda and Haskell, I decided to be very strict about this, in large part because it enables me to have many different syntaxes in the same file without having to worry too much about what the layout is.
The rules for blocking are basically fairly simple:
- The indentation is measured using a combination of tabs and spaces;
- Any line with no indentation is considered a comment;
- The first line must have exactly one tab;
- Any subsequent line must either have the same number of tabs, in which case it is in the same block; exactly one more tab, in which case it is the first statement in a nested block; if it has less tabs, it reverts to an outer block;
- Any line with the same number of tabs as the previous line but also with one or more spaces is a continuation line.
Once the Blocker has run, the output is a list of Block objects, each of which has exactly one ContinuedLine consisting of multiple SingleLine objects, and may have nested Block objects.