mirror of
https://github.com/GaloisInc/cryptol.git
synced 2024-11-24 15:08:58 +03:00
Fix up html syntax highlighting.
This commit is contained in:
parent
c666731495
commit
5c51d32a4e
@ -219,6 +219,12 @@ executable cryptol
|
||||
if os(linux) && flag(static)
|
||||
ld-options: -static -pthread
|
||||
|
||||
executable cryptol-html
|
||||
main-is: CryHtml.hs
|
||||
hs-source-dirs: utils
|
||||
build-depends: base, text, cryptol
|
||||
GHC-options: -Wall
|
||||
|
||||
-- Note: the Cryptol server needs to be updated to some new APIs.
|
||||
--executable cryptol-server
|
||||
-- main-is: Main.hs
|
||||
|
@ -391,7 +391,6 @@ data TokenKW = KW_else
|
||||
| KW_constraint
|
||||
deriving (Eq, Show, Generic, NFData)
|
||||
|
||||
-- | The named operators are a special case for parsing types, and 'Other' is
|
||||
-- | The named operators are a special case for parsing types, and 'Other' is
|
||||
-- used for all other cases that lexed as an operator.
|
||||
data TokenOp = Plus | Minus | Mul | Div | Exp | Mod
|
||||
|
@ -10,19 +10,27 @@
|
||||
|
||||
import Cryptol.Parser.Lexer
|
||||
import Cryptol.Utils.PP
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.IO as Text
|
||||
|
||||
main :: IO ()
|
||||
main = interact (wrap . concat . map toHTML . fst . primLexer defaultConfig)
|
||||
main =
|
||||
do txt <- Text.getContents
|
||||
putStrLn $ wrap
|
||||
$ concat
|
||||
$ map toHTML
|
||||
$ fst
|
||||
$ primLexer defaultConfig txt
|
||||
|
||||
wrap :: String -> String
|
||||
wrap txt = "<html><head>" ++ sty ++ "</head><body>" ++ txt ++ "</body>"
|
||||
|
||||
toHTML :: Located Token -> String
|
||||
toHTML tok = "<span class=\"" ++ cl ++ "\" title=\"" ++ pos ++ "\">"
|
||||
++ concatMap esc (tokenText (thing tok))
|
||||
++ concatMap esc (Text.unpack (tokenText (thing tok)))
|
||||
++ "</span>"
|
||||
where
|
||||
pos = show (pp (srcRange tok)) ++ " " ++ show (tokenType (thing tok))
|
||||
pos = show (pp (srcRange tok)) ++ " " ++ concatMap esc (show (tokenType (thing tok)))
|
||||
cl = case tokenType (thing tok) of
|
||||
Num {} -> "number"
|
||||
Ident {} -> "identifier"
|
||||
@ -42,6 +50,7 @@ toHTML tok = "<span class=\"" ++ cl ++ "\" title=\"" ++ pos ++ "\">"
|
||||
'>' -> ">"
|
||||
'&' -> "&"
|
||||
' ' -> " "
|
||||
'"' -> """
|
||||
'\n' -> "<br>"
|
||||
_ -> [c]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user