module Lasercutter
(
Parser
, runParser
, IsTree (..)
, self
, proj
, expect
, one
, try
, empty
, (<|>)
, onChildren
, onSingleChild
, target
, targetMap
, when
, whenNode
, ifS
, ifNode
, breadcrumbs
, onBreadcrumbs
, mapBreadcrumbs
, dimap
, rmap
, lmap
, liftA2
, optional
, guard
, asum
, mapMaybe
, catMaybes
, select
, (<*?)
, branch
, fromMaybeS
, orElse
, andAlso
, (<||>)
, (<&&>)
, foldS
, anyS
, allS
, bindS
) where
import Control.Applicative
import Control.Monad (guard)
import Control.Selective
import Data.Foldable (asum)
import Data.Maybe (listToMaybe, isJust)
import Lasercutter.Internal
import Lasercutter.Types
import Prelude hiding (filter)
import Witherable (Filterable (..))
import Data.Profunctor
proj :: (t -> a) -> Parser bc t a
proj :: (t -> a) -> Parser bc t a
proj t -> a
f = (t -> a) -> Parser bc t t -> Parser bc t a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap t -> a
f Parser bc t t
forall bc t. Parser bc t t
self
onChildren :: Parser bc t a -> Parser bc t [a]
onChildren :: Parser bc t a -> Parser bc t [a]
onChildren = Parser bc t a -> Parser bc t [a]
forall bc t a. Parser bc t a -> Parser bc t [a]
OnChildren
target :: (t -> Bool) -> Parser bc t a -> Parser bc t [a]
target :: (t -> Bool) -> Parser bc t a -> Parser bc t [a]
target = (t -> Bool) -> Parser bc t a -> Parser bc t [a]
forall t bc a. (t -> Bool) -> Parser bc t a -> Parser bc t [a]
Target
breadcrumbs :: Parser bc t bc
breadcrumbs :: Parser bc t bc
breadcrumbs = Parser bc t bc
forall bc t. Parser bc t bc
GetCrumbs
onBreadcrumbs :: (bc -> a) -> Parser bc t a
onBreadcrumbs :: (bc -> a) -> Parser bc t a
onBreadcrumbs bc -> a
f = (bc -> a) -> Parser bc t bc -> Parser bc t a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap bc -> a
f Parser bc t bc
forall bc t. Parser bc t bc
breadcrumbs
onSingleChild :: Parser bc t a -> Parser bc t (Maybe a)
onSingleChild :: Parser bc t a -> Parser bc t (Maybe a)
onSingleChild = ([a] -> Maybe a) -> Parser bc t [a] -> Parser bc t (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> Maybe a
forall a. [a] -> Maybe a
listToMaybe (Parser bc t [a] -> Parser bc t (Maybe a))
-> (Parser bc t a -> Parser bc t [a])
-> Parser bc t a
-> Parser bc t (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser bc t a -> Parser bc t [a]
forall bc t a. Parser bc t a -> Parser bc t [a]
onChildren
self :: Parser bc t t
self :: Parser bc t t
self = Parser bc t t
forall bc t. Parser bc t t
Current
one :: Parser bc t [a] -> Parser bc t a
one :: Parser bc t [a] -> Parser bc t a
one = Parser bc t (Maybe a) -> Parser bc t a
forall bc t a. Parser bc t (Maybe a) -> Parser bc t a
expect (Parser bc t (Maybe a) -> Parser bc t a)
-> (Parser bc t [a] -> Parser bc t (Maybe a))
-> Parser bc t [a]
-> Parser bc t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> Maybe a) -> Parser bc t [a] -> Parser bc t (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> Maybe a
forall a. [a] -> Maybe a
listToMaybe
when
:: Parser bc t Bool
-> Parser bc t a
-> Parser bc t a
when :: Parser bc t Bool -> Parser bc t a -> Parser bc t a
when Parser bc t Bool
b Parser bc t a
tr = Parser bc t (Maybe a) -> Parser bc t a
forall bc t a. Parser bc t (Maybe a) -> Parser bc t a
expect (Parser bc t (Maybe a) -> Parser bc t a)
-> Parser bc t (Maybe a) -> Parser bc t a
forall a b. (a -> b) -> a -> b
$ Parser bc t Bool
-> Parser bc t (Maybe a)
-> Parser bc t (Maybe a)
-> Parser bc t (Maybe a)
forall (f :: * -> *) a. Selective f => f Bool -> f a -> f a -> f a
ifS Parser bc t Bool
b ((a -> Maybe a) -> Parser bc t a -> Parser bc t (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just Parser bc t a
tr) (Parser bc t (Maybe a) -> Parser bc t (Maybe a))
-> Parser bc t (Maybe a) -> Parser bc t (Maybe a)
forall a b. (a -> b) -> a -> b
$ Maybe a -> Parser bc t (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
ifNode
:: (t -> Bool)
-> Parser bc t a
-> Parser bc t a
-> Parser bc t a
ifNode :: (t -> Bool) -> Parser bc t a -> Parser bc t a -> Parser bc t a
ifNode t -> Bool
f Parser bc t a
tr Parser bc t a
fl = Parser bc t Bool -> Parser bc t a -> Parser bc t a -> Parser bc t a
forall (f :: * -> *) a. Selective f => f Bool -> f a -> f a -> f a
ifS ((t -> Bool) -> Parser bc t Bool
forall t a bc. (t -> a) -> Parser bc t a
proj t -> Bool
f) Parser bc t a
tr Parser bc t a
fl
whenNode :: (t -> Bool) -> Parser bc t a -> Parser bc t a
whenNode :: (t -> Bool) -> Parser bc t a -> Parser bc t a
whenNode = Parser bc t Bool -> Parser bc t a -> Parser bc t a
forall bc t a. Parser bc t Bool -> Parser bc t a -> Parser bc t a
when (Parser bc t Bool -> Parser bc t a -> Parser bc t a)
-> ((t -> Bool) -> Parser bc t Bool)
-> (t -> Bool)
-> Parser bc t a
-> Parser bc t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> Bool) -> Parser bc t Bool
forall t a bc. (t -> a) -> Parser bc t a
proj
targetMap :: (t -> Maybe a) -> Parser bc t [a]
targetMap :: (t -> Maybe a) -> Parser bc t [a]
targetMap t -> Maybe a
f = ([Maybe a] -> [a]) -> Parser bc t [Maybe a] -> Parser bc t [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes (Parser bc t [Maybe a] -> Parser bc t [a])
-> Parser bc t [Maybe a] -> Parser bc t [a]
forall a b. (a -> b) -> a -> b
$ (t -> Bool) -> Parser bc t (Maybe a) -> Parser bc t [Maybe a]
forall t bc a. (t -> Bool) -> Parser bc t a -> Parser bc t [a]
target (Maybe a -> Bool
forall a. Maybe a -> Bool
isJust (Maybe a -> Bool) -> (t -> Maybe a) -> t -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Maybe a
f) (Parser bc t (Maybe a) -> Parser bc t [Maybe a])
-> Parser bc t (Maybe a) -> Parser bc t [Maybe a]
forall a b. (a -> b) -> a -> b
$ (t -> Maybe a) -> Parser bc t (Maybe a)
forall t a bc. (t -> a) -> Parser bc t a
proj t -> Maybe a
f