Skip to content

Commit

Permalink
Don't hardcode the entity declaration type
Browse files Browse the repository at this point in the history
  • Loading branch information
infomiho committed Jul 8, 2024
1 parent 96523f9 commit f1869e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 7 additions & 8 deletions waspc/src/Wasp/Analyzer/Parser/Valid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ where

import Data.List (find)
import qualified Wasp.Analyzer.Parser as P
import Wasp.Analyzer.StdTypeDefinitions.Entity (entityDeclTypeName)

validateAst :: P.AST -> Either (String, P.Ctx) P.AST
validateAst = validateNoEntityDeclInWaspFile

validateNoEntityDeclInWaspFile :: P.AST -> Either (String, P.Ctx) P.AST
validateNoEntityDeclInWaspFile ast@(P.AST stmts) = case findEntityDecl stmts of
validateNoEntityDeclInWaspFile ast@(P.AST stmts) = case findEntityStmt stmts of
Just (P.WithCtx ctx _) -> Left (entitiesNoLongerSupportedError, ctx)
Nothing -> Right ast
where
findEntityDecl :: [P.WithCtx P.Stmt] -> Maybe (P.WithCtx P.Stmt)
findEntityDecl = find isEntityDecl

isEntityDecl :: P.WithCtx P.Stmt -> Bool
isEntityDecl = \case
P.WithCtx _ (P.Decl "entity" _ _) -> True
_ -> False
findEntityStmt :: [P.WithCtx P.Stmt] -> Maybe (P.WithCtx P.Stmt)
findEntityStmt =
find
( \(P.WithCtx _ (P.Decl declTypeName _ _)) -> declTypeName == entityDeclTypeName
)

entitiesNoLongerSupportedError :: String
entitiesNoLongerSupportedError =
Expand Down
10 changes: 8 additions & 2 deletions waspc/src/Wasp/Analyzer/StdTypeDefinitions/Entity.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Wasp.Analyzer.StdTypeDefinitions.Entity () where
module Wasp.Analyzer.StdTypeDefinitions.Entity
( entityDeclTypeName,
)
where

import Control.Arrow (left)
import Wasp.Analyzer.Evaluator.EvaluationError (mkEvaluationError)
Expand All @@ -16,7 +19,7 @@ import qualified Wasp.Psl.Parser.Model
instance IsDeclType Entity where
declType =
DeclType
{ dtName = "entity",
{ dtName = entityDeclTypeName,
dtBodyType = Type.QuoterType "psl",
dtEvaluate = \typeDefinitions bindings declName expr ->
Decl.makeDecl @Entity declName <$> declEvaluate typeDefinitions bindings expr
Expand All @@ -27,3 +30,6 @@ instance IsDeclType Entity where
left (ER.mkEvaluationError ctx . ER.ParseError . ER.EvaluationParseErrorParsec) $
makeEntity <$> Wasp.Psl.Parser.Model.parseBody pslString
_ -> Left $ mkEvaluationError ctx $ ER.ExpectedType (Type.QuoterType "psl") (TC.AST.exprType expr)

entityDeclTypeName :: String
entityDeclTypeName = "entity"

0 comments on commit f1869e7

Please sign in to comment.