From 32dbc6423c325fc9210d43e7cabef1bd65cc212f Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Fri, 1 Mar 2019 10:17:46 +0100 Subject: [PATCH] preamble --- parse.icl | 8 ++++---- tests/preamble.mfp | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 tests/preamble.mfp diff --git a/parse.icl b/parse.icl index 1a99e90..e17ad02 100644 --- 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 index 0000000..d89ffff --- /dev/null +++ b/tests/preamble.mfp @@ -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; -- 2.20.1