summaryrefslogtreecommitdiff
path: root/src/Parser.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-04-26 10:57:46 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2025-04-27 09:34:04 +0200
commit55c3c2bd6cf3964458d017ad8ea058d1743577ca (patch)
tree766d1668b605d3eb2c1ec33f745d4c7e9b183e06 /src/Parser.hs
parent43ef4858ecf9dc05a16a6e588f2ab9ebd478db30 (diff)
Evaluate asset path to absolute and check if it exists
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs16
1 files changed, 13 insertions, 3 deletions
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