aboutsummaryrefslogtreecommitdiffhomepage
path: root/scaffolder/src/Text/Edifact/Scaffolder/Simples/Specification.hs
blob: 0651cbd50b760cb983ae9c51d8e226a953cb6c96 (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.Simples.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 [ simpleParser ]

simpleParser :: Parser (SimpleCode, SimpleName)
simpleParser = do
  _ <- count 3 (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