module Data.Icao.Lang
( FreeText
, endOfFieldParser
, freeTextParser
, mkFreeText
) where
import Control.Monad.Fail
import Data.Aeromess.Parser
import Prelude hiding (fail)
newtype FreeText =
FreeText String
deriving (Eq, Show)
freeTextParser :: Parser FreeText
freeTextParser = fmap FreeText (some (noneOf "-/()"))
endOfFieldParser :: Parser ()
endOfFieldParser = do
d <- optional dash
case d of
Nothing -> return ()
Just _
-> do
_ <- lookAhead freeTextParser
return ()
mkFreeText
:: (MonadFail m)
=> String -> m FreeText
mkFreeText s
| null s = fail "empty free text"
| any (\c -> c == '/' || c == '-' || c == '(' || c == ')') s = fail ("invalid free text=" ++ s)
| otherwise = return (FreeText s)