Skip to content

Commit ebab91b

Browse files
committed
language-powerquery: Main: JSON print
1 parent 1114196 commit ebab91b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

language-powerquery/app/Main.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import "language-powerquery" Language.PowerQuery
1414
data Lex
1515
= Lex
1616
{ _lex_path :: !(Maybe FilePath)
17+
, _lex_json :: !Bool
1718
}
1819

1920
data Parse
@@ -40,6 +41,11 @@ lexParser = C1 <$> (Lex
4041
<> metavar "PATH"
4142
<> help "Lex PowerQuery Text"
4243
))
44+
<*> switch
45+
( long "json"
46+
<> short 'j'
47+
<> help "print Tokens as JSON"
48+
)
4349
)
4450

4551
parseParser :: Parser Command
@@ -73,12 +79,14 @@ readPathOrStdin (Just path) = B.readFile path
7379

7480

7581
lex :: Lex -> IO ()
76-
lex (Lex mPath) = do
82+
lex (Lex mPath shouldJSON) = do
7783
bs <- readPathOrStdin mPath
7884
let tokens = lexer
7985
. B.unpack
8086
$ bs
81-
print tokens
87+
if shouldJSON
88+
then B.putStrLn . encode $ tokens
89+
else print $ tokens
8290
return ()
8391

8492

0 commit comments

Comments
 (0)