-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Parser and interpreter of OpenStreetMap conditional restriction values -- -- Please see the README on GitHub at -- https://github.com/geometalab/conditional-restriction-parser#readme @package conditional-restriction-parser @version 0.1.0.5 -- | AST for conditional restrictions and incomplete AST for opening hours. module ConditionalRestriction.Parse.AST -- | A single token. Is used to represent values of any kind that the -- parser does not touch. type Token = String -- | AST representation of a conditional restriction. newtype ConditionalRestriction ConditionalRestriction :: [Expression] -> ConditionalRestriction -- | AST representation of a conditional restriction expression, containing -- a value and conditions for that value data Expression Expression :: Token -> [Condition] -> Expression -- | AST representation of a condition. data Condition -- | An OpeningHours condition. When evaluating, the given time must -- be within those opening hours. OH :: OpeningHours -> Condition -- | A comparison. Looks something like "weight > 3.0" Comparison :: Token -> ComparisonOp -> Double -> Condition -- | An absolute condition, e.g. "wet", "disabled". Absolute :: Token -> Condition -- | A comparison operator. data ComparisonOp Gt :: ComparisonOp Lt :: ComparisonOp GtEq :: ComparisonOp LtEq :: ComparisonOp Eq :: ComparisonOp -- | AST representation of opening hours. Not complete. newtype OpeningHours OpeningHours :: [RuleSequence] -> OpeningHours -- | Opening hour state. True/False if known to be open/closed, Nothing if -- unknown. type OHState = Maybe Bool -- | Type of opening hour rule. data RuleType -- | First rule or rules separated by ";". Normal :: RuleType -- | Rules separated by ",". Additional :: RuleType -- | AST representation of a rule sequence. data RuleSequence RuleSequence :: RuleType -> SelectorSequence -> OHState -> RuleSequence -- | AST representation of a weekday selector (e.g. "Sa-Di, Th"). type WeekdaySelector = [WeekdayRange] -- | AST representation of a time selector (e.g. "18:00-20:00, -- 21:00-03:00"). type TimeSelector = [TimeSpan] -- | AST representation of a selector sequence (e.g. "24/7", -- "We-Su 18:00-20:00"). data SelectorSequence TwentyFourSeven :: SelectorSequence WeekdaySel :: WeekdaySelector -> SelectorSequence TimeSel :: TimeSelector -> SelectorSequence WeekdayTime :: WeekdaySelector -> TimeSelector -> SelectorSequence -- | AST representation of a weekday range. data WeekdayRange SingleDay :: WeekDay -> WeekdayRange WdayRange :: WeekDay -> WeekDay -> WeekdayRange -- | AST representation of time span. data TimeSpan Moment :: TimeOfDay -> TimeSpan Span :: TimeOfDay -> TimeOfDay -> TimeSpan instance GHC.Show.Show ConditionalRestriction.Parse.AST.ComparisonOp instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.ComparisonOp instance GHC.Show.Show ConditionalRestriction.Parse.AST.RuleType instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.RuleType instance GHC.Show.Show ConditionalRestriction.Parse.AST.WeekdayRange instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.WeekdayRange instance GHC.Show.Show ConditionalRestriction.Parse.AST.TimeSpan instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.TimeSpan instance GHC.Show.Show ConditionalRestriction.Parse.AST.SelectorSequence instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.SelectorSequence instance GHC.Show.Show ConditionalRestriction.Parse.AST.RuleSequence instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.RuleSequence instance GHC.Show.Show ConditionalRestriction.Parse.AST.OpeningHours instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.OpeningHours instance GHC.Show.Show ConditionalRestriction.Parse.AST.Condition instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.Condition instance GHC.Show.Show ConditionalRestriction.Parse.AST.Expression instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.Expression instance GHC.Show.Show ConditionalRestriction.Parse.AST.ConditionalRestriction instance GHC.Classes.Eq ConditionalRestriction.Parse.AST.ConditionalRestriction -- | Input data types and values. module ConditionalRestriction.Parse.InputData -- | An identifier, identifying a value, e.g. "weight". type ID = String -- | Input data type. data Type -- | Boolean type, e.g. value "true". TBool :: Type -- | Number type, e.g. value "3.0". TNum :: Type -- | Time type, e.g. value "2022-05-10 18:00". TTime :: Type -- | Input data value, corresponding to input Types. data Value -- | Boolean value, e.g. "true". VBool :: Bool -> Value -- | Number value, e.g. "3.0". VNum :: Double -> Value -- | Time value, e.g. "2022-05-10 18:00". VTime :: DateTime -> Value instance GHC.Show.Show ConditionalRestriction.Parse.InputData.Type instance GHC.Classes.Eq ConditionalRestriction.Parse.InputData.Type instance GHC.Show.Show ConditionalRestriction.Parse.InputData.Value instance GHC.Classes.Eq ConditionalRestriction.Parse.InputData.Value -- | A simple result type. Similar to the Either type, but tuned for -- results with an error type. module ConditionalRestriction.Result -- | The Result type consists of an error type e and a -- success type a. data Result e a Err :: e -> Result e a Ok :: a -> Result e a -- | Result equivalent to fromMaybe. fromResult :: a -> Result e a -> a instance (GHC.Show.Show e, GHC.Show.Show a) => GHC.Show.Show (ConditionalRestriction.Result.Result e a) instance (GHC.Classes.Eq e, GHC.Classes.Eq a) => GHC.Classes.Eq (ConditionalRestriction.Result.Result e a) instance GHC.Base.Functor (ConditionalRestriction.Result.Result e) instance Data.Bifunctor.Bifunctor ConditionalRestriction.Result.Result instance GHC.Base.Applicative (ConditionalRestriction.Result.Result e) instance GHC.Base.Monad (ConditionalRestriction.Result.Result e) -- | Parsing library. Implements a simple Parser type, and some -- basic parsers, e.g. ws, dbl. module ConditionalRestriction.Internal.Parse.ParserLib -- | A generic parser. Takes an input type i and returns an output -- type a. newtype Parser i a Parser :: (i -> Result String (a, i)) -> Parser i a [parse] :: Parser i a -> i -> Result String (a, i) str :: String -> Parser String String anyOf :: [Char] -> Parser String Char noneOf :: [Char] -> Parser String Char ws :: Parser String String word :: String -> Parser String String tok :: Parser String String dbl :: Parser String Double bint :: Int -> Parser String Int end :: Parser String () shorten :: Int -> String -> String strip :: String -> String instance GHC.Base.Functor (ConditionalRestriction.Internal.Parse.ParserLib.Parser i) instance GHC.Base.Applicative (ConditionalRestriction.Internal.Parse.ParserLib.Parser i) instance GHC.Base.Alternative (ConditionalRestriction.Internal.Parse.ParserLib.Parser i) instance GHC.Base.Monad (ConditionalRestriction.Internal.Parse.ParserLib.Parser i) -- | Parsing library. Implements a simple Parser type. module ConditionalRestriction.Parse.ParserLib -- | A generic parser. Takes an input type i and returns an output -- type a. data Parser i a parse :: Parser i a -> i -> Result String (a, i) -- | Parsers for input data values. module ConditionalRestriction.Parse.InputDataParser -- | Parses Values. See pBool, pNum and pTime -- for formats. pValue :: Parser String Value -- | Parses boolean values. Possible values are "true" and -- "false". pBool :: Parser String Value -- | Parses numbers. Values can be with or without decimal places, i.e. -- "5" or "5.34". pNum :: Parser String Value -- | Parses time and date in the format "YYYY-MM-DD hh:mm". pTime :: Parser String Value -- | Parser for opening hours (incomplete). module ConditionalRestriction.Internal.Parse.OpeningHoursParser -- | Parse opening hours, e.g. "Di-Fr 08:00-20:00". pOpeningHours :: Parser String OpeningHours pRuleSequence :: RuleType -> Parser String RuleSequence pRuleModifier :: Parser String OHState pSelectorSequence :: Parser String SelectorSequence pWeekdaySelector :: Parser String WeekdaySelector pTimeSelector :: Parser String TimeSelector pWeekdayRange :: Parser String WeekdayRange pWday :: Parser String WeekDay pTimeSpan :: Parser String TimeSpan pTime :: Bool -> Parser String TimeOfDay pComment :: Parser String String -- | Parser for opening hours (incomplete). module ConditionalRestriction.Parse.OpeningHoursParser -- | Parse opening hours, e.g. "Di-Fr 08:00-20:00". pOpeningHours :: Parser String OpeningHours -- | Parser for conditional restrictions. module ConditionalRestriction.Internal.Parse.RestrictionParser -- | Parse conditional restrictions, e.g. "90 @ 18:00-22:00; 50 @ -- wet". pConditionalRestriction :: Parser String ConditionalRestriction pExpression :: Parser String Expression pMultipleConditions :: Parser String [Condition] pCondition :: Parser String Condition pCompOperator :: Parser String ComparisonOp pIdentifier :: Parser String String -- | Parser for conditional restrictions. module ConditionalRestriction.Parse.RestrictionParser -- | Parse conditional restrictions, e.g. "90 @ 18:00-22:00; 50 @ -- wet". pConditionalRestriction :: Parser String ConditionalRestriction pCondition :: Parser String Condition -- | This module reexports functions and types you are most likely to use -- from ConditionalRestriction.Parse.*. module ConditionalRestriction.Parse -- | A generic parser. Takes an input type i and returns an output -- type a. data Parser i a parse :: Parser i a -> i -> Result String (a, i) -- | Parse conditional restrictions, e.g. "90 @ 18:00-22:00; 50 @ -- wet". pConditionalRestriction :: Parser String ConditionalRestriction pCondition :: Parser String Condition -- | Parses Values. See pBool, pNum and pTime -- for formats. pValue :: Parser String Value -- | Parse opening hours, e.g. "Di-Fr 08:00-20:00". pOpeningHours :: Parser String OpeningHours -- | AST representation of a conditional restriction. data ConditionalRestriction -- | AST representation of a condition. data Condition -- | AST representation of opening hours. Not complete. data OpeningHours -- | An identifier, identifying a value, e.g. "weight". type ID = String -- | Input data value, corresponding to input Types. data Value -- | Boolean value, e.g. "true". VBool :: Bool -> Value -- | Number value, e.g. "3.0". VNum :: Double -> Value -- | Time value, e.g. "2022-05-10 18:00". VTime :: DateTime -> Value -- | Input data type. data Type -- | Boolean type, e.g. value "true". TBool :: Type -- | Number type, e.g. value "3.0". TNum :: Type -- | Time type, e.g. value "2022-05-10 18:00". TTime :: Type -- | A single token. Is used to represent values of any kind that the -- parser does not touch. type Token = String -- | Functions to evaluate conditional restrictions. module ConditionalRestriction.Internal.Evaluate -- | Plain text error message. type ErrorMsg = String -- | The result function takes input data in the form of (ID, -- Value) and a ConditionalRestriction and returns the -- result of that ConditionalRestriction when applied to the input -- data given. If data needed for the evaluation is missing or of the -- wrong type, it will return a list of error messages and a list of -- missing data types instead. -- -- Note that this function will accept incomplete data if it is enough to -- evaluate the expression, but will always return a complete list of -- needed data types. result :: [(ID, Value)] -> ConditionalRestriction -> Result ([ErrorMsg], [(ID, Type)]) (Maybe Token) -- | The fulfills function takes input data in the form of -- (ID, Value) and a Condition and returns whether -- that condition is fulfilled. If some data is missing, it will return -- the missing data ID and Type and if the given data is of -- the wrong type, it will return an error message. fulfills :: [(ID, Value)] -> Condition -> Result (Either ErrorMsg (ID, Type)) Bool -- | The timeIn function returns wheter a DateTime is within -- given OpeningHours. Unknown values count as not within the -- opening hours. timeIn :: DateTime -> OpeningHours -> Bool ohTimes :: OpeningHours -> [TimeSelector] timeInSelector :: TimeOfDay -> TimeSelector -> Bool timeExtendedInSelector :: TimeOfDay -> TimeSelector -> Bool addTimespan :: TimeSpan -> TimeSelector -> TimeSelector subtractTimespan :: TimeSpan -> TimeSelector -> TimeSelector explicitExtended :: TimeSpan -> TimeSpan mapDays :: [WeekDay] -> (a -> a) -> [a] -> [a] combineWeekdays :: WeekdaySelector -> [WeekDay] range :: (Ord a, Enum a, Bounded a) => a -> a -> [a] -- | Functions to evaluate conditional restrictions. module ConditionalRestriction.Evaluate -- | Plain text error message. type ErrorMsg = String -- | The result function takes input data in the form of (ID, -- Value) and a ConditionalRestriction and returns the -- result of that ConditionalRestriction when applied to the input -- data given. If data needed for the evaluation is missing or of the -- wrong type, it will return a list of error messages and a list of -- missing data types instead. -- -- Note that this function will accept incomplete data if it is enough to -- evaluate the expression, but will always return a complete list of -- needed data types. result :: [(ID, Value)] -> ConditionalRestriction -> Result ([ErrorMsg], [(ID, Type)]) (Maybe Token) -- | The fulfills function takes input data in the form of -- (ID, Value) and a Condition and returns whether -- that condition is fulfilled. If some data is missing, it will return -- the missing data ID and Type and if the given data is of -- the wrong type, it will return an error message. fulfills :: [(ID, Value)] -> Condition -> Result (Either ErrorMsg (ID, Type)) Bool -- | The timeIn function returns wheter a DateTime is within -- given OpeningHours. Unknown values count as not within the -- opening hours. timeIn :: DateTime -> OpeningHours -> Bool -- | The ConditionalRestriction library offers functionality for parsing -- and evaluating of conditional restriction values (see OSM -- Wiki). -- -- This module offers functions suitable for most basic use cases. module ConditionalRestriction -- | Takes a conditional restriction string and returns the data needed in -- order to evaluate this string. If the conditional restriction couldn't -- be parsed, an error message is returned instead. needsData :: String -> Result ErrorMsg [(ID, Type)] -- | Takes a conditional restriction string and some input data. It returns -- the value as a token if any restriction condition was met, or -- Nothing otherwise. If there was a parsing error or a problem -- with the provided data, a list of error messages and a list of needed -- data is returned. evaluate :: String -> [(ID, String)] -> Result ([ErrorMsg], [(ID, Type)]) (Maybe Token) -- | Takes a conditional restriction string and returns the corresponding -- AST. Take a look at the ConditionalRestriction.Parse.AST module -- for AST manipulation. parseRestriction :: String -> Result ErrorMsg ConditionalRestriction -- | An identifier, identifying a value, e.g. "weight". type ID = String -- | Input data value, corresponding to input Types. data Value -- | Boolean value, e.g. "true". VBool :: Bool -> Value -- | Number value, e.g. "3.0". VNum :: Double -> Value -- | Time value, e.g. "2022-05-10 18:00". VTime :: DateTime -> Value -- | Input data type. data Type -- | Boolean type, e.g. value "true". TBool :: Type -- | Number type, e.g. value "3.0". TNum :: Type -- | Time type, e.g. value "2022-05-10 18:00". TTime :: Type -- | A single token. Is used to represent values of any kind that the -- parser does not touch. type Token = String -- | The Result type consists of an error type e and a -- success type a. data Result e a Err :: e -> Result e a Ok :: a -> Result e a -- | Plain text error message. type ErrorMsg = String