From 70e996b9a6cd657d441cba95014304a588c0fd7c Mon Sep 17 00:00:00 2001 From: David Waern Date: Mon, 12 Nov 2007 02:38:56 +0000 Subject: [PATCH] Merge from Haddock: Modify lexing of /../ Tue Aug 28 11:19:54 CEST 2007 Simon Marlow * Modify lexing of /../ This makes /../ more like '..', so that a single / on a line doesn't trigger a parse error. This should reduce the causes of accidental parse errors in Haddock comments; apparently stray / characters are a common source of failures. Please merge this to the 6.8.2 branch. --- compiler/parser/HaddockLex.hs-boot | 1 + compiler/parser/HaddockLex.x | 10 ++++++---- compiler/parser/HaddockParse.y | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/parser/HaddockLex.hs-boot b/compiler/parser/HaddockLex.hs-boot index abfc2d6..3144744 100644 --- a/compiler/parser/HaddockLex.hs-boot +++ b/compiler/parser/HaddockLex.hs-boot @@ -14,5 +14,6 @@ data Token | TokIdent [RdrName] | TokString String | TokURL String + | TokEmphasis String | TokAName String | TokBirdTrack String diff --git a/compiler/parser/HaddockLex.x b/compiler/parser/HaddockLex.x index f395976..acc04d6 100644 --- a/compiler/parser/HaddockLex.x +++ b/compiler/parser/HaddockLex.x @@ -34,7 +34,7 @@ import System.IO.Unsafe $ws = $white # \n $digit = [0-9] $hexdigit = [0-9a-fA-F] -$special = [\"\@\/] +$special = [\"\@] $alphanum = [A-Za-z0-9] $ident = [$alphanum \'\_\.\!\#\$\%\&\*\+\/\<\=\>\?\@\\\\\^\|\-\~] @@ -69,15 +69,16 @@ $ident = [$alphanum \'\_\.\!\#\$\%\&\*\+\/\<\=\>\?\@\\\\\^\|\-\~] $special { strtoken $ \s -> TokSpecial (head s) } \<.*\> { strtoken $ \s -> TokURL (init (tail s)) } \#.*\# { strtoken $ \s -> TokAName (init (tail s)) } + \/ [^\/]* \/ { strtoken $ \s -> TokEmphasis (init (tail s)) } [\'\`] $ident+ [\'\`] { ident } \\ . { strtoken (TokString . tail) } "&#" $digit+ \; { strtoken $ \s -> TokString [chr (read (init (drop 2 s)))] } "&#" [xX] $hexdigit+ \; { strtoken $ \s -> case readHex (init (drop 3 s)) of [(n,_)] -> TokString [chr n] } -- allow special characters through if they don't fit one of the previous -- patterns. - [\'\`\<\#\&\\] { strtoken TokString } - [^ $special \< \# \n \'\` \& \\ \]]* \n { strtoken TokString `andBegin` line } - [^ $special \< \# \n \'\` \& \\ \]]+ { strtoken TokString } + [\/\'\`\<\#\&\\] { strtoken TokString } + [^ $special \/ \< \# \n \'\` \& \\ \]]* \n { strtoken TokString `andBegin` line } + [^ $special \/ \< \# \n \'\` \& \\ \]]+ { strtoken TokString } } { @@ -101,6 +102,7 @@ data Token | TokIdent [RdrName] | TokString String | TokURL String + | TokEmphasis String | TokAName String | TokBirdTrack String -- deriving Show diff --git a/compiler/parser/HaddockParse.y b/compiler/parser/HaddockParse.y index ded4dbe..d591957 100644 --- a/compiler/parser/HaddockParse.y +++ b/compiler/parser/HaddockParse.y @@ -22,6 +22,7 @@ import RdrName DQUO { TokSpecial '\"' } URL { TokURL $$ } ANAME { TokAName $$ } + '/../' { TokEmphasis $$ } '-' { TokBullet } '(n)' { TokNumber } '>..' { TokBirdTrack $$ } @@ -80,7 +81,7 @@ seq1 :: { HsDoc RdrName } elem1 :: { HsDoc RdrName } : STRING { DocString $1 } - | '/' strings '/' { DocEmphasis (DocString $2) } + | '/../' { DocEmphasis (DocString $1) } | URL { DocURL $1 } | ANAME { DocAName $1 } | IDENT { DocIdentifier $1 } -- 1.7.10.4