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
= 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
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