Simple lexer/parser fixes.
This commit is contained in:
25
hsrc/Main.hs
25
hsrc/Main.hs
@@ -6,15 +6,38 @@ import System.Exit
|
|||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
|
|
||||||
import Syntax.AST
|
import Syntax.AST
|
||||||
|
import Syntax.Lexer
|
||||||
import Syntax.Parser
|
import Syntax.Parser
|
||||||
import Syntax.ParserCore
|
import Syntax.ParserCore
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
[file] <- getArgs
|
args <- getArgs
|
||||||
|
case args of
|
||||||
|
[file] -> do
|
||||||
ast <- loadModule file
|
ast <- loadModule file
|
||||||
putStrLn "Successful parse!"
|
putStrLn "Successful parse!"
|
||||||
putStrLn (show ast)
|
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 :: FilePath -> IO (Module ())
|
||||||
loadModule path = do
|
loadModule path = do
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ $bindigit = [01]
|
|||||||
-- Identifier Characters
|
-- Identifier Characters
|
||||||
$typestart = [A-Z\_]
|
$typestart = [A-Z\_]
|
||||||
$valstart = [a-z\_]
|
$valstart = [a-z\_]
|
||||||
$identrest = [a-zA-Z0-9\_]
|
$identrest = [a-zA-Z0-9\_\.]
|
||||||
$opident = [\~\!\@\#\$\%\^\&\*\+\-\=\.\:\<\>\?\/\_]
|
$opident = [\~\!\@\#\$\%\^\&\*\+\-\=\.\:\<\>\?\/\_]
|
||||||
$escape_char = [abfnrtv'\"\\]
|
$escape_char = [abfnrtv'\"\\]
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,6 @@ bangtype2 :: { Type }
|
|||||||
|
|
||||||
bangtype3 :: { Type }
|
bangtype3 :: { Type }
|
||||||
: TYPE_IDENT { TVar (makeQualified $1) Star }
|
: TYPE_IDENT { TVar (makeQualified $1) Star }
|
||||||
| VAL_IDENT { TVar (makeQualified $1) Star }
|
|
||||||
| '(' bangtype ')' { $2 }
|
| '(' bangtype ')' { $2 }
|
||||||
|
|
||||||
-- Expressions --------------------------------------------------------------
|
-- Expressions --------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user