X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=src%2Fparse.icl;h=042ec474e2270fa34c0d127c2f9793e82b4f4fcb;hb=7c16c9353b324301ee8c028e39c33aa2a46895f8;hp=d64efcb97c7111b3854e014200a8dc5808b38c38;hpb=43d45105726b3ad3e5cc5165f8c9b066ec8d2790;p=cc1516.git diff --git a/src/parse.icl b/src/parse.icl index d64efcb..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 @@ -151,8 +151,7 @@ parseVarDef = liftM2 VarDef (parseIdent >>= \i.if (i == "snd") (pure FieldSnd) empty)))) parseOp1 :: Parser Token Op1 -parseOp1 = trans1 DashToken UnMinus <|> - trans1 ExclamationToken UnNegation +parseOp1 = trans1 DashToken UnMinus <|> trans1 ExclamationToken UnNegation parseBBraces :: (Parser Token a) -> Parser Token a parseBBraces p = satTok BraceOpenToken *> p <* satTok BraceCloseToken @@ -169,7 +168,7 @@ parseTuple p = satTok BraceOpenToken *> <* satTok BraceCloseToken trans2 :: TokenValue (TokenValue -> a) -> Parser Token a -trans2 t f = satTok t >>= \(_, r).pure (f r) +trans2 t f = liftM (f o thd3) $ satTok t trans1 :: TokenValue a -> Parser Token a trans1 t r = trans2 t $ const r @@ -177,14 +176,14 @@ trans1 t r = trans2 t $ const r derive gPrint TokenValue derive gEq TokenValue satTok :: TokenValue -> Parser Token Token -satTok t = top >>= \tok=:(pos, tv) -> if (eq t tok) +satTok t = top >>= \tok=:(pos1, pos2, tv) -> if (eq t tok) (return tok) - (fail (printToString tv+++printToString t, pos)) + (fail (printToString tv+++printToString t, pos1)) where - eq (IdentToken _) (_, IdentToken _) = True - eq (NumberToken _) (_, NumberToken _) = True - eq (CharToken _) (_, CharToken _) = True - eq x (_, y) = gEq {|*|} x y + eq (IdentToken _) (_, _, IdentToken _) = True + eq (NumberToken _) (_, _, NumberToken _) = True + eq (CharToken _) (_, _, CharToken _) = True + eq x (_, _, y) = gEq {|*|} x y parseSepList :: TokenValue (Parser Token a) -> Parser Token [a] parseSepList sep p =