1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

Either makes this easier

This commit is contained in:
Ayman Nadeem 2019-10-15 13:27:54 -04:00
parent be5f00ee50
commit c9219f71c3

View File

@ -41,17 +41,15 @@ main :: IO ()
main = generateAST =<< execParser opts main = generateAST =<< execParser opts
generateAST :: SemanticAST -> IO () generateAST :: SemanticAST -> IO ()
generateAST (SemanticAST _ filePath sourceString) = do generateAST (SemanticAST _ source) = do
case filePath of case source of
Just filePath -> do Left filePath -> do
bytestring <- Data.ByteString.readFile filePath bytestring <- Data.ByteString.readFile filePath
print =<< parseByteString @TreeSitter.Python.AST.Module @(Range, Span) tree_sitter_python bytestring print =<< parseByteString @TreeSitter.Python.AST.Module @(Range, Span) tree_sitter_python bytestring
Nothing -> do Right source -> do
case sourceString of let bytestring = Data.ByteString.Char8.pack source
Just sourceString -> do print =<< parseByteString @TreeSitter.Python.AST.Module @(Range, Span) tree_sitter_python bytestring
bytestring <- Data.ByteString.Char8.pack . Prelude.head <$> getArgs
print =<< parseByteString @TreeSitter.Python.AST.Module @(Range, Span) tree_sitter_python bytestring
Nothing -> print "please provide a file path or source string to parse"
opts :: ParserInfo SemanticAST opts :: ParserInfo SemanticAST
opts = info (parseAST <**> helper) opts = info (parseAST <**> helper)