update
authorMart Lubbers <mart@martlubbers.net>
Fri, 19 Feb 2016 18:00:29 +0000 (19:00 +0100)
committerMart Lubbers <mart@martlubbers.net>
Fri, 19 Feb 2016 18:00:29 +0000 (19:00 +0100)
lex.icl
main.prj

diff --git a/lex.icl b/lex.icl
index 6966cde..876e302 100644 (file)
--- a/lex.icl
+++ b/lex.icl
@@ -4,7 +4,9 @@ import Control.Monad
 import Data.Either
 import Data.Maybe
 import Data.Map
+import Data.Func
 import StdString
+import StdTuple
 import StdBool
 import StdList
 import StdChar
@@ -20,9 +22,8 @@ SingleCharTokens = fromList [
        ('<', LesserToken), ('>', BiggerToken), ('!', ExclamationToken)]
 
 EscapeMap :: Map Char Char
-EscapeMap = fromList [
-       ('a', toChar 7), ('b', '\b'), ('f', '\f'), ('n', '\n'), ('r', '\r'),
-       ('t', '\t'), ('v', '\v')]
+EscapeMap = fromList [('a', toChar 7), ('b', '\b'), ('f', '\f'), ('n', '\n'),
+       ('r', '\r'), ('t', '\t'), ('v', '\v')]
 
 lexer :: [Char] -> LexerOutput
 lexer [] = Right []
@@ -32,38 +33,37 @@ lexer x = case lex x of
 
 lex :: [Char] -> (Either String Token, [Char])
 lex [] = (Right EndOfFileToken, [])
-lex ['/':'/':x:rest] = if (x == '\n') (lex rest) (lex ['/':'/':rest])
-lex ['/':'*':x1:x2:rest] = if (x1 == '*' && x2 == '/') 
-       (lex rest) (lex ['/':'*':rest])
-lex ['v':'a':'r':rest] = (Right VarToken, rest)
-lex ['V':'o':'i':'d':rest] = (Right VoidToken, rest)
-lex ['r':'e':'t':'u':'r':'n':rest] = (Right ReturnToken, rest)
-lex ['i':'f':rest] = (Right IfToken, rest)
-lex ['e':'l':'s':'e':rest] = (Right ElseToken, rest)
-lex ['w':'h':'i':'l':'e':rest] = (Right WhileToken, rest)
-lex ['T':'r':'u':'e':rest] = (Right TrueToken, rest)
-lex ['F':'a':'l':'s':'e':rest] = (Right FalseToken, rest)
-lex ['I':'n':'t':rest] = (Right IntTypeToken, rest)
-lex ['C':'h':'a':'r':rest] = (Right CharTypeToken, rest)
-lex ['B':'o':'o':'l':rest] = (Right BoolTypeToken, rest)
-lex [':':':':rest] = (Right DoubleColonToken, rest)
-lex ['!':'=':rest] = (Right NotEqualToken, rest)
-lex ['<':'=':rest] = (Right LesserEqToken, rest)
-lex ['>':'=':rest] = (Right GreaterEqToken, rest)
-lex ['=':'=':rest] = (Right EqualsToken, rest)
-lex ['&':'&':rest] = (Right AmpersandsToken, rest)
-lex ['|':'|':rest] = (Right PipesToken, rest)
-lex ['-':'>':rest] = (Right ArrowToken, rest)
-lex ['\'':x:'\'':rest] = (Right (CharToken x), rest)
-lex ['\'':'\\':x:'\'':rest] = case get x EscapeMap of
-       Just t = (Right (CharToken t), rest)
+lex ['/':'/':xs] = lex $ dropWhile ((<>) '\n') xs
+lex ['/':'*':xs] = lex $ tl $ map snd $ dropWhile ((<>) ('*', '/')) $ zip2 [zero:xs] xs
+lex ['v':'a':'r':xs] = (Right VarToken, xs)
+lex ['V':'o':'i':'d':xs] = (Right VoidToken, xs)
+lex ['r':'e':'t':'u':'r':'n':xs] = (Right ReturnToken, xs)
+lex ['i':'f':xs] = (Right IfToken, xs)
+lex ['e':'l':'s':'e':xs] = (Right ElseToken, xs)
+lex ['w':'h':'i':'l':'e':xs] = (Right WhileToken, xs)
+lex ['T':'r':'u':'e':xs] = (Right TrueToken, xs)
+lex ['F':'a':'l':'s':'e':xs] = (Right FalseToken, xs)
+lex ['I':'n':'t':xs] = (Right IntTypeToken, xs)
+lex ['C':'h':'a':'r':xs] = (Right CharTypeToken, xs)
+lex ['B':'o':'o':'l':xs] = (Right BoolTypeToken, xs)
+lex [':':':':xs] = (Right DoubleColonToken, xs)
+lex ['!':'=':xs] = (Right NotEqualToken, xs)
+lex ['<':'=':xs] = (Right LesserEqToken, xs)
+lex ['>':'=':xs] = (Right GreaterEqToken, xs)
+lex ['=':'=':xs] = (Right EqualsToken, xs)
+lex ['&':'&':xs] = (Right AmpersandsToken, xs)
+lex ['|':'|':xs] = (Right PipesToken, xs)
+lex ['-':'>':xs] = (Right ArrowToken, xs)
+lex ['\'':x:'\'':xs] = (Right (CharToken x), xs)
+lex ['\'':'\\':x:'\'':xs] = case get x EscapeMap of
+       Just t = (Right (CharToken t), xs)
        _ = (Left ("Unknown escape: \\" +++ toString x), [])
-lex [x:rest]
+lex [x:xs]
 # t = get x SingleCharTokens
-| isJust t = (Right (fromJust t), rest)
-| isSpace x = lex rest
-| isDigit x = let (is, rest`) = span isDigit rest in
-       (Right (NumberToken [x:is]), rest`)
-| isAlpha x = let (is, rest`) = span (\c.isAlphanum c || c == '_') rest in
-       (Right (IdentToken [x:is]), rest`)
+| isJust t = (Right (fromJust t), xs)
+| isSpace x = lex xs
+| isDigit x = let (is, xs`) = span isDigit xs in
+       (Right (NumberToken [x:is]), xs`)
+| isAlpha x = let (is, xs`) = span (\c.isAlphanum c || c == '_') xs in
+       (Right (IdentToken [x:is]), xs`)
 | otherwise = (Left ("Unexpected character: " +++ toString x), [])
index 537dca6..c86f61c 100644 (file)
--- a/main.prj
+++ b/main.prj
@@ -31,7 +31,6 @@ Global
        Link
                LinkMethod:     Static
                GenerateRelocations:    False
-               GenerateSymbolTable:    False
                GenerateLinkMap:        False
                LinkResources:  False
                ResourceSource: 
@@ -394,7 +393,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Control.Applicative
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -408,7 +407,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Control.Monad
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -422,7 +421,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Either
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -436,7 +435,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Foldable
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -450,7 +449,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Func
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -464,7 +463,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Functor
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -478,7 +477,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.List
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -492,7 +491,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Map
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -506,7 +505,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Maybe
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -520,7 +519,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Monoid
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -534,7 +533,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Set
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -548,7 +547,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Traversable
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -562,7 +561,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Data.Void
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -576,7 +575,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   System.IO
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -590,7 +589,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Text
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -604,7 +603,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Text.JSON
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False
@@ -618,7 +617,7 @@ OtherModules
                        Fusion: False
        Module
                Name:   Text.PPrint
-               Dir:    {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+               Dir:    {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
                Compiler
                        NeverMemoryProfile:     False
                        NeverTimeProfile:       False