ogma-language-xmlspec-1.10.0: Ogma: Runtime Monitor translator: XML Frontend

Safe Haskell | Safe-Inferred
Language | Haskell2010

Language.XMLSpec.Parser

Contents

- Auxiliary

Description

Parser for Ogma specs stored in XML files.

Synopsis

- data XMLFormat = XMLFormat {
  - specInternalVars :: Maybe String
  - specInternalVarId :: (String, Maybe (String, String))
  - specInternalVarExpr :: (String, Maybe (String, String))
  - specInternalVarType :: Maybe (String, Maybe (String, String))
  - specExternalVars :: Maybe String
  - specExternalVarId :: (String, Maybe (String, String))
  - specExternalVarType :: Maybe (String, Maybe (String, String))
  - specRequirements :: (String, Maybe (String, String))
  - specRequirementId :: (String, Maybe (String, String))
  - specRequirementDesc :: Maybe (String, Maybe (String, String))
  - specRequirementExpr :: (String, Maybe (String, String))
  - specRequirementResultType :: Maybe (String, Maybe (String, String))
  - specRequirementResultExpr :: Maybe (String, Maybe (String, String))
  }
- parseXMLSpec :: (String -> IO (Either String a)) -> a -> XMLFormat -> String -> IO (Either String (Spec a))
- data XMLFormatInternal = XMLFormatInternal {
  - xfiInternalVars :: Maybe XPathExpr
  - xfiInternalVarId :: XPathExpr
  - xfiInternalVarExpr :: XPathExpr
  - xfiInternalVarType :: Maybe XPathExpr
  - xfiExternalVars :: Maybe XPathExpr
  - xfiExternalVarId :: XPathExpr
  - xfiExternalVarType :: Maybe XPathExpr
  - xfiRequirements :: XPathExpr
  - xfiRequirementId :: XPathExpr
  - xfiRequirementDesc :: Maybe XPathExpr
  - xfiRequirementExpr :: [XPathExpr]
  - xfiRequirementResultType :: Maybe XPathExpr
  - xfiRequirementResultExpr :: Maybe XPathExpr
  }
- type XPathExpr = String
- resolveIndirectly :: String -> (String, Maybe (String, String)) -> ExceptT String IO XPathExpr
- resolveIndirectly' :: String -> (String, Maybe (String, String)) -> ExceptT String IO [XPathExpr]
- checkXPathExpr :: String -> Either String XPathExpr
- parseXMLFormat :: XMLFormat -> String -> ExceptT String IO XMLFormatInternal
- executeXPath :: String -> String -> IO [String]
- textUnescape :: String -> String
- swapMaybeEither :: Maybe (Either a b) -> Either a (Maybe b)
- swapMaybeExceptT :: Monad m => Maybe (ExceptT a m b) -> ExceptT a m (Maybe b)
- listToEither :: String -> [String] -> Either String String
- replace :: String -> String -> String -> String
- concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]

# Documentation

data XMLFormat Source #

List of XPath routes to the elements we need to parse.

The optional paths denote elements that may not exist. If they are nothing, those elements are not parsed in the input file.

The subfields are applied on each string matching the parent element. That is, the internal var ID XPath will be a applied to the strings returned when applying the internal vars XPath (if it exists). Paths whose names are plural denote expected lists of elements.

The components of a tuple (String, Maybe (String, String)) mean the following: if a string is present but the second component is Nothing, then the string is the XPath expression to be used. If a Just value is present, the first element of its inner tuple represents a key, and the second element represents an XPath expression that will produce a value when evaluated globally in the file. After evaluating that expression, the key must be found in the first string of the three and replaced with the result of evaluating the expression.

Constructors

XMLFormat |

Fields

- specInternalVars :: Maybe String
- specInternalVarId :: (String, Maybe (String, String))
- specInternalVarExpr :: (String, Maybe (String, String))
- specInternalVarType :: Maybe (String, Maybe (String, String))
- specExternalVars :: Maybe String
- specExternalVarId :: (String, Maybe (String, String))
- specExternalVarType :: Maybe (String, Maybe (String, String))
- specRequirements :: (String, Maybe (String, String))
- specRequirementId :: (String, Maybe (String, String))
- specRequirementDesc :: Maybe (String, Maybe (String, String))
- specRequirementExpr :: (String, Maybe (String, String))
- specRequirementResultType :: Maybe (String, Maybe (String, String))
- specRequirementResultExpr :: Maybe (String, Maybe (String, String))

#### Instances

Instances details

Read XMLFormat Source # |
Instance details Defined in Language.XMLSpec.Parser Methods readsPrec :: Int -> ReadS XMLFormat Source # readList :: ReadS [XMLFormat] Source # readPrec :: ReadPrec XMLFormat Source # readListPrec :: ReadPrec [XMLFormat] Source #
Show XMLFormat Source # |
Instance details Defined in Language.XMLSpec.Parser Methods showsPrec :: Int -> XMLFormat -> ShowS Source # show :: XMLFormat -> String Source # showList :: [XMLFormat] -> ShowS Source #

parseXMLSpec Source #

Arguments

:: (String -> IO (Either String a)) | Parser for expressions.
-> a |
-> XMLFormat | XPaths for spec locations.
-> String | String containing XML
-> IO (Either String (Spec a)) |

Parse an XML file and extract a Spec from it.

An auxiliary function must be provided to parse the requirement expressions.

Fails if any of the XPaths in the argument XMLFormat are not valid expressions, of the XML is malformed, or if the elements are not found with the frequency expected (e.g., an external variable id is not found even though external variables are found).

data XMLFormatInternal Source #

Internal representation of an XML Format specification.

Constructors

XMLFormatInternal |

Fields

- xfiInternalVars :: Maybe XPathExpr
- xfiInternalVarId :: XPathExpr
- xfiInternalVarExpr :: XPathExpr
- xfiInternalVarType :: Maybe XPathExpr
- xfiExternalVars :: Maybe XPathExpr
- xfiExternalVarId :: XPathExpr
- xfiExternalVarType :: Maybe XPathExpr
- xfiRequirements :: XPathExpr
- xfiRequirementId :: XPathExpr
- xfiRequirementDesc :: Maybe XPathExpr
- xfiRequirementExpr :: [XPathExpr]
- xfiRequirementResultType :: Maybe XPathExpr
- xfiRequirementResultExpr :: Maybe XPathExpr

type XPathExpr = String Source #

Internal representation of an XPath expression.

resolveIndirectly :: String -> (String, Maybe (String, String)) -> ExceptT String IO XPathExpr Source #

Resolve an indirect XPath query, returning an XPath expression.

resolveIndirectly' :: String -> (String, Maybe (String, String)) -> ExceptT String IO [XPathExpr] Source #

Resolve an indirect XPath query, returning a list of XPath expressions.

checkXPathExpr :: String -> Either String XPathExpr Source #

Check that an XPath expression is syntactically correct.

parseXMLFormat :: XMLFormat -> String -> ExceptT String IO XMLFormatInternal Source #

Check an XMLFormat and return an internal representation.

Fails with an error message if any of the given expressions are not a valid XPath expression.

executeXPath :: String -> String -> IO [String] Source #

Execute an XPath query in an XML string, returning the list of strings that match the path.

# Auxiliary

textUnescape :: String -> String Source #

Unescape ``<``, ``>`` and ``&`` in a string.

swapMaybeEither :: Maybe (Either a b) -> Either a (Maybe b) Source #

Swap the Maybe and Either layers of a value.

swapMaybeExceptT :: Monad m => Maybe (ExceptT a m b) -> ExceptT a m (Maybe b) Source #

Swap the Maybe and Either layers of a value.

listToEither :: String -> [String] -> Either String String Source #

Convert a list to an Either, failing if the list provided does not have exactly one value.

replace :: String -> String -> String -> String Source #

Replace a string by another string

concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] Source #

Map a monadic action over the elements of a container and concatenate the resulting lists.