[Haskell-cafe] Re: ANNOUNCE: haskell-src-exts 0.4.4

Niklas Broberg niklas.broberg at gmail.com
Tue Dec 9 19:46:32 EST 2008


>> Apart from this, HSE now also parses any unrecognized pragma in option
>> (e.g. LANGUAGE), declaration (e.g. RULES) or expression (e.g. SCC)
>> position, allowing user-customized pragmas. Unrecognized pragmas in
>> other positions will (unfortunately) give a parse error. If this ever
>> means a problem for you - let me know!
>
> This is likely to be a problem for me :-)
>
> I certainly have OPTIONS_DERIVE and CATCH pragmas that I've inserted
> into various programs over time.

Are you sure that would be a problem? Seems to me that OPTIONS_DERIVE
would appear in the same position as any other OPTIONS pragma, in
which case HSE will handle it just fine. I don't know where CATCH
would appear, but intuitively it sounds like something that would
appear as an expression (or statement which is really just an
expression), in which case HSE will handle it too.
It's only pragmas appearing in "surprising" locations that would cause
HSE to balk.

> I think failing on an unrecognised
> pragma is probably a bad idea, when ignoring a pragma is usually
> perfectly safe.

Well, I have a dilemma here. To ignore a pragma, I need to ignore it
at the lexer stage, since once I've passed a lexed token to the parser
it needs to be handled in some way, or a parse error ensues. It's not
hard to have a set of recognized pragmas that pass the lexer stage,
and discard any others as comments. However, I am not fully satisfied
with this approach, the reason being that I've had feature requests
for HSE to allow for custom, user-defined pragmas. I can't ignore
unrecognized pragmas *and* allow custom pragmas. The safe way is
obviously to be conservative, but it is also the way that gives the
users the least power over pragmas.

There is also the option to lex all pragmas, and then pollute the
parser so that every primitive could be an unrecognized pragma
followed by the actual primitive. That would make it safe in all
instances, and user-custom pragmas could be allowed in predefined
positions, and discarded by the parser in others. But the cost would
be quite high in terms of parser complexity.

I could potentially also add the possibility for unknown pragmas to
appear in all other positions too - types, patterns etc. But that too
would be quite a lot of extra machinery for something that would most
likely be used very rarely at best.

I'm torn and welcome all input on this matter.

Cheers,

/Niklas


More information about the Haskell-Cafe mailing list