Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue translating megaparsec example #68

Open
locallycompact opened this issue Nov 26, 2018 · 0 comments
Open

Issue translating megaparsec example #68

locallycompact opened this issue Nov 26, 2018 · 0 comments

Comments

@locallycompact
Copy link

Hi, I'm trying to translate the last megaparsec example on this page.

http://akashagrawal.me/beginners-guide-to-megaparsec/

I ended up with this, which typechecks.

boldP : Parser (List Char)
boldP = do
  _ <- ntimes 2 (char '*')
  txt <- some (alphaNum <|> char ' ')
  _ <- ntimes 2 (char '*')
  pure $ unpack "<strong>" ++ txt ++ unpack "</strong>"

foo : Either String (List Char)
foo = parse boldP "**idris is cool**"

But it seems to fail to do anything.

Expression: foo = case case uncons "idris is cool**" of
       Nothing => ue [Err pos "a token, not EOF"] (ST i pos tw)
       Just (t, rest) => case f t of
                           Nothing => ue [Err pos "a different token"] (ST i pos tw)
                           Just res => case updatePos tw pos t of
                                         (newPos, b) => us res (ST rest newPos tw) of
  Id r => case r of
            MkReply _ (Success x) => Right x
            MkReply _ (Failure es) => Left (concat (intersperse "\n" (map display es))) : Either String (List Char)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant