Yeah I was on an LSD trip and I saw Lisp without its syntax on
Name:
Anonymous2007-08-18 4:35 ID:3qA4A9y2
[spoiler][code]module Language.BBCode.Parser
(BBCode(..),
-- A fast monadic BBCode parser utilizing the industrial
-- strength combinator library Parsec.
parseBBCode)
where
import Text.ParserCombinators.Parsec
-- Belongs in another module.
data BBCode = Element String [BBCode]
| Text String
-- An optimizing BBCode rendering machine.
-- Belongs in another module.
render (Element e []) = ""
render (Element e bs) = "[" ++ e ++ "]" ++
(concatMap render bs) ++
"[/" ++ e ++ "]"
render (Text s) = s
bbcode = many (bbcodeElement <|> bbcodeText)
bbcodeElement = do element <- try bbcodeOpenElement
content <- bbcode
bbcodeCloseElement element
return (Element element content)
bbcodeOpenElement = do char '['
s <- many1 letter
char ']'
return s
bbcodeCloseElement s = string ("[/" ++ s ++ "]")
bbcodeText = many1 (noneOf "[") >>= return . Text
parseBBCode bb = case parse bbcode "" bb of
Left e -> error $ show e
Right bs -> bs
-- A simple test case.
testbb = "[b][u][o]EXPERT PROGRAMMER[/o][/u][/b] " ++
"[spoiler][i]Read SICP![/i][/spoiler]"
test = do putStrLn testbb
putStrLn $ concatMap render $ parseBBCode testbb[/code][/spoiler]