revent
[cc1516.git] / spl.icl
diff --git a/spl.icl b/spl.icl
index 63b1487..1690d71 100644 (file)
--- a/spl.icl
+++ b/spl.icl
@@ -12,10 +12,12 @@ import Data.Maybe
 import Data.Func
 import System.CommandLine
 import GenPrint
-from Text import class Text(concat), instance Text String
+from Text import class Text(concat,join), instance Text String
 
 import parse
 import lex
+import sem
+import AST
 from yard import :: Error, instance toString Error
 
 :: Opts = {
@@ -23,6 +25,7 @@ from yard import :: Error, instance toString Error
        program :: String,
        lex :: Bool,
        parse :: Bool,
+       sem :: Bool,
        fp :: Maybe String,
        help :: Bool}
 
@@ -52,24 +55,28 @@ Start w
 # (contents, stdin, w) = readFileOrStdin stdin args.fp w
 = case contents of
        (Left cs) = snd $ fclose (stdin <<< cs) w
-       (Right cs)
-       # lexOut = lexer cs
-       # stdin = if (not args.lex) stdin (case lexOut of
-               (Right toks) = 
-                       stdin <<< "---LEXER\n" <<< printTokens toks <<< "---LEXER\n"
-               _ = stdin)
-       # parseOut = parser lexOut
-       # stdin = if (not args.parse) stdin (case parser lexOut of
-               (Right ast) = 
-                       stdin <<<  "---PARSER\n" <<< toString ast <<< "---PARSER\n" 
-               (Left parse) = stdin <<< toString parse)
-       = snd $ fclose stdin w
+       (Right cs) = case lexer cs of
+               (Left e) = snd $ fclose (stdin <<< toString e) w
+               (Right lexOut)
+               # stdin = if (not args.lex) stdin (
+                       stdin <<< "//LEXER\n" <<< printTokens lexOut <<< "//LEXER\n")
+               = case parser lexOut of
+                       (Left e) = snd $ fclose (stdin <<< toString e) w
+                       (Right parseOut)
+                       # stdin = if (not args.parse) stdin (
+                               stdin <<<  "//PARSER\n" <<< toString parseOut <<< "//PARSER\n")
+                       = case sem parseOut of
+                               (Left e) = snd $ fclose (stdin <<< join "\n" (map toString e)) w
+                               (Right semOut)
+                               # stdin = if (not args.sem) stdin (
+                                       stdin <<<  "//SEM\n" <<< toString semOut <<< "//SEM\n")
+                               = snd $ fclose stdin w
                where
                        printTokens :: [Token] -> String
                        printTokens ts = concat $ flatten $ map pt ts
                                where
-                                       pt {line,column,token} = [toString line, ":", 
-                                               toString column, ": ", printToString token, "\n"]
+                               pt ({line,col},token) = [toString line, ":", 
+                                               toString col, ": ", printToString token, "\n"]
 
 parseArgs :: *World -> (Opts, *World)
 parseArgs w
@@ -78,7 +85,8 @@ parseArgs w
        program=p,
        version=False,
        lex=False,
-       parse=True,
+       parse=False,
+       sem=True,
        fp=Nothing,
        help=False}, w)
 where
@@ -90,6 +98,8 @@ where
        pa ["--no-lex":r] o = pa r {o & lex=False}
        pa ["--parse":r] o = pa r {o & parse=True}
        pa ["--no-parse":r] o = pa r {o & parse=False}
+       pa ["--sem":r] o = pa r {o & sem=True}
+       pa ["--no-sem":r] o = pa r {o & sem=False}
        pa [x:r] o = pa r {o & fp=Just x}
 
 readFileOrStdin :: *File (Maybe String) *World -> *(Either String [Char], *File, *World)