implementation module lex
import Control.Monad, Control.Applicative
-import Data.Either, Data.Maybe, Data.Map, Data.Func
-import StdString
-import StdTuple
-from StdFunc import const, o
+import Data.Either, Data.Func
+from StdFunc import o
import StdBool
import StdList
import StdChar
(Right p, _) = Right p
(Left e, _) = Left $ toString e
-trans1 :: Char a -> Parser Char a
-trans1 t r = item t >>| pure r
-
lexProgram :: Parser Char [Token]
-lexProgram = lexToken >>= \t->pure [(0, 0, t)]
+lexProgram = some lexToken >>= \ts->pure (map (\t->(0, 0, t)) ts)
lexToken :: Parser Char TokenValue
lexToken =
+ //Keyword tokens
(lexKw "var" VarToken) <|>
(lexKw "Void" VoidToken) <|>
(lexKw "return" ReturnToken) <|>
(lexKw "Int" IntTypeToken) <|>
(lexKw "Bool" BoolTypeToken) <|>
(lexKw "Char" CharTypeToken) <|>
- //Escape chars
+ //Escape chars tokens
(liftM CharToken $ item '\'' *> item '\\' *> lexEscape <* item '\'') <|>
- //Normal chars
+ //Normal chars tokens
(liftM CharToken $ item '\'' *> satisfy ((<>) '\'') <* item '\'') <|>
- (lexOp "::" DoubleColonToken) <|>
- (lexOp "!=" NotEqualToken) <|>
- (lexOp "<=" LesserEqToken) <|>
- (lexOp ">=" GreaterEqToken) <|>
- (lexOp "==" EqualsToken) <|>
- (lexOp "&&" AmpersandsToken) <|>
- (lexOp "||" PipesToken) <|>
- (lexOp "[]" EmptyListToken) <|>
- (lexOp "->" ArrowToken) <|>
- (lexOp "(" BraceOpenToken) <|>
- (lexOp ")" BraceCloseToken) <|>
- (lexOp "{" CBraceOpenToken) <|>
- (lexOp "}" CBraceCloseToken) <|>
- (lexOp "[" SquareOpenToken) <|>
- (lexOp "]" SquareCloseToken) <|>
- (lexOp "," CommaToken) <|>
- (lexOp ":" ColonToken) <|>
- (lexOp ";" SColonToken) <|>
- (lexOp "." DotToken) <|>
- (lexOp "+" PlusToken) <|>
- (lexOp "*" StarToken) <|>
- (lexOp "/" SlashToken) <|>
- (lexOp "%" PercentToken) <|>
- (lexOp "=" AssignmentToken) <|>
- (lexOp "<" LesserToken) <|>
- (lexOp ">" BiggerToken) <|>
- (lexOp "!" ExclamationToken) <|>
- (lexOp "-" DashToken) <|>
- //Numbers
+ //Two char ops tokens
+ (lexOp "::" DoubleColonToken) <|> (lexOp "!=" NotEqualToken) <|>
+ (lexOp "<=" LesserEqToken) <|> (lexOp ">=" GreaterEqToken) <|>
+ (lexOp "==" EqualsToken) <|> (lexOp "&&" AmpersandsToken) <|>
+ (lexOp "||" PipesToken) <|> (lexOp "[]" EmptyListToken) <|>
+ (lexOp "->" ArrowToken) <|> (lexOp "(" BraceOpenToken) <|>
+ //One char ops tokens
+ (lexOp ")" BraceCloseToken) <|> (lexOp "{" CBraceOpenToken) <|>
+ (lexOp "}" CBraceCloseToken) <|> (lexOp "[" SquareOpenToken) <|>
+ (lexOp "]" SquareCloseToken) <|> (lexOp "," CommaToken) <|>
+ (lexOp ":" ColonToken) <|> (lexOp ";" SColonToken) <|>
+ (lexOp "." DotToken) <|> (lexOp "+" PlusToken) <|>
+ (lexOp "*" StarToken) <|> (lexOp "/" SlashToken) <|>
+ (lexOp "%" PercentToken) <|> (lexOp "=" AssignmentToken) <|>
+ (lexOp "<" LesserToken) <|> (lexOp ">" BiggerToken) <|>
+ (lexOp "!" ExclamationToken) <|> (lexOp "-" DashToken) <|>
+ //Number tokens
(liftM (NumberToken o toInt o toString) $ some $ satisfy isDigit) <|>
- //Identifiersr
+ //Ident tokens
(liftM IdentToken $ some $ satisfy isIdentChar) <|>
- (satisfy isSpace >>| lexToken)
-
-lexEscape = (
- lexOp "a" (toChar 7) <|>
- lexOp "b" '\b' <|>
- lexOp "f" '\f' <|>
- lexOp "n" '\n' <|>
- lexOp "r" '\t' <|>
- lexOp "v" '\v' <|>
- lexOp "'" '\''
- ) <?> ("Unknown escape", 0)
-
-lexKw :: String a -> Parser Char a
-lexKw kw tv = list (fromString kw) <* check (not o isIdentChar) >>| pure tv
-
-lexOp :: String a -> Parser Char a
-lexOp s tv = list (fromString s) >>| pure tv
-
-isIdentChar :: Char -> Bool
-isIdentChar c = isAlphanum c || c == '_'
+ (satisfy isSpace >>| lexToken) //<|>
+// (eof >>| pure EndOfFileToken)
+ where
+ isIdentChar c = isAlphanum c || c == '_'
+ lexOp s tv = list (fromString s) >>| pure tv
+ lexKw kw tv = lexOp kw tv <* check (not o isIdentChar) >>| pure tv
+ lexEscape = (
+ lexOp "a" (toChar 7) <|> lexOp "b" '\b' <|> lexOp "f" '\f' <|>
+ lexOp "n" '\n' <|> lexOp "r" '\t' <|> lexOp "v" '\v' <|>
+ lexOp "'" '\'') <?> ("Unknown escape", 0)
Link
LinkMethod: Static
GenerateRelocations: False
- GenerateSymbolTable: False
GenerateLinkMap: False
LinkResources: False
ResourceSource:
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
- Module
- Name: StdOverloadedList
- Dir: {Application}/lib/StdEnv
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- Fusion: False
Module
Name: StdReal
Dir: {Application}/lib/StdEnv
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
- Module
- Name: StdStrictLists
- Dir: {Application}/lib/StdEnv
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- Fusion: False
Module
Name: StdString
Dir: {Application}/lib/StdEnv
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
- Module
- Name: _SystemEnumStrict
- Dir: {Application}/lib/StdEnv
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- Fusion: False
- Module
- Name: _SystemStrictLists
- Dir: {Application}/lib/StdEnv
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- Fusion: False
- Module
- Name: System.OS
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- Fusion: False
- Module
- Name: System.OS
- Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- 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
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
Fusion: False
Module
Name: Data.Either
- Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- 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
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
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
Fusion: False
Module
Name: Data.List
- Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- 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
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
Fusion: False
Module
Name: Data.Monoid
- Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- Fusion: False
- Module
- Name: Data.Set
- Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
- Compiler
- NeverMemoryProfile: False
- NeverTimeProfile: False
- StrictnessAnalysis: True
- ListTypes: StrictExportTypes
- ListAttributes: True
- Warnings: True
- Verbose: True
- ReadableABC: False
- ReuseUniqueNodes: True
- 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
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
Fusion: False
Module
Name: System.CommandLine
- 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
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
Fusion: False
Module
Name: System._Pointer
- 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
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
ReuseUniqueNodes: True
Fusion: False
Module
- Name: Text.JSON
- Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+ Name: System.OS
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
ReuseUniqueNodes: True
Fusion: False
Module
- Name: Text.PPrint
- Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent
+ Name: System.OS
+ Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
ReuseUniqueNodes: True
Fusion: False
Module
- Name: StdMaybe
- Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent/Deprecated/StdLib
+ Name: _SystemDynamic
+ Dir: {Application}/lib/iTasks-SDK/Patches/Dynamics
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
ReuseUniqueNodes: True
Fusion: False
Module
- Name: _SystemDynamic
- Dir: {Application}/lib/iTasks-SDK/Patches/Dynamics
+ Name: GenEq
+ Dir: {Application}/lib/iTasks-SDK/Patches/Generics
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
ReuseUniqueNodes: True
Fusion: False
Module
- Name: GenEq
+ Name: GenPrint
Dir: {Application}/lib/iTasks-SDK/Patches/Generics
Compiler
NeverMemoryProfile: False
ReuseUniqueNodes: True
Fusion: False
Module
- Name: GenPrint
- Dir: {Application}/lib/iTasks-SDK/Patches/Generics
+ Name: StdGeneric
+ Dir: {Application}/lib/iTasks-SDK/Patches/StdEnv
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
ReuseUniqueNodes: True
Fusion: False
Module
- Name: StdGeneric
- Dir: {Application}/lib/iTasks-SDK/Patches/StdEnv
+ Name: StdMaybe
+ Dir: {Application}/lib/iTasks-SDK/Server/lib
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False