At 4:35 pm 4/2/98, Simon Marlow wrote:
>[EMAIL PROTECTED] (Kevin Hammond) writes:
>
>> Isn't it rather that the report doesn't need to say this explicitly,
>> since it's covered by the general rule noted below (i.e., the
>> '(' below the case introduces a '}' and a ';', and the case is thus illegal
>> [or odd!] according to the report). The expanded parse is
>>
>> do { case a of {}; (Just x,_) -> return x; _ -> error "hey"; }
>
>I don't think this is right:
No, sorry, I meant it to illustrate how it could be parsed if case could
have 0 arms (a demonstration of how fragile this is!).
> do { case a of { ; (Just x, _) -> return x; ; _-> error "hey" }}
>
>with the extra semicolons being inserted due to the 'do' scope.
>
>There are two options: either
>
> a) only the inner scope can generate tokens, or
> b) a new scope must be more indented than the previous one
>
>obviously b) implies a). I implemented a) in the Happy Haskell Parser.
I don't see how (a) alone is consistent with the report. If a token appears
below a layout initiator, then a semicolon *must* be inserted to match the list
started by an initiator (unless layout processing is turned off by an
explicit '{'). This may involve closing inner scopes. That implies (b) surely?
>> >> f a
>> >> = do
>> >> if x then
>> >> y
>> >> else
>> >> z
>
>This seems useful, it could probably be implemented by suspending
>layout processing until the 'else' had been parsed.
Suspending isn't quite the right thing to do -- you wouldn't want to turn
off processing for columns to the left, could give odd results in some
strange error situations!!
(a, let f a = if x then f
g b else h)
I think the rule you're looking for is really quite specific:
don't insert ';' if the next token is 'else'
or possibly don't insert ';' in the same column as 'if'
unless a matching 'else' has been read
or even change grammer to if e [;] then e [;] else e
(which is what Gofer did, I think, maybe HUGS too?).
[Note that empty productions might cause problems, and what about
other syntactic constructs -- this is why this looked like
"tinkering" rather than design to me! There's also the issue
of how errors get reported -- the messages might be less
useful?]
Regards,
Kevin
----------
Division of Computer Science, Tel: +44-1334 463241 (Direct)
School of Mathematical Fax: +44-1334 463278
and Computational Sciences, URL:
http://www.dcs.st-and.ac.uk/~kh/kh.html
University of St. Andrews, Fife, KY16 9SS.