Skip to content

Commit

Permalink
few more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Feb 25, 2020
1 parent 7606f48 commit c10eb9e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Cabal/Distribution/FieldGrammar/Described.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ reOptCommaList = REOptCommaList
reHsString :: Regex a
reHsString = RENamed "hs-string" impl where
impl = reChar '"' <> REMunch reEps (REUnion [strChar, escChar]) <> reChar '"'
strChar = RECharSet $ CS.intersection CS.universe (CS.fromList "\"\\")
strChar = RECharSet $ CS.difference CS.universe (CS.fromList "\"\\")

escChar = REUnion
[ "\\&"
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/Types/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ instance Described Dependency where
, REAppend
[ reChar '{'
, RESpaces
, REMunch reSpacedComma reUnqualComponent
, RECommaList reUnqualComponent
, RESpaces
, reChar '}'
]
Expand Down
19 changes: 11 additions & 8 deletions Cabal/Distribution/Utils/Regex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ regexDoc = go 0 . vacuous where
go :: Int -> Regex PP.Doc -> PP.Doc
go _ (REAppend []) = ""
go d (REAppend rs) = parensIf (d > 2) $ PP.hcat (map (go 2) rs)
go d (REUnion rs) = parensIf (d > 1) $
if length rs < 4
then PP.hcat (PP.punctuate (PP.text "\\mid") (map (go 1) rs))
else "\\bigcup \\left\\{\\begin{gathered}" <<>>
PP.hcat (PP.punctuate "\\\\" (map (go 0) rs)) <<>>
"\\end{gathered}\\right\\}"
go d (REUnion [r]) = go d r
go _ (REUnion rs) = PP.hsep
[ "\\left\\{"
, if length rs < 4
then PP.hcat (PP.punctuate (PP.text "\\mid") (map (go 0) rs))
else "\\begin{gathered}" <<>>
PP.hcat (PP.punctuate "\\\\" (map (go 0) rs)) <<>>
"\\end{gathered}"
, "\\right\\}" ]

go d (REMunch sep r) = parensIf (d > 3) $
PP.text "{" <<>> go 4 r <<>> PP.text "}^\\ast_{" <<>> go 4 sep <<>> PP.text "}"
Expand All @@ -142,9 +145,9 @@ regexDoc = go 0 . vacuous where
go _ RESpaces1 = "\\bullet"

go _ (RECommaList r) =
"\\mathrm{commalist}\\left(" <<>> go 0 r <<>> "\\right)"
"\\mathrm{commalist}" <<>> go 4 r
go _ (REOptCommaList r) =
"\\mathrm{optcommalist}\\left(" <<>> go 0 r <<>> "\\right)"
"\\mathrm{optcommalist}" <<>> go 4 r

go _ (REVar a) = a
go _ (RENamed n _) = terminalDoc n
Expand Down
Loading

0 comments on commit c10eb9e

Please sign in to comment.