One of our students just pointed out an IMHO rather
problematic clause in the layout rule.  In Section 2.7 of
the Haskell 98 Report it says,

  A close brace is also inserted whenever the syntactic
  category containing the layout list ends; that is, if an
  illegal lexeme is encountered at a point where a close
  brace would be legal, a close brace is inserted.

And in B.3, we have in the first equation of the definition
of `L',

  L (t:ts) (m:ms) = } : (L (t:ts) ms)   if parse-error(t)  (Note 1)

where Note 1 says,

  The side condition parse-error(t) is to be interpreted as
  follows: if the tokens generated so far by L together with
  the next token t represent an invalid prefix of the
  Haskell grammar, and the tokens generated so far by L
  followed by the token } represent a valid prefix of the
  Haskell grammar, then parse-error(t) is true.

What kind of implementation did the originators of this
clause envision?  If the layout rule is really implemented
as a filter between the scanner and the parser, it seems
extremely awkward to add a dependency on the error condition
of the parser - in particular, it makes a functional, ie,
side-effect free implementation rather hard and a true two
phase implementation impossible.  So, I guess (I hope!!) 
there is a nifty trick that lets you achieve the same effect
by using only conditions depending on local information
(either during layout processing or by letting the parser
insert the missing braces).

Cheers,

Manuel


Reply via email to