import StdList
import StdChar
-SingleCharTokens :: Map Char Token
+SingleCharTokens :: Map Char TokenValue
SingleCharTokens = fromList [
('(', BraceOpenToken), (')', BraceCloseToken), ('{', CBraceOpenToken),
('}', CBraceCloseToken), ('[', SquareOpenToken), (']', SquareCloseToken),
('r', '\r'), ('t', '\t'), ('v', '\v')]
lexer :: [Char] -> LexerOutput
-lexer [] = Right []
-lexer x = case lex x of
- (Right t, rest) = lexer rest >>= \ts.Right [t:ts]
- (Left e, _) = Left e
+lexer x = lexer` x 1
+ where
+ lexer` :: [Char] Int -> LexerOutput
+ lexer` [] i = Right []
+ lexer` x i = case lex x i of
+ (Right t, rest, i) = lexer` rest i >>= \ts.Right [t:ts]
+ (Left e, _, _) = Left e
-lex :: [Char] -> (Either String Token, [Char])
-lex [] = (Right EndOfFileToken, [])
-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)
+ret:: TokenValue [Char] Int -> (Either String Token, [Char], Int)
+ret tv rest i = (Right (i, tv), rest, i)
+
+err :: String Int -> (Either String Token, [Char], Int)
+err s i = (Left ("Line " +++ toString i +++ ": " +++ s), [], i)
+
+lex :: [Char] -> (Int -> (Either String Token, [Char], Int))
+lex [] = ret EndOfFileToken []
+lex ['/':'/':xs] = lex (dropWhile ((<>) '\n') xs)
+lex ['/':'*':xs] = \i.let (c, r) = span ((<>) ('*','/')) $ zip2 [' ':xs] xs in
+ lex (tl $ map snd $ tl $ r) (i + length [x\\(x, _)<-c | x == '\n'])
+lex ['v':'a':'r':xs] = ret VarToken xs
+lex ['V':'o':'i':'d':xs] = ret VoidToken xs
+lex ['r':'e':'t':'u':'r':'n':xs] = ret ReturnToken xs
+lex ['i':'f':xs] = ret IfToken xs
+lex ['e':'l':'s':'e':xs] = ret ElseToken xs
+lex ['w':'h':'i':'l':'e':xs] = ret WhileToken xs
+lex ['T':'r':'u':'e':xs] = ret TrueToken xs
+lex ['F':'a':'l':'s':'e':xs] = ret FalseToken xs
+lex ['I':'n':'t':xs] = ret IntTypeToken xs
+lex ['C':'h':'a':'r':xs] = ret CharTypeToken xs
+lex ['B':'o':'o':'l':xs] = ret BoolTypeToken xs
+lex [':':':':xs] = ret DoubleColonToken xs
+lex ['!':'=':xs] = ret NotEqualToken xs
+lex ['<':'=':xs] = ret LesserEqToken xs
+lex ['>':'=':xs] = ret GreaterEqToken xs
+lex ['=':'=':xs] = ret EqualsToken xs
+lex ['&':'&':xs] = ret AmpersandsToken xs
+lex ['|':'|':xs] = ret PipesToken xs
+lex ['-':'>':xs] = ret ArrowToken xs
+lex ['\'':x:'\'':xs] = ret (CharToken x) xs
lex ['\'':'\\':x:'\'':xs] = case get x EscapeMap of
- Just t = (Right (CharToken t), xs)
- _ = (Left ("Unknown escape: \\" +++ toString x), [])
+ Just t = ret (CharToken t) xs
+ _ = err ("Unknown escape: \\" +++ toString x)
lex ['-':t=:[x:xs]]
-| isDigit x = let (i, r) = span isDigit t in (Right (NumberToken ['-':i]), r)
-| otherwise = (Right DashToken, xs)
+| isDigit x = let (n, r) = span isDigit t in ret (NumberToken ['-':n]) r
+| otherwise = ret DashToken xs
lex t=:[x:xs] = case get x SingleCharTokens of
- (Just tok) = (Right tok, xs)
+ (Just tok) = ret tok xs
Nothing
+ | x == '\n' = \i.lex xs (i+1)
| isSpace x = lex xs
- | isDigit x = let (i, r) = span isDigit t in (Right (NumberToken i), r)
- | isAlpha x = let (i, r) = span isIdent t in (Right (IdentToken i), r)
+ | isDigit x = let (v, r) = span isDigit t in ret (NumberToken v) r
+ | isAlpha x = let (v, r) = span isIdent t in ret (IdentToken v) r
with isIdent c = isAlphanum c || c == '_'
- | otherwise = (Left ("Unexpected character: " +++ toString x), [])
+ | otherwise = err ("Unexpected character: " +++ toString x)
Link
LinkMethod: Static
GenerateRelocations: False
+ GenerateSymbolTable: False
GenerateLinkMap: False
LinkResources: False
ResourceSource:
Fusion: False
Module
Name: Control.Applicative
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Control.Monad
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Either
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Foldable
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Func
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Functor
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.List
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Map
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Maybe
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Monoid
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Set
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Traversable
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Data.Void
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: System.IO
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Text
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Text.JSON
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
Fusion: False
Module
Name: Text.PPrint
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False