aboutsummaryrefslogtreecommitdiff
path: root/src/HaddockLex.x
diff options
context:
space:
mode:
authorsimonmar <unknown>2004-02-10 12:10:08 +0000
committersimonmar <unknown>2004-02-10 12:10:08 +0000
commit68e212d2b48044c0742fd492024d36f99d9b1c03 (patch)
treee9bd13c81a4179b4cafed2603e0e50a58fb0bac4 /src/HaddockLex.x
parentf4e7edcbc2fc5742ebbc8823f5429508cc975e37 (diff)
[haddock @ 2004-02-10 12:10:08 by simonmar]
Fix for previous commit: I now realise why the whitespace was stripped from the beginning of the line. Work around it.
Diffstat (limited to 'src/HaddockLex.x')
-rw-r--r--src/HaddockLex.x12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/HaddockLex.x b/src/HaddockLex.x
index dbd3dc21..c521046f 100644
--- a/src/HaddockLex.x
+++ b/src/HaddockLex.x
@@ -39,6 +39,12 @@ $ident = [$alphanum \_\.\!\#\$\%\&\*\+\/\<\=\>\?\@\\\\\^\|\-\~]
<line> {
$ws* \> { begin birdtrack }
$ws* \n { token TokPara `andBegin` para }
+ -- Here, we really want to be able to say
+ -- $ws* (\n | <eof>) { token TokPara `andBegin` para}
+ -- because otherwise a trailing line of whitespace will result in
+ -- a spurious TokString at the end of a docstring. We don't have <eof>,
+ -- though (NOW I realise what it was for :-). To get around this, we always
+ -- append \n to the end of a docstring.
() { begin string }
}
@@ -96,7 +102,7 @@ alexGetChar (_, c:cs) = Just (c, (c,cs))
alexInputPrevChar (c,_) = c
tokenise :: String -> [Token]
-tokenise str = let toks = go ('\n',str) para in {-trace (show toks)-} toks
+tokenise str = let toks = go ('\n', eofHack str) para in {-trace (show toks)-} toks
where go inp@(_,str) sc =
case alexScan inp sc of
AlexEOF -> []
@@ -104,6 +110,10 @@ tokenise str = let toks = go ('\n',str) para in {-trace (show toks)-} toks
AlexSkip inp' len -> go inp' sc
AlexToken inp' len act -> act (take len str) sc (\sc -> go inp' sc)
+-- NB. we add a final \n to the string, (see comment in the beginning of line
+-- production above).
+eofHack str = str++"\n"
+
andBegin :: Action -> StartCode -> Action
andBegin act new_sc = \str sc cont -> act str new_sc cont