aboutsummaryrefslogtreecommitdiffhomepage
path: root/scaffolder/src/Text/Edifact/Scaffolder/CodedSimples/Specification.hs
blob: 967f685744c9ada0b326a690ac2df86915d7bee1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Text.Edifact.Scaffolder.CodedSimples.Specification
  ( -- *
    specificationParser
  ) where

import           Text.Edifact.Scaffolder.Commons

import           Text.Parsec                     as P (anyChar, count, digit,
                                                       endOfLine, manyTill,
                                                       oneOf, skipMany, string,
                                                       try)
import           Text.Parsec.String              (Parser)

specificationParser :: Parser (SimpleCode, SimpleName)
specificationParser = scanUntil [ codedSimpleParser ]

codedSimpleParser :: Parser (SimpleCode, SimpleName)
codedSimpleParser = do
  _ <- count 2 (oneOf "+*#|-X ")
  skipMany (string " ")
  code <- simpleCodeParser
  _ <- string " "
  skipMany (string " ")
  name <- SimpleName <$> manyTill anyChar (() <$ try endOfLine)
  pure (code, name)

simpleCodeParser :: Parser SimpleCode
simpleCodeParser = fromString <$> count 4 digit