[Haskell-cafe] WANTED: grey line layout boxes in vim and emacs

John Meacham john at repetae.net
Wed Dec 6 21:07:28 EST 2006

On Wed, Dec 06, 2006 at 05:37:01PM -0800, Carl Witty wrote:
> On Wed, 2006-12-06 at 16:56 -0800, John Meacham wrote:
> > Having played with haskell parsers for various reasons, the layout rule
> > is quite tricky due to the rules involving 'parse-error'. if we could
> > come up with a formulation that didn't have those. it would make things
> > a whole lot nicer. something like an unexpected 'in', 'of', ')' '}'
> > ']' might  do it. the lexer would have to keep track of matching
> > brackets.. hmmm..
> Yes, not having the parser->lexer feedback would be great!  And this
> proposal seems like it should work quite well.  Somebody with a lot more
> spare time than me should code it up and see how much real code it
> breaks.

there is the helium layout rule:


which is similar to what I am thinking of but only has a special case
for 'in'.

my general thought is to take the layout rule algorithm from the haskell
report, and add some more possibiliies to the 'layout stack'.

so, right now it is 

layout :: [Token] -> [Int] -> [Token]

where the first argument is the token stream, the next argument is a
stack of layout contexts, and the result is the new token stream.

now we change it to something like (in semi-psuedo haskell)

data LContext = LExpects Token | LLevel Int

expectableTokens = ['of','in',')','}',']']

and change the signature to 

layout :: [Token] -> [LContext] -> [Token]
layout = ...

now, LLevel nodes will be pushed just like the old algorihm, but
whenever a 'case' for instance is encountered, a "LExpects 'of'" node
will be pushed.

now, whenever we get something in expectableTokens, an 'of' say, either
the top of the stack is a LExpects 'of', in which case we pop it add the
'of' to the output stream and continue, or it is a 'LLevel' in which
case we insert a '}' then pop the LLevel and continue (with the 'of'
still in the input stream)

I think something like this could work.

the only odd bits I can think of are handling 'let's without 'in's as
occur in 'do' blocks, and the comma, but I think we can integrate them

does something like this seem like it will work?


John Meacham - ⑆repetae.net⑆john⑈

More information about the Haskell-Cafe mailing list