Simple lexer/parser fixes.

This commit is contained in:
2011-01-06 18:03:56 -08:00
parent 7a435e5f64
commit 39ff973e81
3 changed files with 28 additions and 6 deletions

View File

@@ -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

View File

@@ -20,7 +20,7 @@ $bindigit = [01]
-- Identifier Characters
$typestart = [A-Z\_]
$valstart = [a-z\_]
$identrest = [a-zA-Z0-9\_]
$identrest = [a-zA-Z0-9\_\.]
$opident = [\~\!\@\#\$\%\^\&\*\+\-\=\.\:\<\>\?\/\_]
$escape_char = [abfnrtv'\"\\]

View File

@@ -175,7 +175,6 @@ bangtype2 :: { Type }
bangtype3 :: { Type }
: TYPE_IDENT { TVar (makeQualified $1) Star }
| VAL_IDENT { TVar (makeQualified $1) Star }
| '(' bangtype ')' { $2 }
-- Expressions --------------------------------------------------------------