1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-06 06:53:33 +03:00

[scoper] simplify infix parser

This commit is contained in:
Jan Mas Rovira 2022-01-21 15:53:55 +01:00
parent f597f652e5
commit 4155898883
3 changed files with 11 additions and 23 deletions

View File

@ -488,7 +488,7 @@ data ExpressionAtom (s :: Stage)
| AtomFunction (Function s)
| AtomFunArrow
| AtomMatch (Match s)
| AtomParens (ExpressionAtoms s)
| AtomParens (ExpressionType s)
deriving stock instance
( Show (ExpressionType s),

View File

@ -10,7 +10,7 @@ import MiniJuvix.Syntax.Concrete.Base (MonadParsec)
import qualified MiniJuvix.Syntax.Concrete.Base as P
import MiniJuvix.Syntax.Concrete.Language
import MiniJuvix.Syntax.Concrete.Lexer hiding (symbol)
import MiniJuvix.Utils.Prelude hiding (universe)
import MiniJuvix.Utils.Prelude
--------------------------------------------------------------------------------
-- Running the parser

View File

@ -819,7 +819,7 @@ checkExpressionAtom e = case e of
AtomLetBlock letBlock -> AtomLetBlock <$> checkLetBlock letBlock
AtomUniverse uni -> return (AtomUniverse uni)
AtomFunction fun -> AtomFunction <$> checkFunction fun
AtomParens par -> AtomParens <$> checkExpressionAtoms par
AtomParens par -> AtomParens <$> checkParseExpressionAtoms par
AtomFunArrow -> return AtomFunArrow
AtomMatch match -> AtomMatch <$> checkMatch match
@ -1006,20 +1006,14 @@ mkExpressionParser ::
mkExpressionParser table = embed @Parse pExpression
where
pExpression :: Parse Expression
pExpression = P.makeExprParser pTerm table
pTerm :: Parse Expression
pTerm = runM parseTermRec
where
parseTermRec :: Sem '[Embed Parse] Expression
parseTermRec = runReader pExpression parseTerm
pExpression = P.makeExprParser (runM parseTerm) table
parseTerm :: forall r. Members '[Reader (Parse Expression), Embed Parse] r => Sem r Expression
parseTerm = do
pExpr <- ask
parseTerm :: forall r. Members '[Embed Parse] r => Sem r Expression
parseTerm =
embed @Parse $
parseUniverse
<|> parseNoInfixIdentifier
<|> parseParens pExpr
<|> parseParens
<|> parseFunction
<|> parseLambda
<|> parseMatch
@ -1074,18 +1068,12 @@ parseTerm = do
| not (S.hasFixity n) -> Just n
_ -> Nothing
parseParens :: Parse Expression -> Parse Expression
parseParens expressionParer = do
exprs <- P.token parenExpr mempty
case P.parse expressionParer strPath exprs of
Right r -> return r
Left {} -> P.failure Nothing mempty
parseParens :: Parse Expression
parseParens = P.token parenExpr mempty
where
strPath :: FilePath
strPath = "inner parens"
parenExpr :: ExpressionAtom 'Scoped -> Maybe [ExpressionAtom 'Scoped]
parenExpr :: ExpressionAtom 'Scoped -> Maybe Expression
parenExpr s = case s of
AtomParens (ExpressionAtoms ss) -> Just (toList ss)
AtomParens e -> Just e
_ -> Nothing
-------------------------------------------------------------------------------