tldr-0.9.2: Haskell tldr client
Safe HaskellSafe-Inferred
LanguageHaskell2010

Tldr.Parser

Synopsis

Documentation

>>> :set -XOverloadedStrings
>>> import Data.Attoparsec.Text

codeParser :: Parser [Either Text Text] Source #

Parses '{{foo}}' blocks in CommonMark Code, such that:

  • `ls {{foo}} bar` -> `[Left "ls ", Right "foo", Left " bar"]`
>>> parseOnly codeParser ""
Right []
>>> parseOnly codeParser "tar"
Right [Left "tar"]
>>> parseOnly codeParser "tar{"
Right [Left "tar{"]
>>> parseOnly codeParser "tar{{"
Right [Left "tar{{"]
>>> parseOnly codeParser "tar{{{"
Right [Left "tar{{{"]
>>> parseOnly codeParser "tar}"
Right [Left "tar}"]
>>> parseOnly codeParser "tar{{{b}"
Right [Left "tar{{{b}"]
>>> parseOnly codeParser "tar{{{b}}"
Right [Left "tar",Right "{b"]
>>> parseOnly codeParser "tar{{b}}}"
Right [Left "tar",Right "b}"]
>>> parseOnly codeParser "tar xf {{source.tar[.gz|.bz2|.xz]}} --directory={{directory}}"
Right [Left "tar xf ",Right "source.tar[.gz|.bz2|.xz]",Left " --directory=",Right "directory"]

collectEither :: (Eq a, Eq b, Monoid a, Monoid b) => [Either a b] -> [Either a b] Source #

Collect both Lefts and Rights, mappending them to zore or one item per connected sublist.

>>> collectEither []
[]
>>> collectEither [Right "abc", Right "def", Left "x", Left "z", Right "end"]
[Right "abcdef",Left "xz",Right "end"]
>>> collectEither [Right "", Right "def", Left "x", Left "", Right ""]
[Right "def",Left "x"]

peek2Chars :: Parser (Maybe Char, Maybe Char) Source #

Peek 2 characters, not consuming any input.