From 68e212d2b48044c0742fd492024d36f99d9b1c03 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 10 Feb 2004 12:10:08 +0000 Subject: [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. --- src/HaddockLex.x | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') 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 \_\.\!\#\$\%\&\*\+\/\<\=\>\?\@\\\\\^\|\-\~] { $ws* \> { begin birdtrack } $ws* \n { token TokPara `andBegin` para } + -- Here, we really want to be able to say + -- $ws* (\n | ) { 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 , + -- 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 -- cgit v1.2.3