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: Andreas Rossberg <rossberg@m...>
Subject: Re: [Caml-list] ocamllex and python-style indentation
On Jun 30, 2009, at 20.58 h, Yitzhak Mandelbaum wrote:
> To restart this thread, do your solutions handle the following  
> (legal) variation of the original example?
>
> if True:
>    x = 3+4
>    y = (2 +
> 4 + 5)
>    z = 5
> else:
>    x = 5
>    if False:
>        x = 8
>        z = 2
>
> Notice that the assignment of y wraps onto the next line at an  
> *earlier* column. This is legal b/c it is surrounded by parens.  
> However, it seems that the preprocessing approaches will fail for  
> this example. Do you have a workaround?

Handling that wouldn't be hard with the approach I described. You only  
need to have parentheses start a dummy block at column 0, so that no  
tokens will be inserted inside it .

However, I don't think it is actually a good idea to allow this. (And  
I don't think Haskell does, but I may misremember.)

On Jun 30, 2009, at 22.19 h, Mike Lin wrote:
> More generally, you've got parentheses, comments, and string literals,
> and you need to know to ignore whitespace within any of those -- and
> to ignore e.g. an open parenthesis that occurs within a comment, or a
> close comment that occurs within a string literal. So inevitably
> you've got to lex and parse at some level to make this work for a
> practical language.

Comments and string literals are no problem, since the lex wrapper  
will never see anything inside them as separate tokens anyway.

- Andreas