From: Mart Lubbers Date: Mon, 29 Feb 2016 19:21:38 +0000 (+0100) Subject: hoi X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=6c1945d3b85c0bf8ff2d56b4a6fb456d07a7282a;p=cc1516.git hoi --- diff --git a/src/lex.icl b/src/lex.icl index 8aae65a..a6f31ab 100644 --- a/src/lex.icl +++ b/src/lex.icl @@ -1,10 +1,8 @@ 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 @@ -16,14 +14,12 @@ lexer r = case runParser lexProgram r of (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) <|> @@ -35,59 +31,37 @@ lexToken = (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) diff --git a/src/main.prj b/src/main.prj index f0b6422..d7bf8d0 100644 --- a/src/main.prj +++ b/src/main.prj @@ -31,7 +31,6 @@ Global Link LinkMethod: Static GenerateRelocations: False - GenerateSymbolTable: False GenerateLinkMap: False LinkResources: False ResourceSource: @@ -294,20 +293,6 @@ OtherModules 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 @@ -322,20 +307,6 @@ OtherModules 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 @@ -392,65 +363,9 @@ OtherModules 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 @@ -464,7 +379,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 @@ -478,21 +393,7 @@ OtherModules 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 @@ -506,7 +407,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 @@ -520,7 +421,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 @@ -534,21 +435,7 @@ OtherModules 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 @@ -562,7 +449,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 @@ -576,35 +463,7 @@ OtherModules 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 @@ -618,7 +477,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 @@ -632,7 +491,7 @@ OtherModules 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 @@ -646,7 +505,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 @@ -660,7 +519,7 @@ OtherModules 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 @@ -674,7 +533,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 @@ -687,8 +546,8 @@ OtherModules 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 @@ -701,8 +560,8 @@ OtherModules 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 @@ -715,8 +574,8 @@ OtherModules 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 @@ -729,8 +588,8 @@ OtherModules 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 @@ -743,7 +602,7 @@ OtherModules ReuseUniqueNodes: True Fusion: False Module - Name: GenEq + Name: GenPrint Dir: {Application}/lib/iTasks-SDK/Patches/Generics Compiler NeverMemoryProfile: False @@ -757,8 +616,8 @@ OtherModules 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 @@ -771,8 +630,8 @@ OtherModules 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 diff --git a/src/parse.icl b/src/parse.icl index 56bc554..042ec47 100644 --- a/src/parse.icl +++ b/src/parse.icl @@ -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