From 0c1413c8daaec2986c878105f367d0d6649fcd1c Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Thu, 3 May 2007 02:58:17 +0000 Subject: [PATCH] Fix formal parsing --- fco2/Parse.hs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/fco2/Parse.hs b/fco2/Parse.hs index 788e317..813d710 100644 --- a/fco2/Parse.hs +++ b/fco2/Parse.hs @@ -1432,17 +1432,32 @@ formalList :: OccParser [A.Formal] formalList = do m <- md sLeftR - fs <- sepBy formalArgSet sComma + fs <- formalArgSet sRightR - return $ concat fs + return fs "formal list" formalItem :: OccParser (A.AbbrevMode, A.Type) -> OccParser A.Name -> OccParser [A.Formal] formalItem spec name = do (am, t) <- spec - ns <- sepBy1NE name sComma - return [A.Formal am t n | n <- ns] + names am t + where + names :: A.AbbrevMode -> A.Type -> OccParser [A.Formal] + names am t + = do n <- name + fs <- tail am t + return $ (A.Formal am t n) : fs + tail :: A.AbbrevMode -> A.Type -> OccParser [A.Formal] + tail am t + = do sComma + -- We must try formalArgSet first here, so that we don't + -- accidentally parse a DATA TYPE name thinking it's a formal + -- name. + formalArgSet <|> names am t + <|> return [] + +-- | Parse a set of formal arguments. formalArgSet :: OccParser [A.Formal] formalArgSet = formalItem formalVariableType newVariableName