X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=spl.icl;h=1690d71850c97d1d312ee9c9808fa992dd623fac;hb=6f035b0bf9e10d215a2d8d6198d29f7727877cad;hp=893d69932597be73b76f4e31e158fd37682f2446;hpb=fe40818bbc1d327f0adfbbbfe7ecfbe15d4eb053;p=cc1516.git diff --git a/spl.icl b/spl.icl index 893d699..1690d71 100644 --- a/spl.icl +++ b/spl.icl @@ -12,10 +12,11 @@ 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 @@ -24,6 +25,7 @@ from yard import :: Error, instance toString Error program :: String, lex :: Bool, parse :: Bool, + sem :: Bool, fp :: Maybe String, help :: Bool} @@ -53,23 +55,27 @@ 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,col},token) = [toString line, ":", + pt ({line,col},token) = [toString line, ":", toString col, ": ", printToString token, "\n"] parseArgs :: *World -> (Opts, *World) @@ -79,7 +85,8 @@ parseArgs w program=p, version=False, lex=False, - parse=True, + parse=False, + sem=True, fp=Nothing, help=False}, w) where @@ -91,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)