diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-04-26 10:57:46 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-04-27 09:34:04 +0200 |
commit | 55c3c2bd6cf3964458d017ad8ea058d1743577ca (patch) | |
tree | 766d1668b605d3eb2c1ec33f745d4c7e9b183e06 /src/Parser/Core.hs | |
parent | 43ef4858ecf9dc05a16a6e588f2ab9ebd478db30 (diff) |
Evaluate asset path to absolute and check if it exists
Diffstat (limited to 'src/Parser/Core.hs')
-rw-r--r-- | src/Parser/Core.hs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/Parser/Core.hs b/src/Parser/Core.hs index d90f227..132dbc8 100644 --- a/src/Parser/Core.hs +++ b/src/Parser/Core.hs @@ -27,6 +27,7 @@ newtype TestParser a = TestParser (StateT TestParserState (ParsecT CustomTestErr , MonadState TestParserState , MonadPlus , MonadFail + , MonadIO , MonadParsec CustomTestError TestStream ) @@ -36,6 +37,7 @@ type TestParseError = ParseError TestStream CustomTestError data CustomTestError = ModuleNotFound ModuleName + | FileNotFound FilePath | ImportModuleError (ParseErrorBundle TestStream CustomTestError) deriving (Eq) @@ -44,17 +46,22 @@ instance Ord CustomTestError where compare (ModuleNotFound _) _ = LT compare _ (ModuleNotFound _) = GT + compare (FileNotFound a) (FileNotFound b) = compare a b + compare (FileNotFound _) _ = LT + compare _ (FileNotFound _) = GT + -- Ord instance is required to store errors in Set, but there shouldn't be -- two ImportModuleErrors at the same possition, so "dummy" comparison -- should be ok. compare (ImportModuleError _) (ImportModuleError _) = EQ instance ShowErrorComponent CustomTestError where - showErrorComponent (ModuleNotFound name) = "module `" <> T.unpack (textModuleName name) <> "' not found" + showErrorComponent (ModuleNotFound name) = "module ‘" <> T.unpack (textModuleName name) <> "’ not found" + showErrorComponent (FileNotFound path) = "file ‘" <> path <> "’ not found" showErrorComponent (ImportModuleError bundle) = "error parsing imported module:\n" <> errorBundlePretty bundle -runTestParser :: String -> TestStream -> TestParserState -> TestParser a -> IO (Either (ParseErrorBundle TestStream CustomTestError) a) -runTestParser path content initState (TestParser parser) = flip (flip runParserT path) content . flip evalStateT initState $ parser +runTestParser :: TestStream -> TestParserState -> TestParser a -> IO (Either (ParseErrorBundle TestStream CustomTestError) a) +runTestParser content initState (TestParser parser) = flip (flip runParserT (testSourcePath initState)) content . flip evalStateT initState $ parser data Toplevel = ToplevelTest Test @@ -63,7 +70,8 @@ data Toplevel | ToplevelImport ( ModuleName, VarName ) data TestParserState = TestParserState - { testVars :: [ ( VarName, ( FqVarName, SomeExprType )) ] + { testSourcePath :: FilePath + , testVars :: [ ( VarName, ( FqVarName, SomeExprType )) ] , testContext :: SomeExpr , testNextTypeVar :: Int , testTypeUnif :: Map TypeVar SomeExprType |