]>
Commit | Line | Data |
---|---|---|
a9d77a20 FM |
1 | {-# LANGUAGE OverloadedStrings #-} |
2 | ||
3 | module Text.Edifact.Scaffolder.Commons.Formatters | |
4 | ( -- * | |
5 | fMessageCode | |
6 | , fMessageParserFunction | |
7 | , fGroupCode | |
8 | , fSegmentCode | |
9 | , fSegmentParserFunction | |
10 | , fCompositeCode | |
11 | , fCompositeParserFunction | |
12 | , fSimpleCode | |
13 | , fSimpleParserFunction | |
14 | ||
15 | -- * | |
16 | , fParserSignature | |
17 | , fParserDeclaration | |
18 | -- * | |
19 | , fModuleName | |
20 | , fPosition | |
21 | , fPresence | |
22 | -- * | |
23 | , quoted | |
24 | , simpleQuoted | |
25 | , parens | |
26 | , notYetImplemented | |
27 | ) where | |
28 | ||
29 | import Text.Edifact.Scaffolder.Commons.Types | |
30 | ||
31 | import Formatting as F | |
32 | ||
33 | fMessageCode:: Format r (MessageCode -> r) | |
34 | fMessageCode = mapf getMessageCode F.string | |
35 | ||
36 | fMessageParserFunction :: Format r (MessageCode -> r) | |
37 | fMessageParserFunction = mapf getMessageCode ("message" % F.string) | |
38 | ||
39 | fGroupCode :: Format r (GroupCode -> r) | |
40 | fGroupCode = mapf getGroupCode F.string | |
41 | ||
42 | fSegmentCode :: Format r (SegmentCode -> r) | |
43 | fSegmentCode = mapf getSegmentCode F.string | |
44 | ||
45 | fSegmentParserFunction :: Format r (SegmentCode -> r) | |
46 | fSegmentParserFunction = mapf getSegmentCode ("segment" % F.string) | |
47 | ||
48 | fCompositeCode :: Format r (CompositeCode -> r) | |
49 | fCompositeCode = mapf getCompositeCode F.string | |
50 | ||
51 | fCompositeParserFunction :: Format r (CompositeCode -> r) | |
52 | fCompositeParserFunction = mapf getCompositeCode ("composite" % F.string) | |
53 | ||
54 | fSimpleCode :: Format r (SimpleCode -> r) | |
55 | fSimpleCode = mapf getSimpleCode F.string | |
56 | ||
57 | fSimpleParserFunction :: Format r (SimpleCode -> r) | |
58 | fSimpleParserFunction = mapf getSimpleCode ("simple" % F.string) | |
59 | ||
60 | fParserSignature :: Format r a -> Format r a | |
61 | fParserSignature f = f % " :: Parser Value" | |
62 | ||
63 | fParserDeclaration :: Format r a -> Format r a | |
64 | fParserDeclaration f = f % " =" | |
65 | ||
66 | fModuleName :: Format r (ModuleName -> r) | |
67 | fModuleName = mapf getModuleName string | |
68 | ||
69 | fPosition :: Format r (Position -> r) | |
70 | fPosition = mapf getPosition F.string | |
71 | ||
72 | fPresence :: Format r (Presence -> r) | |
73 | fPresence = | |
74 | let f Mandatory = "mandatory" | |
75 | f Optional = "optional " | |
76 | in mapf f F.string | |
77 | ||
78 | quoted :: Format r a -> Format r a | |
79 | quoted f = "\"" % f % "\"" | |
80 | ||
81 | simpleQuoted :: Format r a -> Format r a | |
82 | simpleQuoted f = "'" % f % "'" | |
83 | ||
84 | parens :: Format r a -> Format r a | |
85 | parens f = "(" % f % ")" | |
86 | ||
87 | notYetImplemented :: Format r a -> Format r a | |
88 | notYetImplemented desc = "notYetImplemented " % quoted (desc % " not yet implemented") |