comments parsen is kapot
authorMart Lubbers <mart@martlubbers.net>
Tue, 1 Mar 2016 14:48:55 +0000 (15:48 +0100)
committerMart Lubbers <mart@martlubbers.net>
Tue, 1 Mar 2016 14:48:55 +0000 (15:48 +0100)
Signed-off-by: Mart Lubbers <mart@martlubbers.net>
src/example.spl
src/lex.dcl
src/lex.icl
src/main.icl
src/main.prj
src/parse.icl

index 2a1f3ab..b4efb27 100644 (file)
@@ -93,4 +93,4 @@ squareOddNumbers(list) :: [Int] -> [Int] {
        }
        return list;
 }
-//deze comment eindigt met EOF ipv newline
\ No newline at end of file
+//deze comment eindigt met EOF ipv newline
index a713e5d..df25ea8 100644 (file)
@@ -5,7 +5,7 @@ from Data.Either import :: Either
 :: Token :== (Int, Int, TokenValue)
 :: TokenValue
        //Value tokens
-       = IdentToken [Char] // Identifier
+       = IdentToken String // Identifier
        | NumberToken Int   // Integer
        | CharToken Char    // Character literal
        //Keyword tokens
index bedb75f..4cf915c 100644 (file)
@@ -16,7 +16,7 @@ lexer r = case runParser lexProgram r of
 
 lexProgram :: Parser Char [Token]
 lexProgram = some lexToken <* many (satisfy isSpace) <* eof
-       >>= \ts->pure (map (\t->(0, 0, t)) ts)
+       >>= \ts->pure $ (map (\t->(0, 0, t)) ts) ++ [(0, 0, EndOfFileToken)]
 
 lexToken :: Parser Char TokenValue
 lexToken = 
@@ -59,10 +59,10 @@ lexToken =
        //Number tokens
        (liftM (NumberToken o toInt o toString) $ some $ satisfy isDigit) <|>
        //Ident tokens
-       (liftM IdentToken $ some $ satisfy isIdentChar) <|>
+       (liftM (IdentToken o toString) $ some $ satisfy isIdentChar) <|>
        (satisfy isSpace >>| lexToken)
        where
-               lexUntilNL = top until ((item '\n' >>| return Void) <|> eof)
+               lexUntilNL = top until (eof <|> (item '\n' >>| pure Void))
                lexUntilCommentClose = top until list (fromString "*/")
                isIdentChar c = isAlphanum c || c == '_'
                lexOp s tv = list (fromString s) >>| pure tv
index f2b5c93..0dfab03 100644 (file)
@@ -4,11 +4,15 @@ import StdFile
 import StdBool
 import StdMisc
 import StdFunc
+import StdTuple
 import StdList
 import StdString
 import Data.Either
 import Data.Maybe
+import Data.Func
 import System.CommandLine
+import GenPrint
+from Text import class Text(concat), instance Text String
 
 import parse
 import lex
@@ -20,45 +24,48 @@ import lex
        fp :: Maybe String,
        help :: Bool}
 
-:: *StartType :== (LexerOutput, ParserOutput, *World)
+derive gPrint TokenValue
 
-Start :: *World -> *StartType
+Start :: *World -> *World
 Start w
 # (args, w) = parseArgs w
 | args.help
        # (out, w) = stdio w
-       # out = out <<< "\nUsage: " <<< args.program <<< " [opts] [FILENAME]\n"
+       # out = out <<< "Usage: " <<< args.program <<< " [opts] [FILENAME]\n"
                <<< "\t--help  Show this help\n"
-               <<< "\t--lex   Lex only, is mutually exclusive with --parse\n"
-               <<< "\t--parse Lex & Parse only\n\n"
+               <<< "\t--[no-]lex   Lexer output(default: disabled)\n"
+               <<< "\t--[no-]parse Parser output(default: enabled)\n\n"
                <<< "\tFILENAME   File to parse, when unspecified stdin is parsed\n"
-       # (_, w) = fclose out w
-       = (Left "", Left "", w)
+       = snd $ fclose out w
 # (stdin, w) = stdio w
 # (contents, stdin, w) = readFileOrStdin stdin args.fp w
-| args.lex = case contents of
-       (Right cs) = (lexer cs, Left "Parsing Disabled", w)
-       (Left e) = (Left e, Left "Parsing disabled", w)
 = case contents of
-       (Left e) = (Left e, Left "", w)
+       (Left cs) = snd $ fclose (stdin <<< cs) w
        (Right cs)
-       # lexout = lexer cs
-       # parsout = parser lexout
-       # stdin = stdin <<< (either (const "") toString parsout)
-       # (_, w) = fclose stdin w
-       = (lexout, parser lexout, w)
+       # lexOut = lexer cs
+       # stdin = if (not args.lex) stdin (case lexOut of
+               (Left lex) = stdin <<< toString lex
+               (Right toks) = stdin <<< 
+                       concat (map (\(_, _, t)->printToString t +++ "\n") toks))
+       # parseOut = parser lexOut
+       # stdin = if (not args.parse) stdin (case parser lexOut of
+               (Left parse) = stdin <<< toString parse
+               (Right ast) = stdin <<< toString ast)
+       = snd $ fclose stdin w
 
 parseArgs :: *World -> (Opts, *World)
 parseArgs w
 # ([p:args], w) = getCommandLine w
-= (pa args {program=p, lex=False, parse=False, fp=Nothing, help=False}, w)
+= (pa args {program=p, lex=False, parse=True, fp=Nothing, help=False}, w)
 where
-       pa :: [String] -> (Opts -> Opts)
-       pa [] = id
-       pa ["--help":r] = \o.pa r {o & help=True}
-       pa ["--lex":r] = \o.pa r {o & lex=True, parse=False}
-       pa ["--parse":r] = \o.pa r {o & lex=False, parse=True}
-       pa [x:r] = \o.pa r {o & fp=Just x}
+       pa :: [String] Opts -> Opts
+       pa [] o = o
+       pa ["--help":r] o = pa r {o & help=True}
+       pa ["--lex":r] o = pa r {o & lex=True}
+       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 [x:r] o = pa r {o & fp=Just x}
 
 readFileOrStdin :: *File (Maybe String) *World -> *(Either String [Char], *File, *World)
 readFileOrStdin stdin Nothing w
index d7bf8d0..933ed3d 100644 (file)
@@ -24,13 +24,14 @@ Global
                        Time:   True
                        Stack:  True
                Output
-                       Output: ShowConstructors
+                       Output: NoConsole
                        Font:   Courier
                        FontSize:       9
                        WriteStdErr:    False
        Link
                LinkMethod:     Static
                GenerateRelocations:    False
+               GenerateSymbolTable:    False
                GenerateLinkMap:        False
                LinkResources:  False
                ResourceSource: 
@@ -364,8 +365,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Control.Applicative
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   System.OS
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -378,8 +379,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Control.Monad
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   System.OS
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -392,8 +393,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Data.Either
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Control.Applicative
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -406,8 +407,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Data.Func
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Control.Monad
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -420,8 +421,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Data.Functor
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Data.Either
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -434,8 +435,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Data.List
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Data.Func
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -448,8 +449,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Data.Maybe
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Data.Functor
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -462,8 +463,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Data.Monoid
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Data.List
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -476,8 +477,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Data.Void
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Data.Maybe
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -490,8 +491,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   System.CommandLine
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Data.Monoid
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -504,8 +505,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   System.IO
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   Data.Void
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -518,8 +519,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   System._Pointer
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   System.CommandLine
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -532,8 +533,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   Text
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+               Name:   System.IO
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -546,8 +547,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   System.OS
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64
+               Name:   System._Pointer
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -560,8 +561,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   System.OS
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64
+               Name:   Text
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -574,8 +575,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   _SystemDynamic
-               Dir:    {Application}/lib/iTasks-SDK/Patches/Dynamics
+               Name:   StdMaybe
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent/Deprecated/StdLib
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -588,8 +589,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   GenEq
-               Dir:    {Application}/lib/iTasks-SDK/Patches/Generics
+               Name:   _SystemDynamic
+               Dir:    {Application}/lib/iTasks-SDK/Patches/Dynamics
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -602,7 +603,7 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   GenPrint
+               Name:   GenEq
                Dir:    {Application}/lib/iTasks-SDK/Patches/Generics
                Compiler
                        NeverMemoryProfile:     False
@@ -616,8 +617,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   StdGeneric
-               Dir:    {Application}/lib/iTasks-SDK/Patches/StdEnv
+               Name:   GenPrint
+               Dir:    {Application}/lib/iTasks-SDK/Patches/Generics
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -630,8 +631,8 @@ OtherModules
                        ReuseUniqueNodes:       True
                        Fusion: False
        Module
-               Name:   StdMaybe
-               Dir:    {Application}/lib/iTasks-SDK/Server/lib
+               Name:   StdGeneric
+               Dir:    {Application}/lib/iTasks-SDK/Patches/StdEnv
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
index 042ec47..ec89565 100644 (file)
@@ -25,7 +25,7 @@ parser (Right r) = case runParser parseProgram r of
 
 parseProgram :: Parser Token AST
 parseProgram = liftM2 AST (many parseVarDecl) (some parseFunDecl) 
-//     <* satTok EndOfFileToken
+       <* satTok EndOfFileToken
 
 parseFunDecl :: Parser Token FunDecl
 parseFunDecl = liftM5 FunDecl
@@ -191,7 +191,7 @@ parseSepList sep p =
        (liftM pure p) <|> pure empty
 
 parseIdent :: Parser Token String
-parseIdent = trans2 (IdentToken []) (\(IdentToken e).toString e)
+parseIdent = trans2 (IdentToken "") (\(IdentToken e).toString e)
 
 instance toString AST where
        toString (AST v f) = concat (