module Parser (runOFLParser) where
import TopLevel
import TargetMapping
-import Data.List (foldl1')
import Data.Functor.Identity (Identity)
import Text.Parsec
import Text.Parsec.Expr
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"