[nem-en] indentation syntax ideas

Michal Moskal michal.moskal at gmail.com
Fri Oct 28 11:02:20 CEST 2005


Hi,

I converted a moderatly small piece of Nemerle code to the indentation syntax
using an automated tool (well, a 5-line perl script). The code can be found
here:

  http://nemerle.org/svn/nemerle/trunk/snippets/the-game/

and the conversion script here:

  http://nemerle.org/svn/nemerle/trunk/misc/to-indentation-syntax.pl

Some notes about the indenation syntax are here:

  http://nemerle.org/Indentation-based_syntax

I would like to share my ideas how to improve this syntax.

Problems:

1. traditional code like
     class Foo
     {
       something
     }
   is not understood by the new syntax, because it adds ; after Foo
   (because the next token is at the same indentation level).

2. similarly for
     [SomeAttribute]
     class Something ...
   it adds ; after ].

3. there is a problem with matching:
     match (something)
       | p1 => ...
       | p2 => ...
   was not understood because the match lines begin with |, which is operator
   and are more indented, so it treats it like the code:
     def foo = bar
       && baz
       && qux
   that is doesn't add { }. I changed the rule to ignore |.

I'm not very happy with the exception for the indented-operator rule made
for |. Also it wouldn't handle:

  while (something)
    ++i
    foo ()

I guess it would even understand it in a wrong way:

  while (something) i++;

  {
    foo ()
  }

This doesn't seem any good. I would vote for removing the indented-operator
rule.

Also I guess the \ processing should be changed, that if it is proceeded
by the newline, the newline is ignored. This should be done at the
lexer level.

Now the syntax is activated by the -i switch. Maybe it would be good
to provide something like #pragma indent or #indent to activate it
on file-by-file basis (that is no mixture of syntaxes within a file,
just when the traditional lexer sees #indent, it aborts and creates a
new indentaion lexer for this file).

I'm not sure how to handle 1. Probably if the next line begins with {,
don't add { nor ;.

--
   Michal Moskal,
   http://nemerle.org/~malekith/



More information about the devel-en mailing list