diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-09-28 22:06:10 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-09-30 22:45:58 +0200 |
commit | bfe4705f525ba2bc5faaa5f2474f3ee994ed7850 (patch) | |
tree | cae60d7f8b501ade8d11c55506a05588bc191224 /src | |
parent | e6f8e2eeb66880950bd35fd82d439d87e7fa6bf5 (diff) |
Fix parser error position for variable redefinition
Diffstat (limited to 'src')
-rw-r--r-- | src/Parser.hs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index 0f3747d..cd0c028 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -104,14 +104,16 @@ varName = VarName <$> identifier newVarName :: forall a proxy. ExprType a => proxy a -> TestParser VarName newVarName proxy = do + off <- stateOffset <$> getParserState name <- varName - addVarName proxy name + addVarName off proxy name return name -addVarName :: forall a proxy. ExprType a => proxy a -> VarName -> TestParser () -addVarName _ name = do +addVarName :: forall a proxy. ExprType a => Int -> proxy a -> VarName -> TestParser () +addVarName off _ name = do gets (lookup name . testVars) >>= \case - Just _ -> fail $ "variable '" ++ unpackVarName name ++ "' already exists" + Just _ -> parseError $ FancyError off $ S.singleton $ ErrorFail $ T.unpack $ + T.pack "variable '" <> textVarName name <> T.pack "' already exists" Nothing -> return () modify $ \s -> s { testVars = (name, SomeExprType @a Proxy) : testVars s } @@ -299,13 +301,14 @@ letStatement = do line <- getSourceLine indent <- L.indentLevel wsymbol "let" + off <- stateOffset <$> getParserState name <- varName osymbol "=" SomeExpr (e :: Expr a) <- someExpr - void $ eol s <- get - addVarName @a Proxy name + addVarName @a off Proxy name + void $ eol body <- testBlock indent put s |