}
return list;
}
-//deze comment eindigt met EOF ipv newline
\ No newline at end of file
+//deze comment eindigt met EOF ipv newline
:: Token :== (Int, Int, TokenValue)
:: TokenValue
//Value tokens
- = IdentToken [Char] // Identifier
+ = IdentToken String // Identifier
| NumberToken Int // Integer
| CharToken Char // Character literal
//Keyword tokens
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 =
//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
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
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
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:
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
ReuseUniqueNodes: True
Fusion: False
Module
- Name: GenPrint
+ Name: GenEq
Dir: {Application}/lib/iTasks-SDK/Patches/Generics
Compiler
NeverMemoryProfile: False
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
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
parseProgram :: Parser Token AST
parseProgram = liftM2 AST (many parseVarDecl) (some parseFunDecl)
-// <* satTok EndOfFileToken
+ <* satTok EndOfFileToken
parseFunDecl :: Parser Token FunDecl
parseFunDecl = liftM5 FunDecl
(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 (