]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Simplify index and value type parsing.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 20 Sep 2012 16:17:24 +0000 (17:17 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 20 Sep 2012 16:17:24 +0000 (17:17 +0100)
src/Parser.hs

index 13dd462d9e8f36f26671431d92acde2aa70ef5a7..4692dbcd433f94b400a286b6436409247354ae48 100644 (file)
@@ -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"