conditional-restriction-parser-0.1.0.5: Parser and interpreter of OpenStreetMap conditional restriction values
Safe HaskellSafe-Inferred
LanguageHaskell2010

ConditionalRestriction

Description

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.

Synopsis

Documentation

needsData :: String -> Result ErrorMsg [(ID, Type)] Source #

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.

evaluate :: String -> [(ID, String)] -> Result ([ErrorMsg], [(ID, Type)]) (Maybe Token) Source #

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.

parseRestriction :: String -> Result ErrorMsg ConditionalRestriction Source #

Takes a conditional restriction string and returns the corresponding AST. Take a look at the ConditionalRestriction.Parse.AST module for AST manipulation.

type ID = String Source #

An identifier, identifying a value, e.g. "weight".

data Value Source #

Input data value, corresponding to input Types.

Constructors

VBool Bool

Boolean value, e.g. "true".

VNum Double

Number value, e.g. "3.0".

VTime DateTime

Time value, e.g. "2022-05-10 18:00".

Instances

Instances details
Show Value Source # 
Instance details

Defined in ConditionalRestriction.Parse.InputData

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

Eq Value Source # 
Instance details

Defined in ConditionalRestriction.Parse.InputData

Methods

(==) :: Value -> Value -> Bool #

(/=) :: Value -> Value -> Bool #

data Type Source #

Input data type.

Constructors

TBool

Boolean type, e.g. value "true".

TNum

Number type, e.g. value "3.0".

TTime

Time type, e.g. value "2022-05-10 18:00".

Instances

Instances details
Show Type Source # 
Instance details

Defined in ConditionalRestriction.Parse.InputData

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

Eq Type Source # 
Instance details

Defined in ConditionalRestriction.Parse.InputData

Methods

(==) :: Type -> Type -> Bool #

(/=) :: Type -> Type -> Bool #

type Token = String Source #

A single token. Is used to represent values of any kind that the parser does not touch.

data Result e a Source #

The Result type consists of an error type e and a success type a.

Constructors

Err e 
Ok a 

Instances

Instances details
Bifunctor Result Source # 
Instance details

Defined in ConditionalRestriction.Result

Methods

bimap :: (a -> b) -> (c -> d) -> Result a c -> Result b d #

first :: (a -> b) -> Result a c -> Result b c #

second :: (b -> c) -> Result a b -> Result a c #

Applicative (Result e) Source # 
Instance details

Defined in ConditionalRestriction.Result

Methods

pure :: a -> Result e a #

(<*>) :: Result e (a -> b) -> Result e a -> Result e b #

liftA2 :: (a -> b -> c) -> Result e a -> Result e b -> Result e c #

(*>) :: Result e a -> Result e b -> Result e b #

(<*) :: Result e a -> Result e b -> Result e a #

Functor (Result e) Source # 
Instance details

Defined in ConditionalRestriction.Result

Methods

fmap :: (a -> b) -> Result e a -> Result e b #

(<$) :: a -> Result e b -> Result e a #

Monad (Result e) Source # 
Instance details

Defined in ConditionalRestriction.Result

Methods

(>>=) :: Result e a -> (a -> Result e b) -> Result e b #

(>>) :: Result e a -> Result e b -> Result e b #

return :: a -> Result e a #

(Show e, Show a) => Show (Result e a) Source # 
Instance details

Defined in ConditionalRestriction.Result

Methods

showsPrec :: Int -> Result e a -> ShowS #

show :: Result e a -> String #

showList :: [Result e a] -> ShowS #

(Eq e, Eq a) => Eq (Result e a) Source # 
Instance details

Defined in ConditionalRestriction.Result

Methods

(==) :: Result e a -> Result e a -> Bool #

(/=) :: Result e a -> Result e a -> Bool #

type ErrorMsg = String Source #

Plain text error message.