Skip to content

Instantly share code, notes, and snippets.

@aiya000
Created June 2, 2020 12:20
Show Gist options
  • Save aiya000/471ca6a06e9c982324afad9d98888f7f to your computer and use it in GitHub Desktop.
Save aiya000/471ca6a06e9c982324afad9d98888f7f to your computer and use it in GitHub Desktop.
{
module Main where
}
%error { parseError }
%errorhandlertype explist
%monad { Either String }
%name parseFoo
%tokentype { Char }
%token
char { $$ }
%%
Foo :: { String }
: char {% Left "error" }
| char { "good" }
{
parseError :: ([Char], [String]) -> Either String a
parseError (got, expected) = Left $ show got <> ", " <> show expected
main :: IO ()
main = print $ parseFoo "x"
-- unused rules: 1
-- reduce/reduce conflicts: 1
-- Right "good"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment