Skip to content

Instantly share code, notes, and snippets.

@paolino
Last active September 13, 2020 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paolino/ddd9774e4ada24ace2512e74e6113ced to your computer and use it in GitHub Desktop.
Save paolino/ddd9774e4ada24ace2512e74e6113ced to your computer and use it in GitHub Desktop.
extract an enclosed subtext with attoparsec
import Control.Applicative ((<|>))
import Data.Attoparsec.Text hiding (match)
import Data.Text (Text)
atto :: Text -> Text -> Text -> Either String [Char]
atto x y = parseOnly $ untilWord x >> untilWord y
untilWord :: Text -> Parser [Char]
untilWord x = mempty <$ string x <|> (:) <$> anyChar <*> untilWord
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment