summaryrefslogtreecommitdiff
path: root/src/Parser.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-10-02 20:43:08 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-10-05 21:04:17 +0200
commit4161f5776e5e7a01fb9eb62351c0f648bb918076 (patch)
tree5ff89419ecc034538a26f3c4863c4d54d4dc537f /src/Parser.hs
parent4f078b27fda0738ab4ed8f67fe3c8f2c8d010626 (diff)
Support multiple node variables with same name
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs24
1 files changed, 10 insertions, 14 deletions
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 _ = "<source line>"
-instance ParamType NodeName where
- parseParam = NodeName . textVarName <$> newVarName @Node Proxy
- showParamType _ = "<node>"
-
instance ParamType ProcName where
parseParam = procName
showParamType _ = "<proc>"
-instance ParamType VarName where
- parseParam = newVarName @Text Proxy
+instance ExprType a => ParamType (TypedVarName a) where
+ parseParam = newVarName
showParamType _ = "<variable>"
instance ExprType a => ParamType (Expr a) where