Copyright © 2007 Dave Bayer. Subject to a BSD-style license.
This module is part of the Annote project.
module Haskell (doHaskell) where
Haskell
provides a language-specific filter for the language
Haskell.
Regex
provides regular expression matching.
It is a wrapper around Text.Regex.
import Regex (mkRegex,matchRegex,Sub,mkSub,doSub)
Split
divides an input file into code, documentation, and external documentation.
import Split (Split(..))
Filter
processes the Code and Doc lines of split input text.
import Filter (Filt,DocSubs,filterLine,docSubs,process)
notSymbol is a pattern matching any character that cannot be used
to form a Haskell operator symbol.
notSymbol :: String notSymbol = "[^-!#$%&*+./<=>?@\\^|~]"
isolated matches the string s if it is not part of a longer
Haskell operator symbol.
isolated :: String → String isolated s = "(^|" ++ notSymbol ++ ")" ++ s ++ "($|" ++ notSymbol ++ ")"
codeSubs is a mapping of regular expression substitutions to apply to
Haskell source code. We rewrite
=>, <=, ->, <- arrows.
codeSubs :: [Sub]
codeSubs = map mkSub
[ (isolated "⇒", "\\1⇒\\2")
, (isolated "⇐", "\\1⇐\\2")
, (isolated "→", "\\1→\\2")
, (isolated "←", "\\1←\\2")
]
libraries is the location of GHC Haskell web pages documenting
libraries.
libraries :: String libraries = "http://www.haskell.org/ghc/docs/latest/html/libraries/"
haskellDocSubs is a mapping of regular expression substitutions
to apply to Haskell documentation.
haskellDocSubs :: DocSubs
haskellDocSubs =
[ ("lib", "([^` \t]+)[ \t]+`([^` \t]+)`",
"[`\\3`](" ++ libraries ++ "\\2/\\3.html \"\\3\")")
]
undotURL converts . to - in the name of a Haskell
standard library module.
undotURL :: String → String
undotURL line =
let regex = mkRegex $ "(^.*" ++ libraries ++ ")(.*)(.html .*$)"
sub = mkSub ("\\.", "-")
in case matchRegex regex line of
Just [x,y,z] → x ++ (doSub y sub) ++ z
_ → line
codeFilter, docFilter specialize filterLine to code and
documentation, using codeSubs and docSubs respectively.
For documentation, we also apply undotURL to clean up library module
references.
codeFilter, docFilter :: Filt codeFilter = filterLine codeSubs docFilter = undotURL . (filterLine $ docSubs haskellDocSubs)
doHaskell is the exported function for this module.
It provides a language-specific filter for the language
Haskell.
doHaskell :: [Split] → [Split] doHaskell = process codeFilter docFilter