Add a debugParseScript for development

This commit is contained in:
Vidar Holen 2018-03-03 15:36:50 -08:00
parent 8b8aeb4409
commit c8cd9dd09c
1 changed files with 22 additions and 2 deletions

View File

@ -2826,12 +2826,32 @@ readScriptFile = do
readScript = readScriptFile readScript = readScriptFile
-- Interactively run a parser in ghci: -- Interactively run a specific parser in ghci:
-- debugParse readScript "echo 'hello world'" -- debugParse readSimpleCommand "echo 'hello world'"
debugParse p string = runIdentity $ do debugParse p string = runIdentity $ do
(res, _) <- runParser testEnvironment p "-" string (res, _) <- runParser testEnvironment p "-" string
return res return res
-- Interactively run the complete parser in ghci:
-- debugParseScript "#!/bin/bash\necho 'Hello World'\n"
debugParseScript string =
result {
-- Remove the noisiest parts
prTokenPositions = Map.fromList [
(Id 0, Position {
posFile = "removed for clarity",
posLine = -1,
posColumn = -1
})]
}
where
result = runIdentity $
parseScript (mockedSystemInterface []) $ ParseSpec {
psFilename = "debug",
psScript = string,
psCheckSourced = False
}
testEnvironment = testEnvironment =
Environment { Environment {
systemInterface = (mockedSystemInterface []), systemInterface = (mockedSystemInterface []),