AspectAG-0.6.0.0: Strongly typed Attribute Grammars implemented using type-level programming.

Copyright(c) Juan García-Garland Marcos Viera 2019 2020
LicenseGPL
Maintainerjpgarcia@fing.edu.uy
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Language.Grammars.AspectAG

Contents

Description

 
Synopsis

Rules

type Rule (prd :: Prod) (sc :: [(Child, [(Att, Type)])]) (ip :: [(Att, Type)]) (ic :: [(Child, [(Att, Type)])]) (sp :: [(Att, Type)]) (ic' :: [(Child, [(Att, Type)])]) (sp' :: [(Att, Type)]) = Fam prd sc ip -> Fam prd ic sp -> Fam prd ic' sp' Source #

Rules are a function from the input family to the output family, with an extra arity to make them composable. They are indexed by a production.

newtype CRule (ctx :: [ErrorMessage]) prd sc ip ic sp ic' sp' Source #

Rules with context (used to print domain specific type errors).

Constructors

CRule 

Fields

Defining Rules

syndef :: Syndef t t' ctx ctx' att sp sp' prd => forall sc ip ic. Label (Att att t) -> Label prd -> (Proxy ctx' -> Fam prd sc ip -> t') -> CRule ctx prd sc ip ic sp ic sp' Source #

The function syndef adds the definition of a synthesized attribute. It takes an attribute label att representing the name of the new attribute; a production label prd representing the production where the rule is defined; a value t' to be assigned to this attribute, given a context and an input family. It updates the output constructed thus far.

syndefM :: Syndef t t' ctx ctx' att sp sp' prd => Label (Att att t) -> Label prd -> Reader (Proxy ctx', Fam prd sc ip) t' -> CRule ctx prd sc ip ic sp ic sp' Source #

As syndef, the function syndefM adds the definition of a synthesized attribute. It takes an attribute label att representing the name of the new attribute; a production label prd representing the production where the rule is defined; a value t' to be assigned to this attribute, given a context and an input family. It updates the output constructed thus far. This function captures the monadic behaviour of the family updating. For instance, the following definition specifies a rule for an attribute `att_size :: Label (Att "size" Int)` at the prduction `p_cons :: Label (Prd "cons" (NT List))`. The value is computed from the very same attribute value at a child `ch_tail :: Chi "tail" (Prd "cons" (NT List) (Left NT))`

foo = syndefM att_size p_cons $ do sizeatchi <- at ch_tail att_size
                                   return (sizeatchi + 1)

syn :: (Require (OpExtend AttReco (Att att t') t' sp) ctx, ReqR (OpExtend AttReco (Att att t') t' sp) ~# Rec AttReco sp') => Label (Att att t') -> Label prd -> Reader (Proxy (((((Text "syndef(" :<>: (((Text "Attribute " :<>: Text att) :<>: Text ":") :<>: ShowType t')) :<>: Text ", ") :<>: ShowTE prd) :<>: Text ")") ': ctx), Fam prd sc ip) t' -> CRule ctx prd sc ip ic sp ic sp' Source #

This is simply an alias for syndefM

synmod :: RequireR (OpUpdate AttReco (Att att t) t r) ctx (Attribution sp') => Label (Att att t) -> Label prd -> (Proxy (((((Text "synmod(" :<>: ShowTE (Att att t)) :<>: Text ", ") :<>: ShowTE prd) :<>: Text ")") ': ctx) -> Fam prd sc ip -> t) -> CRule ctx prd sc ip ic' r ic' sp' Source #

synmodM :: RequireR (OpUpdate AttReco (Att att t) t r) ctx (Attribution sp') => Label (Att att t) -> Label prd -> Reader (Proxy (((((Text "synmod(" :<>: ShowTE (Att att t)) :<>: Text ", ") :<>: ShowTE prd) :<>: Text ")") ': ctx), Fam prd sc ip) t -> CRule ctx prd sc ip ic' r ic' sp' Source #

inh :: (Require (OpExtend AttReco (Att att t') t' r) ctx, Require (OpUpdate (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) (Left n :: Either NT T)) v2 ic) ctx, Require (OpLookup (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) (Left n :: Either NT T)) ic) ctx, ReqR (OpLookup (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) (Left n :: Either NT T)) ic) ~# Rec AttReco r, ReqR (OpExtend AttReco (Att att t') t' r) ~# Rec AttReco v2, ReqR (OpUpdate (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) (Left n :: Either NT T)) v2 ic) ~# Rec (ChiReco (Prd prd nt)) ic') => Label (Att att t') -> Label (Prd prd nt) -> Label (Chi chi (Prd prd nt) (Left n :: Either NT T)) -> Reader (Proxy (((((((Text "inhdef(" :<>: (((Text "Attribute " :<>: Text att) :<>: Text ":") :<>: ShowType t')) :<>: Text ", ") :<>: ((ShowTE nt :<>: Text "::Production ") :<>: Text prd)) :<>: Text ", ") :<>: ((((((ShowTE nt :<>: Text "::Production ") :<>: Text prd) :<>: Text "::Child ") :<>: Text chi) :<>: Text ":") :<>: ShowTE n)) :<>: Text ")") ': ctx), Fam (Prd prd nt) sc ip) t' -> CRule ctx (Prd prd nt) sc ip ic sp ic' sp Source #

This is simply an alias for inhdefM

inhdef :: Inhdef t t' ctx ctx' att r v2 prd nt chi ntch ic ic' n => Label (Att att t) -> Label (Prd prd nt) -> Label (Chi chi (Prd prd nt) ntch) -> (Proxy ctx' -> Fam (Prd prd nt) sc ip -> t') -> forall sp. CRule ctx (Prd prd nt) sc ip ic sp ic' sp Source #

inhdefM :: Inhdef t t' ctx ctx' att r v2 prd nt chi ntch ic ic' n => Label (Att att t) -> Label (Prd prd nt) -> Label (Chi chi (Prd prd nt) ntch) -> Reader (Proxy ctx', Fam (Prd prd nt) sc ip) t' -> CRule ctx (Prd prd nt) sc ip ic sp ic' sp Source #

inhmod :: (RequireEq t t' ctx', RequireR (OpUpdate AttReco (Att att t) t r) ctx (Attribution v2), RequireR (OpUpdate (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) ntch) v2 ic) ctx (ChAttsRec (Prd prd nt) ic'), RequireR (OpLookup (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) ntch) ic) ctx (Attribution r), RequireEq ntch (Left n) ctx', ctx' ~ (((((((Text "inhmod(" :<>: ShowTE (Att att t)) :<>: Text ", ") :<>: ShowTE (Prd prd nt)) :<>: Text ", ") :<>: ShowTE (Chi chi (Prd prd nt) ntch)) :<>: Text ")") ': ctx)) => Label (Att att t) -> Label (Prd prd nt) -> Label (Chi chi (Prd prd nt) ntch) -> (Proxy ctx' -> Fam (Prd prd nt) sc ip -> t') -> CRule ctx (Prd prd nt) sc ip ic sp ic' sp Source #

inhmodM :: (RequireEq t t' ctx', RequireR (OpUpdate AttReco (Att att t) t r) ctx (Attribution v2), RequireR (OpUpdate (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) ntch) v2 ic) ctx (ChAttsRec (Prd prd nt) ic'), RequireR (OpLookup (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) ntch) ic) ctx (Attribution r), RequireEq ntch (Left n) ctx', ctx' ~ (((((((Text "inhmod(" :<>: ShowTE (Att att t)) :<>: Text ", ") :<>: ShowTE (Prd prd nt)) :<>: Text ", ") :<>: ShowTE (Chi chi (Prd prd nt) ntch)) :<>: Text ")") ': ctx)) => Label (Att att t) -> Label (Prd prd nt) -> Label (Chi chi (Prd prd nt) ntch) -> Reader (Proxy ctx', Fam (Prd prd nt) sc ip) t' -> CRule ctx (Prd prd nt) sc ip ic sp ic' sp Source #

emptyRule :: CRule ctx prd sc ip ic' sp' ic' sp' Source #

emptyRuleAtPrd :: Label prd -> CRule ctx prd sc ip ic' sp' ic' sp' Source #

ext :: RequireEq prd prd' (Text "ext" ': ctx) => CRule ctx prd sc ip ic sp ic' sp' -> CRule ctx prd' sc ip a b ic sp -> CRule ctx prd sc ip a b ic' sp' Source #

Given two rules for a given (the same) production, it combines them. Note that the production equality is visible in the context, not sintactically. This is a use of the Require pattern.

Aspects

Building Aspects.

emptyAspect :: CAspect ctx '[] Source #

Recall that Aspects are mappings from productions to rules. They have a record-like interface to build them. This is the constructor for the empty Aspect.

singAsp :: CRule ctx prd sc ip ic sp ic' sp' -> CAspect ctx ((,) prd (CRule ctx prd sc ip ic sp ic' sp') ': ([] :: [(Prod, Type)])) Source #

Singleton Aspect. Wraps a rule to build an Aspect from it.

extAspect :: ExtAspect ctx prd sc ip ic sp ic' sp' a asp => CRule ctx prd sc ip ic sp ic' sp' -> CAspect ctx a -> CAspect ctx asp Source #

The "cons" for CAspects. It adds a Rule rule to a CAspect. If there is no rule for that production in the argument it is a record extension. If the production is there, the rules are combined.

comAspect :: (Require (OpComAsp al ar) ctx, ReqR (OpComAsp al ar) ~ Aspect asp) => CAspect ctx al -> CAspect ctx ar -> CAspect ctx asp Source #

combination of two Aspects. It merges them. When both aspects have rules for a given production, in the resulting Aspect the rule at that field is the combination of the rules for the arguments (with ext).

(.+:) :: (Require (OpComRA ctx prd (CRule ctx prd sc ip ic sp ic' sp') a) ctx, ReqR (OpComRA ctx prd (CRule ctx prd sc ip ic sp ic' sp') a) ~# Rec PrdReco asp) => CRule ctx prd sc ip ic sp ic' sp' -> CAspect ctx a -> CAspect ctx asp infixr 3 Source #

An operator, alias for extAspect. It combines a rule with an aspect, to build a bigger one.

(◃) :: (Require (OpComRA ctx prd (CRule ctx prd sc ip ic sp ic' sp') a) ctx, ReqR (OpComRA ctx prd (CRule ctx prd sc ip ic sp ic' sp') a) ~# Rec PrdReco asp) => CRule ctx prd sc ip ic sp ic' sp' -> CAspect ctx a -> CAspect ctx asp infixr 3 Source #

Unicode version of extAspect or .+: (\triangleleft)

(.:+.) :: (Require (OpComRA ctx prd (CRule ctx prd sc ip ic sp ic' sp') a) ctx, ReqR (OpComRA ctx prd (CRule ctx prd sc ip ic sp ic' sp') a) ~# Rec PrdReco asp) => CAspect ctx a -> CRule ctx prd sc ip ic sp ic' sp' -> CAspect ctx asp infixl 3 Source #

The other way, combines an aspect with a rule. It is a flipped extAspect.

(▹) :: (Require (OpComRA ctx prd (CRule ctx prd sc ip ic sp ic' sp') a) ctx, ReqR (OpComRA ctx prd (CRule ctx prd sc ip ic sp ic' sp') a) ~# Rec PrdReco asp) => CAspect ctx a -> CRule ctx prd sc ip ic sp ic' sp' -> CAspect ctx asp infixl 3 Source #

Unicode operator for .:+. or `flip extAspect`.

(.:+:) :: (Require (OpComAsp al ar) ctx, ReqR (OpComAsp al ar) ~# Rec PrdReco asp) => CAspect ctx al -> CAspect ctx ar -> CAspect ctx asp infixr 4 Source #

Operator for comAspect. It takes two CAspects to build the combination of both.

(⋈) :: (Require (OpComAsp al ar) ctx, ReqR (OpComAsp al ar) ~# Rec PrdReco asp) => CAspect ctx al -> CAspect ctx ar -> CAspect ctx asp infixr 4 Source #

Unicode operator for comAspect or .:+:. (\bowtie)

newtype CAspect (ctx :: [ErrorMessage]) (asp :: [(Prod, Type)]) Source #

Aspects, tagged with context. Aspect is a record instance having productions as labels, containing Rules as fields.

Constructors

CAspect 

Fields

data Label (l :: k) :: forall k. k -> Type #

Constructors

Label 

data Prod Source #

Constructors

Prd Symbol NT 
Instances
type ShowTE (Prd l nt :: Prod) Source # 
Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type ShowTE (Prd l nt :: Prod) = (ShowTE nt :<>: Text "::Production ") :<>: Text l
type Cmp (Prd a _1 :: Prod) (Prd b _2 :: Prod) Source # 
Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type Cmp (Prd a _1 :: Prod) (Prd b _2 :: Prod) = CmpSymbol a b

data T Source #

Constructors

T Type 
Instances
type ShowTE (T l :: T) Source # 
Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type ShowTE (T l :: T) = Text "Terminal " :<>: ShowTE l

data NT Source #

Constructors

NT Symbol 
Instances
type ShowTE (NT l :: NT) Source # 
Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type ShowTE (NT l :: NT) = Text "Non-Terminal " :<>: Text l

data Child Source #

Constructors

Chi Symbol Prod (Either NT T) 
Instances
type ShowTE (Chi l p s :: Child) Source # 
Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type ShowTE (Chi l p s :: Child) = (((ShowTE p :<>: Text "::Child ") :<>: Text l) :<>: Text ":") :<>: ShowTE s
type Cmp (Chi a _1 _2 :: Child) (Chi b _3 _4 :: Child) Source # 
Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type Cmp (Chi a _1 _2 :: Child) (Chi b _3 _4 :: Child) = CmpSymbol a b

data Att Source #

Constructors

Att Symbol Type 
Instances
type ShowTE (Att l t :: Att) Source # 
Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type ShowTE (Att l t :: Att) = ((Text "Attribute " :<>: Text l) :<>: Text ":") :<>: ShowTE t
type Cmp (Att a _1 :: Att) (Att b _2 :: Att) Source # 
Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type Cmp (Att a _1 :: Att) (Att b _2 :: Att) = CmpSymbol a b
type WrapField (ChiReco prd :: Type) (v :: [(Att, Type)]) Source #

Field type

Instance details

Defined in Language.Grammars.AspectAG.RecordInstances

type WrapField (ChiReco prd :: Type) (v :: [(Att, Type)]) = Attribution v

(.#) :: (c ~ Chi ch prd nt, ctx ~ '[((Text "looking up " :<>: ShowTE c) :$$: (Text "on " :<>: ShowTE r)) :$$: (Text "producion: " :<>: ShowTE prd)], Require (OpLookup (ChiReco prd) c r) ctx) => Rec (ChiReco prd) r -> Label c -> ReqR (OpLookup (ChiReco prd) c r) infixl 8 Source #

(#.) :: (msg ~ '[(Text "looking up attribute " :<>: ShowTE l) :$$: (Text "on " :<>: ShowTE r)], Require (OpLookup AttReco l r) msg) => Attribution r -> Label l -> ReqR (OpLookup AttReco l r) infixl 7 Source #

(=.) :: Label l -> v -> Attribute l v infixr 4 Source #

Apretty constructor for an attribute

(.=) :: Label l -> WrapField (ChiReco prd) v -> TaggedChAttr prd l v infixr 4 Source #

Pretty constructor for tagging a child

(.*) :: Require (OpExtend (ChiReco prd) ch attrib attribs) (Text "" ': ([] :: [ErrorMessage])) => TaggedChAttr prd ch attrib -> ChAttsRec prd attribs -> ReqR (OpExtend (ChiReco prd) ch attrib attribs) infixr 2 Source #

Pretty constructors

(*.) :: Require (OpExtend AttReco att val atts) (Text "" ': ([] :: [ErrorMessage])) => Attribute att val -> Attribution atts -> ReqR (OpExtend AttReco att val atts) infixr 2 Source #

Extending

ter :: (RequireR (OpLookup (ChiReco prd) pos chi) ctx (Attribution r), RequireR (OpLookup AttReco (Att "term" t) r) ctx t', RequireEq prd prd' ctx, RequireEq t t' ctx, RequireEq pos (Chi ch prd (Right (T t))) ctx, m ~ Reader (Proxy ctx, Fam prd' chi par)) => Label pos -> m (ResAt pos (Att "term" t) m) Source #

at :: At pos att m => Label pos -> Label att -> m (ResAt pos att m) Source #

lhs :: Label Lhs Source #

sem_Lit :: SemLit a => a -> Attribution ('[] :: [(Att, Type)]) -> Attribution '['(Att "term" a, a)] Source #

knitAspect :: (Empties fc prd1, Kn fc prd1, Require (OpLookup PrdReco prd2 r) ((Text "knit" :<>: ShowTE prd2) ': ([] :: [ErrorMessage])), ReqR (OpLookup PrdReco prd2 r) ~# CRule ([] :: [ErrorMessage]) prd1 (SCh fc) ip (EmptiesR fc) ([] :: [(Att, Type)]) (ICh fc) sp) => Label prd2 -> CAspect ([] :: [ErrorMessage]) r -> Record fc -> Attribution ip -> Attribution sp Source #

traceAspect :: MapCtxAsp r ctx ((Text "aspect " :<>: e) ': ctx) => Proxy e -> CAspect ((Text "aspect " :<>: e) ': ctx) r -> CAspect ctx (ResMapCtx r ctx ((Text "aspect " :<>: e) ': ctx)) Source #

|traceAspect| adds context to an aspect.

traceRule :: Proxy e -> CRule ((Text "rule " :<>: e) ': ctx) prd sc ip ic sp ic' sp' -> CRule ctx prd sc ip ic sp ic' sp' Source #

copyAtChi :: (Require (OpUpdate (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) (Left n :: Either NT T)) v2 ic) ctx, Require (OpExtend AttReco (Att att t') t' r) ctx, Require (OpLookup (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) (Left n :: Either NT T)) ic) ctx, Require (OpLookup AttReco (Att att t') ip) (((((((Text "inhdef(" :<>: (((Text "Attribute " :<>: Text att) :<>: Text ":") :<>: ShowType t')) :<>: Text ", ") :<>: ((ShowTE nt :<>: Text "::Production ") :<>: Text prd)) :<>: Text ", ") :<>: ((((((ShowTE nt :<>: Text "::Production ") :<>: Text prd) :<>: Text "::Child ") :<>: Text chi) :<>: Text ":") :<>: ShowTE n)) :<>: Text ")") ': ctx), ReqR (OpLookup AttReco (Att att t') ip) ~# t', ReqR (OpExtend AttReco (Att att t') t' r) ~# Rec AttReco v2, ReqR (OpLookup (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) (Left n :: Either NT T)) ic) ~# Rec AttReco r, ReqR (OpUpdate (ChiReco (Prd prd nt)) (Chi chi (Prd prd nt) (Left n :: Either NT T)) v2 ic) ~# Rec (ChiReco (Prd prd nt)) ic') => Label (Att att t') -> Label (Chi chi (Prd prd nt) (Left n :: Either NT T)) -> CRule ctx (Prd prd nt) sc ip ic sp ic' sp Source #

a rule to copy one attribute att from the parent to the children chi

use :: UseC att prd nts t' sp sc sp' ctx => Label (Att att t') -> Label prd -> KList nts -> (t' -> t' -> t') -> t' -> forall ip ic'. CRule ctx prd sc ip ic' sp ic' sp' Source #

Defines a rule to compute an attribute att in the production prd, by applying an operator to the values of att in each non terminal in the list nts.

emptyAspectC :: EmptyAspect prds polyArgs ctx => KList prds -> Proxy polyArgs -> CAspect ctx (EmptyAspectR prds polyArgs ctx) Source #

emptyAspectForProds :: EmptyAspect prds polyArgs ctx => KList prds -> CAspect ctx (EmptyAspectR prds polyArgs ctx) Source #