Created
October 23, 2019 20:59
-
-
Save patrickt/3a38a957d40681f4a380473b798f736c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Separator = Dot | Quest | App | |
data Access t | |
= Access Separator (Access t) (Access t) | |
| Term (t Name) | |
| Base Name | |
desugar :: (Monad m, Carrier sig t, Member Core sig) => Access t -> m (t Name) | |
desugar t = case t of | |
Access Dot a b -> (Core....) <$> desugar a <*> ensureName b | |
Access Quest a b -> (Core..?) <$> desugar a <*> ensureName b | |
Access App a b -> (Core.$$) <$> desugar a <*> desugar b | |
Term t -> pure t | |
Base t -> pure . pure $ t | |
where | |
ensureName (Base t) = pure t | |
ensureName _other = fail ("Couldn't desugar access") | |
application :: (TokenParsing m, Carrier sig t, Member Core sig, Monad m) => m (t Name) | |
application = Expr.buildExpressionParser table term >>= desugar | |
where | |
table = [ [ Expr.Infix (Access Quest <$ symbol ".?") Expr.AssocLeft | |
, Expr.Infix (Access Dot <$ symbol ".") Expr.AssocLeft | |
] | |
, [ Expr.Infix (Access App <$ notFollowedBy dot) Expr.AssocLeft | |
] | |
] | |
term = choice [ Term <$> comp | |
, Term <$> lit | |
, Base <$> ident | |
, Term <$> parens expr | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment