1 {-# LANGUAGE OverloadedStrings #-}
3 module Text.Edifact.Scaffolder.Simples.Representation
9 import Text.Edifact.Scaffolder.Commons
10 import Text.Edifact.Scaffolder.Simples.Types
12 import Text.Parsec as P (char, choice,
16 import Text.Parsec.String (Parser)
18 extractRepresentation :: FilePath -> Scaffolding (Maybe Representation)
19 extractRepresentation file =
20 let parser = skipBeginning representationParser
21 in liftIO (readFile file) >>= maybeParse file parser
23 contentParser :: Parser Content
25 choice [ AlphaNumeric <$ try (P.string "an")
26 , Alpha <$ P.string "a"
27 , Numeric <$ P.string "n"
30 cardinalityParser :: Parser Cardinality
33 choice [ Exactly <$> (optional space *> numberParser)
34 , UpTo <$> (dot *> dot *> numberParser)
37 numberParser :: Parser Int
38 numberParser = read <$> many1 digit
43 representationParser :: Parser Representation
44 representationParser =
45 let parser = Representation <$> contentParser
47 in P.string "Repr:" *> space *> parser