[nem-en] indentation syntax ideas
Kamil Skalski
kamil.skalski at gmail.com
Sun Oct 30 22:04:54 CET 2005
Also, I forsee many problems with syntax extensions, for example
class Foo
public f (x : string) : void
requires !string.IsNullOrEmpty (x)
x.Substring (1)
will probably place ; after :void and the syntax extension won't get
parsed correctly.
We should invent something more general for avoiding ;
Maybe at top level we should ignore ; were we can, just like I
proposed for [Attr]
2005/10/28, Michal Moskal <michal.moskal at gmail.com>:
> 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/
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
--
Kamil Skalski
http://nazgul.omega.pl
More information about the devel-en
mailing list