From ad00b4534582c5ce94243f7dda3b76d7c0bba021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 5 Apr 2026 10:31:55 +0200 Subject: Parse data constructors --- src/Parser/Expr.hs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/Parser/Expr.hs') diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index b9b5f01..585f727 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -5,11 +5,13 @@ module Parser.Expr ( varName, newVarName, addVarName, + constrName, someExpr, typedExpr, literal, variable, + constructor, stringExpansion, @@ -83,6 +85,13 @@ addVarName off (TypedVarName name) = do Nothing -> return () modify $ \s -> s { testVars = ( name, ( LocalVarName name, ExprTypePrim @a Proxy )) : testVars s } +constrName :: TestParser VarName +constrName = label "contructor name" $ do + lexeme $ try $ do + lead <- upperChar + rest <- takeWhileP Nothing (\x -> isAlphaNum x || x == '_') + return $ VarName $ TL.toStrict $ TL.fromChunks $ T.singleton lead : TL.toChunks rest + someExpansion :: TestParser SomeExpr someExpansion = do void $ char '$' @@ -370,10 +379,17 @@ variable = label "variable" $ do e <- lookupVarExpr off sline name recordSelector e <|> return e +constructor :: TestParser SomeExpr +constructor = label "constructor" $ do + off <- stateOffset <$> getParserState + sline <- getSourceLine + name <- constrName + lookupVarExpr off sline name + functionCall :: TestParser SomeExpr functionCall = do sline <- getSourceLine - variable >>= \case + (variable <|> constructor) >>= \case SomeExpr e'@(FunVariable argTypes _ _) -> do let check = checkFunctionArguments argTypes args <- functionArguments check someExpr literal (\poff -> lookupVarExpr poff sline . VarName) -- cgit v1.2.3