| Copyright | ©2020 James Alexander Feldman-Crough |
|---|---|
| License | MPL-2.0 |
| Maintainer | alex@fldcr.com |
| Safe Haskell | None |
| Language | Haskell2010 |
Prosidy.Compile
Description
Synopsis
- escapeHatch :: (i -> f (Either (Error e) a)) -> RuleT i e f a
- getContent :: HasContent i => RuleT (Content i) e f a -> RuleT i e f a
- matchContent :: (Applicative f, Traversable t, HasContent i, t x ~ Content i, CanMatch x) => Match x e f a -> RuleT i e f (t a)
- optParse :: HasMetadata i => Key -> (Text -> Either String a) -> RuleT i e f (Maybe a)
- prop :: HasMetadata i => Key -> RuleT i e f Bool
- reqParse :: HasMetadata i => Key -> (Text -> Either String a) -> RuleT i e f a
- traversing :: Traversable t => RuleT i e f a -> RuleT (t i) e f (t a)
- self :: RuleT i e f i
- strict :: (Applicative f, HasMetadata i) => RuleT i e f a -> RuleT i e f a
- data RuleT input error context output
- type Rule input error = RuleT input error Identity
- class (forall i e. Functor (Pattern t i e), HasLocation t) => CanMatch t
- data Error a
- = Custom a
- | ParseError Key String
- | Required Key
- | ExpectedTag TagKind Key
- | ExpectedParagraph
- | ExpectedText
- | ExpectedBreak
- | EmptyMatch
- | UnknownMetadata (HashSet (MetadataKind, Key))
- | Group (Maybe Location) (ErrorSet a)
- data ErrorSet e
- type Error' = Error Void
- type ErrorSet' = ErrorSet Void
- class FromSetting a where
- fromSetting :: Text -> Either String a
- req :: (FromSetting a, HasMetadata i) => Key -> RuleT i e f a
- opt :: (FromSetting a, HasMetadata i) => Key -> RuleT i e f (Maybe a)
- module Prosidy.Compile.Match
- run :: IsError e => RuleT i e Identity a -> i -> Either (ErrorSet e) a
- runM :: (Applicative context, IsError e) => RuleT i e context a -> i -> context (Either (ErrorSet e) a)
Documentation
escapeHatch :: (i -> f (Either (Error e) a)) -> RuleT i e f a Source #
Do anything you want with a node. This should be used sparingly! The actions you perform inside of this function are invisible to inspection.
getContent :: HasContent i => RuleT (Content i) e f a -> RuleT i e f a Source #
Access the inner Content of a node.
matchContent :: (Applicative f, Traversable t, HasContent i, t x ~ Content i, CanMatch x) => Match x e f a -> RuleT i e f (t a) Source #
Traverse over each item in a node's Content via fallible matches.
optParse :: HasMetadata i => Key -> (Text -> Either String a) -> RuleT i e f (Maybe a) Source #
Parse an optional setting from a node with attached Metadata.
prop :: HasMetadata i => Key -> RuleT i e f Bool Source #
Check if a property is set on a node with attached Metadata.
reqParse :: HasMetadata i => Key -> (Text -> Either String a) -> RuleT i e f a Source #
Parse an required setting from a node with attached Metadata.
traversing :: Traversable t => RuleT i e f a -> RuleT (t i) e f (t a) Source #
Lift a RuleT so that it operates on a traversable structure.
strict :: (Applicative f, HasMetadata i) => RuleT i e f a -> RuleT i e f a Source #
Ensure that all properties and settings on a node are expected, and throw an error when extraneous metadata is attached. This is extremely useful for catching typos.
The matchers blockTag,
inlineTag, and literalTag
already match strictly: wrapping them in this combinator is unneccessary.
data RuleT input error context output Source #
A single compilation rule. Parameterized by the following types:
input: The type of the Prosidy node that is currently accessible.error: Allows users to specify a custom error type to be used for throwing errors.Voidcan be used to rely solely on the errors built into this library.context: AMonadfor performing contextual computation beyond what is provided by this library. If additional contextual computation is not desired, useIdentityas the type.output: The resulting output type.
Instances
| MonadTrans (RuleT input error) Source # | |
Defined in Prosidy.Compile.Core | |
| Functor (RuleT input error context) Source # | |
| Applicative (RuleT input error context) Source # | |
Defined in Prosidy.Compile.Core Methods pure :: a -> RuleT input error context a # (<*>) :: RuleT input error context (a -> b) -> RuleT input error context a -> RuleT input error context b # liftA2 :: (a -> b -> c) -> RuleT input error context a -> RuleT input error context b -> RuleT input error context c # (*>) :: RuleT input error context a -> RuleT input error context b -> RuleT input error context b # (<*) :: RuleT input error context a -> RuleT input error context b -> RuleT input error context a # | |
class (forall i e. Functor (Pattern t i e), HasLocation t) => CanMatch t Source #
A (lawless) typeclass for enabling fallible matching on nodes.
Implementing new instances of this class in library code is *unneccessary* and *unsupported*.
Minimal complete definition
Instances
| CanMatch Block Source # | |
Defined in Prosidy.Compile.Core | |
| CanMatch Inline Source # | |
Defined in Prosidy.Compile.Core | |
Enumerates the errors thrown when
Constructors
| Custom a | A custom error, allowing extensibility. |
| ParseError Key String | Thrown when parsing a setting fails. |
| Required Key | Thrown when a setting was required to be set, but wasn't provided. |
| ExpectedTag TagKind Key | Thrown when matching against a |
| ExpectedParagraph | Thrown when matching against paragraph and an unexpected node was encountered. |
| ExpectedText | Thrown when matching against text and an unexpected node was encountered. |
| ExpectedBreak | Thrown when matching against an explicit break and an unexpected node was encountered. |
| EmptyMatch | Thrown when a match has no cases to check against. |
| UnknownMetadata (HashSet (MetadataKind, Key)) | Thrown when an unknown property or setting is encountered when checking that properties and settings conform to strictly known keys. |
| Group (Maybe Location) (ErrorSet a) | Used to group a set of errors thrown at the same point in a tree. |
Instances
A non-empty set of errors.
Instances
| Eq e => Eq (ErrorSet e) Source # | |
| Show e => Show (ErrorSet e) Source # | |
| Generic (ErrorSet e) Source # | |
| IsError e => Semigroup (ErrorSet e) Source # | |
| Hashable e => Hashable (ErrorSet e) Source # | |
Defined in Prosidy.Compile.Error | |
| Exception e => Exception (ErrorSet e) Source # | |
Defined in Prosidy.Compile.Error Methods toException :: ErrorSet e -> SomeException # fromException :: SomeException -> Maybe (ErrorSet e) # displayException :: ErrorSet e -> String # | |
| type Rep (ErrorSet e) Source # | |
Defined in Prosidy.Compile.Error | |
class FromSetting a where Source #
A typeclass for parsing Prosidy settings into typed values. A default
instance exists for all types implementing Read.
Methods
fromSetting :: Text -> Either String a Source #
Given a Text value containing the setting, either parse a value
or return an error message explaining why the value is malformed.
Instances
| (Typeable a, Read a) => FromSetting a Source # | |
Defined in Prosidy.Compile.FromSetting | |
| FromSetting Text Source # | |
Defined in Prosidy.Compile.FromSetting | |
| FromSetting Text Source # | |
Defined in Prosidy.Compile.FromSetting | |
| FromSetting [Char] Source # | |
Defined in Prosidy.Compile.FromSetting | |
| (KnownSymbol delim, FromSetting a) => FromSetting (Sep delim a) Source # | |
Defined in Prosidy.Compile.FromSetting | |
req :: (FromSetting a, HasMetadata i) => Key -> RuleT i e f a Source #
Retrieve an required setting, parsing using its FromSetting instance.
opt :: (FromSetting a, HasMetadata i) => Key -> RuleT i e f (Maybe a) Source #
Retrieve an optional setting, parsing using its FromSetting instance.
module Prosidy.Compile.Match