From: Francis Russell Date: Thu, 20 Sep 2012 16:17:24 +0000 (+0100) Subject: Simplify index and value type parsing. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=f09aa1e6f77697958b50a834df08a455e5388971;p=francis%2Fofc.git Simplify index and value type parsing. --- diff --git a/src/Parser.hs b/src/Parser.hs index 13dd462..4692dbc 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -1,7 +1,6 @@ module Parser (runOFLParser) where import TopLevel import TargetMapping -import Data.List (foldl1') import Data.Functor.Identity (Identity) import Text.Parsec import Text.Parsec.Expr @@ -49,11 +48,16 @@ oflOperatorTable = [[Infix (do _ <- lSymbol "^"; return Power) AssocLeft], type OFLParser a = Parsec String OFL a +parseKeyword :: (OFLKeyword a) => a -> OFLParser a +parseKeyword k = do + lReserved $ toOFLString k + return k + parseType :: OFLParser BaseType -parseType = foldl1' (<|>) [do lReserved $ toOFLString t; return t | t <- [minBound::BaseType ..]] +parseType = choice $ map parseKeyword [minBound::BaseType ..] parseIndex :: OFLParser IndexType -parseIndex = foldl1' (<|>) [do lReserved $ toOFLString t; return t | t <- [minBound::IndexType ..]] +parseIndex = choice $ map parseKeyword [minBound::IndexType ..] parseDeclaration :: OFLParser () parseDeclaration = parseValueDeclaration <|> parseIndexDeclaration "declaration"