Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created February 12, 2013 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasberth/4761647 to your computer and use it in GitHub Desktop.
Save pasberth/4761647 to your computer and use it in GitHub Desktop.
正規表現でいうと /(A|B)*B/ みたいなケース
module Main where
import Control.Applicative hiding ((<|>))
import Text.ParserCombinators.Parsec
data Result = Init String Result
| Last String
deriving (Show)
a = string "a"
b = string "b"
f = try (Init <$> (a <|> b) <*> f)
<|> (Last <$> b)
main = print (parse f "test" "ababb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment