1 {-# LANGUAGE FlexibleContexts #-}
2 module Hcompta.Format.JCC.Common.Read where
4 import Control.Applicative ((<$>))
5 import Control.Monad (void)
7 import Data.Char (Char)
8 import qualified Data.Char
9 import Data.String (fromString)
10 import Data.Text (Text)
11 import Data.Typeable ()
13 import qualified Text.Parsec as R hiding
26 import Text.Parsec (Stream, ParsecT, (<|>), (<?>))
28 import qualified Hcompta.Lib.Parsec as R
32 is_space :: Char -> Bool
34 case Data.Char.generalCategory c of
35 Data.Char.Space -> True
37 space :: Stream s m Char => ParsecT s u m Char
38 space = R.satisfy is_space
40 is_char :: Char -> Bool
42 case Data.Char.generalCategory c of
43 Data.Char.UppercaseLetter -> True
44 Data.Char.LowercaseLetter -> True
45 Data.Char.TitlecaseLetter -> True
46 Data.Char.ModifierLetter -> True
47 Data.Char.OtherLetter -> True
49 Data.Char.NonSpacingMark -> True
50 Data.Char.SpacingCombiningMark -> True
51 Data.Char.EnclosingMark -> True
53 Data.Char.DecimalNumber -> True
54 Data.Char.LetterNumber -> True
55 Data.Char.OtherNumber -> True
57 Data.Char.ConnectorPunctuation -> True
58 Data.Char.DashPunctuation -> True
59 Data.Char.OpenPunctuation -> True
60 Data.Char.ClosePunctuation -> True
61 Data.Char.InitialQuote -> True
62 Data.Char.FinalQuote -> True
63 Data.Char.OtherPunctuation -> True
65 Data.Char.MathSymbol -> True
66 Data.Char.CurrencySymbol -> True
67 Data.Char.ModifierSymbol -> True
68 Data.Char.OtherSymbol -> True
70 Data.Char.Space -> False
71 Data.Char.LineSeparator -> False
72 Data.Char.ParagraphSeparator -> False
73 Data.Char.Control -> False
74 Data.Char.Format -> False
75 Data.Char.Surrogate -> False
76 Data.Char.PrivateUse -> False
77 Data.Char.NotAssigned -> False
78 char :: Stream s m Char => ParsecT s u m Char
79 char = R.satisfy is_char
81 is_char_active :: Char -> Bool
113 char_active :: Stream s m Char => ParsecT s u m Char
114 char_active = R.satisfy is_char_active
116 is_char_passive :: Char -> Bool
118 is_char c && not (is_char_active c)
119 char_passive :: Stream s m Char => ParsecT s u m Char
120 char_passive = R.satisfy is_char_passive
122 word :: Stream s m Char => ParsecT s u m Text
123 word = fromString <$> R.many char_passive
125 words :: Stream s m Char => ParsecT s u m [Text]
126 words = R.many_separated word space
128 name :: Stream s m Char => ParsecT s u m Text
129 name = fromString <$> R.many1 char_passive
131 tabulation :: Stream s m Char => ParsecT s u m Char
132 tabulation = R.char '\t'
134 hspace :: Stream s m Char => ParsecT s u m Char
137 hspaces :: Stream s m Char => ParsecT s u m ()
138 hspaces = void $ R.many hspace
140 hspaces1 :: Stream s m Char => ParsecT s u m ()
141 hspaces1 = void $ R.many1 hspace
143 eol :: Stream s m Char => ParsecT s u m ()
144 eol = ((R.<|>) (void $ R.char '\n') (void $ R.try $ R.string "\r\n")) <?> "eol"
146 line :: Stream s m Char => ParsecT s u m Text
148 fromString <$> R.manyTill char (R.lookAhead eol <|> R.eof)
149 -- R.many (R.notFollowedBy eol >> char)