On Jan 4, 2007, at 2:03 AM, Simon Marlow wrote:
Andy Gill wrote:
LINE can already refer to an external non-.hs file. This is
exactly how
things works now with all manner of pre-processors, alex, happy,
cpphs,
c2hs, hsc2hs, etc.
I don't quite have an intuition for this yet, can you give an
example of
how this more fine grained pragma works and some use-case not
currently
covered by LINE?
Ahhh. LINE does? Oh.
- GENERATED works on an expression based level, and can specify
specific spans.
(20:4 - 21:8, for example).
often LINE can be used to do this - you just have to put the
expression on a line by itself.
GENERATED would seem to be useful if the preprocessor modifies the
column numbers, not just the line numbers, of Haskell code in the
original source text. Happy is careful not to do this: we retain
the indentation of the code inside { .. }, if I recall correctly
(or if not, we should :-).
- GENERATED is a true pragma; it hints where things come from,
but does not change
the error message. I want the Haskell source spans to remain
unchanges.
I don't get this - could you elaborate?
Andy - can you give us an idea of your use case for GENERATED?
Sure.
You have two files.
012345678901234567890123456789
Happy.y:
foo ::= foo bar { BarBaz $1 $2 }
Happy.hs: (generated file)
[stuff]
rhs dollar_1 dollar_2 = BarBaz dollar_1 dollar_2
[more stuff]
Now we still want any error messages in the BarBaz code fragment to
be in terms of the generated file,
and we still want to do coverage in terms of the generated file.
After all, it is a Haskell module.
However, if we change Happy to generate the following:
Happy.hs: (generated file)
[stuff]
rhs dollar_1 dollar_2 = {-# GENERATED "Happy.y" 1:15-1:25 #-} BarBaz
dollar_1 dollar_2
[more stuff]
Under the semantics for GENERATED, this makes no difference to the
generated code,
or any error messages (say BarBaz is a typo, for example). However,
Hpc can use the pragma,
and generate a coverage markup file for *both* Happy.hs (the real
Haskell) and Happy.y,
where the GENERATED code is tied back to its original location.
Note that this is different than LINE, because LINE changes what the
current span is for
the purposes of tagging the AST, and therefore error messages (and
code coverage).
After all, the GENERATED code is even of different length than the
original production code inside {}.
This is fine, because GENERATED says
- This expression was generated from source in another file
- Here is the the file name
- Here is the span inside this file
- The external span need not be the same size as the Haskell span
in the Haskell program
- The Haskell code needs to be an expression
Does this make sense?
The is not specifically for Happy; rather *any* code that generates
Haskell can use the Hpc
tools to get coverage (Alex, for example, or code generated from a
Isabelle specifications).
AndyG
If we do need this, then I suggest either {-# COL #-} for
specifying the source column number and/or {-# SPAN #-} for
specifying a span (which presumably specifies the span of the
following syntactic entity, which we'd have to define precisely).
Cheers,
Simon
_______________________________________________
Cvs-ghc mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-ghc