Version française
Home     About     Download     Resources     Contact us    
Browse thread
ocamllex and python-style indentation
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrej Bauer <andrej.bauer@a...>
Subject: Re: [Caml-list] ocamllex and python-style indentation
Thanks to Andreas, I'll have a look at the "old" code.

I think I understand the general idea of inserting "virtual" tokens,
but the details confuse me still. So starting with

> if True:
>     x = 3
>     y = (2 +
>       4 + 5)
> else:
>     x = 5
>     if False:
>         x = 8
>         z = 2

Martin suggests the following:

> {
> if True:
> ;
>    {
>    x = 3
>    ;
>    y = (2 +
>    ;
>      {
>      4 + 5)
>      }
>    }
> ;
> else:
> ;
>    {
>    x = 5
>    ;
>    if False:
>    ;
>        {
>        x = 8
>        ;
>        z = 2
>        }
>    }
> }

I have two questions. Notice that the { ... } and ( ... ) need not be
correctly nested (in the top half), so how are we going to deal with
this? The second question is, why are there the separators after and
just before "else:". I would expect separators inside { .... }, but
not around "else".

Presumably the intermediate stage that I would preprocess the token
stream would have to know about indentation levels. I have not tried
this, but ocaml lexer will correctly match things like

| '\n' [' ' '\t']* -> { INDENTATION (compute_indentation (lexeme buf)) }

Yes?

With kind regards,

Andrej