So, I considered the comments (thank you, all), and thought I’d have another go at making the ending ‘dot’ optional.

I decided to introduce another token, ‘GAP’, to denote an empty line. Most likely, the scanner, in its current state, will not be able to handle empty lines with white space in them, etc, and the code is starting to look a bit confused. Oh well…

The first two rules are the original rules for indentation-insensitive code. The last two are for the indentation tokens. The ‘OUT’ token is for symmetry, to match the ‘IN’ token after the arrow in function_body. Remember that indentation tokens are normalized in the scanner.

5 Responses to “Indentation-sensitive Erlang 2”

The purpose of the test module is of course not to illustrate how beautiful it can be, but rather to verify that the parser does its job correctly, including parsing “old-style” functions, like test(). But I agree: I think that there is no loss of understanding – only less noise.

Peter – how about simply disallowing TABs in the indentation-sensitive scanner?

The way this hack works, you have to explicitly tell the compiler that the code is indentation-sensitive, at which point it switches to another token scanner.

The only indentation-sensitive language I’ve done any half-serious work in was FORTRAN, so I’m not crusading to get this introduced into Erlang – I’m mainly playing around because I was curious to see how it would work out.

Hi! I’ve been working through Pragmatic Erlang and it’s a very interesting language. One of the things I don’t like too much is the dots and semicolons and commas, thought. I’ve also programmed a little in Python because I’m learning Django, and I always heard that significant indentation was a bad idea, but I’ve found that it works surprisingly well. It reduces a lot of noise and typing, and it’s not at all confusing because the indentation is relative and it has no problem recognizing a TAB or a single space even in a single file.

So I was just wondering if Erlang could be made indentation sensitive. I’m happy to know that someone’s working on it!