preamble
authorMart Lubbers <mart@martlubbers.net>
Fri, 1 Mar 2019 09:17:46 +0000 (10:17 +0100)
committerMart Lubbers <mart@martlubbers.net>
Fri, 1 Mar 2019 09:17:46 +0000 (10:17 +0100)
parse.icl
tests/preamble.mfp [new file with mode: 0644]

index 1a99e90..e17ad02 100644 (file)
--- a/parse.icl
+++ b/parse.icl
@@ -21,10 +21,7 @@ import ast
 derive gEq Token
 lex :: [Char] -> Either [String] [Token]
 lex [] = pure []
-lex ['=':ts] = TTEq <:> lex ts
 lex [';':ts] = TTSemiColon <:> lex ts
-lex ['\\':ts] = TTLambda <:> lex ts
-lex ['.':ts] = TTDot <:> lex ts
 lex [')':ts] = TTBrackClose <:> lex ts
 lex ['(':ts] = TTBrackOpen <:> lex ts
 lex ['True':ts] = TTBool True <:> lex ts
@@ -40,6 +37,9 @@ lex [t:ts]
                = TTInt (toInt (toString i)) <:> lex ts
        | isIdent t
                # (i, ts) = span isIdent [t:ts]
+               | i =: ['='] = TTEq <:> lex ts
+               | i =: ['.'] = TTDot <:> lex ts
+               | i =: ['\\'] = TTLambda <:> lex ts
                = TTIdent i <:> lex ts
        = Left ["Unexpected: " +++ toString t +++ " ord: " +++ toString (toInt t)]
 where
@@ -75,7 +75,7 @@ pChainr :: (Parser (a a -> a)) (Parser a) -> Parser a
 pChainr op p = flip ($) <$> p <*> (flip <$> op <*> pChainr op p) <|> p
 
 parse :: [Token] -> Either [String] AST
-parse ts = case runStateT (AST<$> pAST <* pEof) {zero & tokens=ts} of
+parse ts = case runStateT (AST <$> pAST <* pEof) {zero & tokens=ts} of
        Right (a, _) = Right a
        Left e = Left e
 where
diff --git a/tests/preamble.mfp b/tests/preamble.mfp
new file mode 100644 (file)
index 0000000..d89ffff
--- /dev/null
@@ -0,0 +1,7 @@
+$ ifxr 0 x y = x y;
+& ifxr 0 x y = y x;
+== ifxl 7 x y = eq x y;
+* ifxl 7 x y = mul x y;
+- ifxl 6 x y = sub x y;
++ ifxl 6 x y = add x y;
+start = 3 - 2 - 1;