From c8cd9dd09c5b4d8e0a5e292872d24453cc568cd4 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 3 Mar 2018 15:36:50 -0800 Subject: [PATCH] Add a debugParseScript for development --- ShellCheck/Parser.hs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index e08ed1a..fefe325 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -2826,12 +2826,32 @@ readScriptFile = do readScript = readScriptFile --- Interactively run a parser in ghci: --- debugParse readScript "echo 'hello world'" +-- Interactively run a specific parser in ghci: +-- debugParse readSimpleCommand "echo 'hello world'" debugParse p string = runIdentity $ do (res, _) <- runParser testEnvironment p "-" string 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 = Environment { systemInterface = (mockedSystemInterface []),