X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=spl.icl;h=1690d71850c97d1d312ee9c9808fa992dd623fac;hb=7a0e15a68547d29a87dd0c56d6f5a731d0cd67aa;hp=28b95fb9af33f1a3e8752d3141ba1c5c7d5d8a7b;hpb=5d40ca411bed8014f9bf081436208d831ac5c972;p=cc1516.git diff --git a/spl.icl b/spl.icl index 28b95fb..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,18 +55,22 @@ 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 @@ -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)