Safe Haskell | None |
---|---|
Language | Haskell2010 |
Attribute grammars with regular expression matching.
- type Action c f inh syn = Fix f -> inh -> Map c syn -> (Bool, Map c inh, syn)
- type Rule c f inh syn = (Regex c f, Action c f inh syn)
- type Grammar c f inh syn = [Rule c f inh syn]
- eval :: (Ord c, Matchable f, Monoid syn) => Grammar c f inh syn -> inh -> Fix f -> syn
- rule :: RuleBuilder f inh syn fn r => fn -> r
- check :: Bool -> State (ActionState Integer inh syn) ()
- (->>>) :: Monoid syn => (forall k. Regex' k Integer f) -> (Fix f -> State (ActionState Integer inh syn) ()) -> [Integer] -> Rule Integer f inh syn
- (->>) :: Monoid syn => (forall k. Regex' k Integer f) -> State (ActionState Integer inh syn) () -> [Integer] -> Rule Integer f inh syn
- this :: Functor f => ((inh, syn) -> f (inh, syn)) -> ActionState c inh syn -> f (ActionState c inh syn)
- at :: (Ord c, Functor f) => c -> ((inh, syn) -> f (inh, syn)) -> ActionState c inh syn -> f (ActionState c inh syn)
- inh :: Functor f => (inh -> f inh) -> (inh, syn) -> f (inh, syn)
- syn :: Functor f => (syn -> f syn) -> (inh, syn) -> f (inh, syn)
Basic blocks
type Action c f inh syn = Fix f -> inh -> Map c syn -> (Bool, Map c inh, syn) Source
Actions create new inherited attributes for their children, and synthesized attribute for its own node, from the synthesized attributes of children and the inheritance from its parent. Additionally, actions may include an explicit backtrack.
type Rule c f inh syn = (Regex c f, Action c f inh syn) Source
A rule comprises the regular expression to match and the action to execute if successful.
eval :: (Ord c, Matchable f, Monoid syn) => Grammar c f inh syn -> inh -> Fix f -> syn Source
Evaluate an attribute grammar over a certain term.
Nice syntax for defining rules
rule :: RuleBuilder f inh syn fn r => fn -> r Source
Converts a rule description into an actual Rule
.
Its use must follow this pattern:
- A block of lambda-bound variables will introduce the capture names,
- A tree regular expression to match should capture using the previous names,
- After
->>>
or->>
, the state calculation should proceed.
rule $ \c1 c2 -> regex ... c1 <<- ... c2 <<- ... ->> do at c2 . inh .= ... -- Set inherited for children c1Syn <- use (at c1 . syn) -- Get synthesized from children this . syn .= ... -- Set upwards synthesized attributes
Combinators
check :: Bool -> State (ActionState Integer inh syn) () Source
Makes the attribute calculation fail if the condition is false. This function can be used to add extra conditions over whether a certain rule should be applied (a bit like guards).
(->>>) :: Monoid syn => (forall k. Regex' k Integer f) -> (Fix f -> State (ActionState Integer inh syn) ()) -> [Integer] -> Rule Integer f inh syn Source
Separates matching and attribute calculation on a rule. The action should take as extra parameter the node which was matched.
(->>) :: Monoid syn => (forall k. Regex' k Integer f) -> State (ActionState Integer inh syn) () -> [Integer] -> Rule Integer f inh syn Source
Separates matching and attribute calculation on a rule.
Special lenses
this :: Functor f => ((inh, syn) -> f (inh, syn)) -> ActionState c inh syn -> f (ActionState c inh syn) Source
at :: (Ord c, Functor f) => c -> ((inh, syn) -> f (inh, syn)) -> ActionState c inh syn -> f (ActionState c inh syn) Source