aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/HaddockLex.hs14
-rw-r--r--src/HaddockParse.y4
2 files changed, 15 insertions, 3 deletions
diff --git a/src/HaddockLex.hs b/src/HaddockLex.hs
index f766222d..f1646453 100644
--- a/src/HaddockLex.hs
+++ b/src/HaddockLex.hs
@@ -11,7 +11,7 @@ module HaddockLex (
import Char
-special = '`' : '\'' : '\"' : '@' : '/' : []
+special = '`' : '\'' : '\"' : '@' : []
data Token
= TokPara
@@ -19,6 +19,7 @@ data Token
| TokBullet
| TokSpecial Char
| TokString String
+ | TokEmph String
| TokURL String
| TokBirdTrack
deriving Show
@@ -33,6 +34,7 @@ tokenise "" = []
tokenise str = case str of
'<':cs -> tokenise_url cs
'\n':cs -> tokenise_newline tokenise cs
+ '/':cs -> tokenise_emph tokenise cs
c:cs | c `elem` special -> TokSpecial c : tokenise cs
_other -> tokenise_string "" str
@@ -42,6 +44,12 @@ tokenise_newline next cs =
'>':cs -> TokBirdTrack : next cs -- bird track
_other -> tokenise_string "" cs
+tokenise_emph next cs =
+ case break newlineSlash cs of
+ (bef, aft@('\n':cs)) -> TokString ('/':bef) : next aft -- paragraph break
+ (bef, '/':cs) -> TokEmph bef : next cs
+ _other -> tokenise_string "" cs
+
tokenise_para cs =
case dropWhile nonNewlineSpace cs of
-- bullet: '*'
@@ -60,6 +68,8 @@ tokenise_para cs =
nonNewlineSpace c = isSpace c && c /= '\n'
+newlineSlash c = c == '\n' || c == '/'
+
-- ----------------------------------------------------------------------------
-- Within a paragraph, we don't throw away any whitespace (except before a
-- birdtrack, and before a paragraph break).
@@ -69,6 +79,7 @@ tokenise1 "" = []
tokenise1 str = case str of
'<':cs -> tokenise_url cs
'\n':cs -> tokenise_newline1 cs
+ '/':cs -> tokenise_emph tokenise1 cs
c:cs | c `elem` special -> TokSpecial c : tokenise1 cs
_other -> tokenise_string "" str
@@ -93,6 +104,7 @@ tokenise_string str cs =
'\\':c:cs -> tokenise_string (c:str) cs
'\n':cs -> tokenise_string_newline str cs
'<':cs -> TokString (reverse str) : tokenise_url cs
+ '/':cs -> TokString (reverse str) : tokenise_emph (tokenise_string "") cs
c:cs | c `elem` special -> TokString (reverse str) : tokenise1 (c:cs)
| otherwise -> tokenise_string (c:str) cs
diff --git a/src/HaddockParse.y b/src/HaddockParse.y
index f74d2b69..17fbf2f4 100644
--- a/src/HaddockParse.y
+++ b/src/HaddockParse.y
@@ -12,13 +12,13 @@ import HsParseMonad
%token SQUO { TokSpecial '\'' }
BQUO { TokSpecial '`' }
DQUO { TokSpecial '\"' }
- '/' { TokSpecial '/' }
'@' { TokSpecial '@' }
URL { TokURL $$ }
'*' { TokBullet }
'(n)' { TokNumber }
'>' { TokBirdTrack }
PARA { TokPara }
+ EMPH { TokEmph $$ }
STRING { TokString $$ }
%monad { Either String }
@@ -67,7 +67,7 @@ seq1 :: { Doc }
elem1 :: { Doc }
: STRING { DocString $1 }
- | '/' STRING '/' { DocEmphasis (DocString $2) }
+ | EMPH { DocEmphasis (DocString $1) }
| URL { DocURL $1 }
| squo STRING squo { strToHsQNames $2 }
| DQUO STRING DQUO { DocModule $2 }