From 4161f5776e5e7a01fb9eb62351c0f648bb918076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 2 Oct 2022 20:43:08 +0200 Subject: Support multiple node variables with same name --- src/Parser.hs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/Parser.hs') diff --git a/src/Parser.hs b/src/Parser.hs index 74a5ade..a38d0c9 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -26,7 +26,7 @@ import qualified Text.Megaparsec.Char.Lexer as L import System.Exit -import Network (Node, NodeName(..)) +import Network () import Process (ProcName(..)) import Test @@ -107,15 +107,15 @@ identifier = do varName :: TestParser VarName varName = VarName <$> identifier -newVarName :: forall a proxy. ExprType a => proxy a -> TestParser VarName -newVarName proxy = do +newVarName :: forall a. ExprType a => TestParser (TypedVarName a) +newVarName = do off <- stateOffset <$> getParserState - name <- varName - addVarName off proxy name + name <- TypedVarName <$> varName + addVarName off name return name -addVarName :: forall a proxy. ExprType a => Int -> proxy a -> VarName -> TestParser () -addVarName off _ name = do +addVarName :: forall a. ExprType a => Int -> TypedVarName a -> TestParser () +addVarName off (TypedVarName name) = do gets (lookup name . testVars) >>= \case Just _ -> parseError $ FancyError off $ S.singleton $ ErrorFail $ T.unpack $ T.pack "variable '" <> textVarName name <> T.pack "' already exists" @@ -312,7 +312,7 @@ letStatement = do SomeExpr (e :: Expr a) <- someExpr localState $ do - addVarName @a off Proxy name + addVarName off $ TypedVarName @a name void $ eol body <- testBlock indent return [Let line name e body] @@ -328,16 +328,12 @@ instance ParamType SourceLine where parseParam = mzero showParamType _ = "" -instance ParamType NodeName where - parseParam = NodeName . textVarName <$> newVarName @Node Proxy - showParamType _ = "" - instance ParamType ProcName where parseParam = procName showParamType _ = "" -instance ParamType VarName where - parseParam = newVarName @Text Proxy +instance ExprType a => ParamType (TypedVarName a) where + parseParam = newVarName showParamType _ = "" instance ExprType a => ParamType (Expr a) where -- cgit v1.2.3