From 5014c402e63e882567bb8759cad5cbf61db1e11f Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 25 Mar 2024 22:30:33 +0100 Subject: typechecker --- src/HSVIS/Parser.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/HSVIS/Parser.hs') diff --git a/src/HSVIS/Parser.hs b/src/HSVIS/Parser.hs index e89c679..bea0524 100644 --- a/src/HSVIS/Parser.hs +++ b/src/HSVIS/Parser.hs @@ -30,6 +30,7 @@ import Control.Monad.Chronicle import Control.Monad.Reader import Control.Monad.State.Lazy import Data.Char +import Data.Bifunctor (second) import Data.Either (partitionEithers) import Data.Foldable import Data.List.NonEmpty (NonEmpty(..)) @@ -49,7 +50,9 @@ import HSVIS.Pretty data StageParsed type instance X DataDef StageParsed = Range +type instance X DataField StageParsed = () type instance X FunDef StageParsed = Range +type instance X TypeSig StageParsed = () type instance X FunEq StageParsed = Range type instance X Type StageParsed = Range type instance X Pattern StageParsed = Range @@ -233,7 +236,7 @@ pDataDef0 = do params <- famany (inlineWhite >> ranged (pIdentifier0 InBlock Lowercase WCBacktrack)) cons <- pDatacons "=" pos2 <- gets psCur - return [DataDef (Range pos1 pos2) name params cons] + return [DataDef (Range pos1 pos2) name params (map (second (map (DataField ()))) cons)] where pDatacons :: String -> IParser [(Name, [PType])] pDatacons leader = do @@ -262,20 +265,20 @@ pFunDef0 = clauses <- concat <$> famany (pFunEq (Continue name)) let clauses' = clause1 :| clauses1 ++ clauses let rng = sigrange <> foldMapne extOf clauses' - return [FunDef rng name (TypeSig typ) clauses'] + return [FunDef rng name (TypeSig () typ) clauses'] _ -> do pos <- gets psCur raise Error $ "Expected function equation for " ++ pretty name ++ " after type signature" let rng = Range pos pos - return [FunDef sigrange name (TypeSig typ) + return [FunDef sigrange name (TypeSig () typ) (FunEq rng name [] (Plain rng (EError rng)) :| [])] ,do pFunEq FirstLine >>= \case clause1@(FunEq _ name _ _) : clauses1 -> noFail $ do clauses <- concat <$> famany (pFunEq (Continue name)) let clauses' = clause1 :| clauses1 ++ clauses let rng = foldMapne extOf clauses' - return [FunDef rng name (TypeSigExt NoTypeSig) clauses'] + return [FunDef rng name (TypeSigExt () NoTypeSig) clauses'] [] -> faempty] -- | Given the name from the type signature or a previous clause, if any. -- cgit v1.2.3-70-g09d2