Simple lexer/parser fixes.
This commit is contained in:
31
hsrc/Main.hs
31
hsrc/Main.hs
@@ -6,15 +6,38 @@ import System.Exit
|
||||
import System.IO.Error
|
||||
|
||||
import Syntax.AST
|
||||
import Syntax.Lexer
|
||||
import Syntax.Parser
|
||||
import Syntax.ParserCore
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
[file] <- getArgs
|
||||
ast <- loadModule file
|
||||
putStrLn "Successful parse!"
|
||||
putStrLn (show ast)
|
||||
args <- getArgs
|
||||
case args of
|
||||
[file] -> do
|
||||
ast <- loadModule file
|
||||
putStrLn "Successful parse!"
|
||||
putStrLn (show ast)
|
||||
["-lex",path] -> do
|
||||
mtxt <- tryJust (guard . isDoesNotExistError) $ S.readFile path
|
||||
case mtxt of
|
||||
Left _ -> fail $ "Unable to open file: " ++ path
|
||||
Right txt -> do
|
||||
case runParser path txt pullTokens of
|
||||
Left err -> printError err >> exitWith (ExitFailure 1)
|
||||
Right ress -> do
|
||||
mapM_ putStrLn ress
|
||||
putStrLn "Successful lex."
|
||||
|
||||
pullTokens :: Parser [String]
|
||||
pullTokens = do
|
||||
tok <- scan
|
||||
case tok of
|
||||
Lexeme pos tok -> do
|
||||
let res = show pos ++ " " ++ show tok
|
||||
if tok == TokEOF
|
||||
then return [res]
|
||||
else return (res :) `ap` pullTokens
|
||||
|
||||
loadModule :: FilePath -> IO (Module ())
|
||||
loadModule path = do
|
||||
|
||||
Reference in New Issue
Block a user