From 55c3c2bd6cf3964458d017ad8ea058d1743577ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 26 Apr 2025 10:57:46 +0200 Subject: Evaluate asset path to absolute and check if it exists --- src/Parser.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/Parser.hs') diff --git a/src/Parser.hs b/src/Parser.hs index 9160002..d90b796 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -106,9 +106,18 @@ parseAsset = label "asset definition" $ do osymbol ":" void eol ref <- L.indentGuard scn GT pos1 + wsymbol "path" osymbol ":" - assetPath <- AssetPath . TL.unpack <$> takeWhile1P Nothing (/= '\n') + off <- stateOffset <$> getParserState + path <- TL.unpack <$> takeWhile1P Nothing (/= '\n') + dir <- takeDirectory <$> gets testSourcePath + absPath <- liftIO (makeAbsolute $ dir path) + let assetPath = AssetPath absPath + liftIO (doesPathExist absPath) >>= \case + True -> return () + False -> registerParseError $ FancyError off $ S.singleton $ ErrorCustom $ FileNotFound absPath + void $ L.indentGuard scn LT ref let expr = SomeExpr $ Pure Asset {..} modify $ \s -> s { testVars = ( name, ( GlobalVarName (testCurrentModuleName s) name, someExprType expr )) : testVars s } @@ -191,7 +200,8 @@ parseTestFile parsedModules moduleName path = do Just found -> return $ Right found Nothing -> do let initState = TestParserState - { testVars = concat + { testSourcePath = path + , testVars = concat [ map (\(( mname, name ), value ) -> ( name, ( GlobalVarName mname name, someVarValueType value ))) $ M.toList builtins ] , testContext = SomeExpr (Undefined "void" :: Expr Void) @@ -206,7 +216,7 @@ parseTestFile parsedModules moduleName path = do if isDoesNotExistError e then return Nothing else ioError e case mbContent of Just content -> do - runTestParser path content initState (parseTestModule absPath) >>= \case + runTestParser content initState (parseTestModule absPath) >>= \case Left bundle -> do return $ Left $ ImportModuleError bundle Right testModule -> do -- cgit v1.2.3