Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Maybe ( fromJust )
- import Text.ParserCombinators.Parsec
- -- plain text. Let's say '/' is our token, this will parse
- + "fsfasd/dadc" -> "fsfasd/dadc"
- + "fsfasd / dadc" -> "fsfasd / dadc"
- + "fsfasd /dadc" -> "fsfasd"
- + "fsfasd/ dadc" -> "fsfasd"
- -- i.e. tokens "surrounded" by spaces or letters
- -- are innoquous.
- -- oh, tokenList is something like ['/','-',':']
- text :: Parser String
- text = many1 (noneOf tokenList) >>= \parText -> -- many1: we're sure it's text
- -- and not straight an inline
- -- we've met a token, should we continue ( " / " "cvdf/vdf" or not?)
- let lastChar = last parText in -- safe, since we've used many1
- -- so let's try a "continue text" stuff
- try ( oneOf tokenList >>= \token ->
- ( if lastChar == ' ' -- if last was a whitespace, expect ws
- then space -- if it was not, any char does
- else noneOf " "
- ) >>= \charAdd ->
- newTextParser >>= \newText ->
- return ( parText ++ [token, charAdd] ++ newText )
- )
- <|> return (parText)
- where newTextParser = try text
- <|> return ""
Add Comment
Please, Sign In to add comment