From f09aa1e6f77697958b50a834df08a455e5388971 Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Thu, 20 Sep 2012 17:17:24 +0100 Subject: [PATCH] Simplify index and value type parsing. --- src/Parser.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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" -- 2.47.3