Skip to content

Commit

Permalink
Add PeeledObject and conversion functions
Browse files Browse the repository at this point in the history
fizruk committed Dec 21, 2023

Verified

This commit was signed with the committer’s verified signature.
fizruk Nikolai Kudasov
1 parent 4d3a228 commit 3553917
Showing 6 changed files with 110 additions and 0 deletions.
11 changes: 11 additions & 0 deletions eo-phi-normalizer/grammar/EO/Phi/Syntax.cf
Original file line number Diff line number Diff line change
@@ -30,3 +30,14 @@ Sigma. Attribute ::= "σ" ; -- home object
VTX. Attribute ::= "ν" ; -- ???
Label. Attribute ::= LabelId ;
Alpha. Attribute ::= AlphaIndex ;

PeeledObject. PeeledObject ::= ObjectHead [ObjectAction] ;

HeadFormation. ObjectHead ::= "{" [Binding] "}" ;
HeadGlobal. ObjectHead ::= "Φ" ;
HeadThis. ObjectHead ::= "ξ" ;
HeadTermination. ObjectHead ::= "⊥" ;

ActionApplication. ObjectAction ::= "{" [Binding] "}" ;
ActionDispatch. ObjectAction ::= "." Attribute ;
separator ObjectAction "" ;
31 changes: 31 additions & 0 deletions eo-phi-normalizer/src/Language/EO/Phi/Normalize.hs
Original file line number Diff line number Diff line change
@@ -37,3 +37,34 @@ normalizeObjectWith Context{..} object =
ThisDispatch a ->
fromMaybe object (lookupBinding a thisObject)
_ -> object

-- | Split compound object into its head and applications/dispatch actions.
peelObject :: Object -> PeeledObject
peelObject = \case
Formation bindings -> PeeledObject (HeadFormation bindings) []
Application object bindings -> peelObject object `followedBy` ActionApplication bindings
ObjectDispatch object attr -> peelObject object `followedBy` ActionDispatch attr
GlobalDispatch attr -> PeeledObject HeadGlobal [ActionDispatch attr]
ThisDispatch attr -> PeeledObject HeadThis [ActionDispatch attr]
Termination -> PeeledObject HeadTermination []
where
followedBy (PeeledObject object actions) action = PeeledObject object (actions ++ [action])

unpeelObject :: PeeledObject -> Object
unpeelObject (PeeledObject head_ actions) =
case head_ of
HeadFormation bindings -> go (Formation bindings) actions
HeadGlobal ->
case actions of
ActionDispatch a : as -> go (GlobalDispatch a) as
_ -> error "impossible: global object without dispatch!"
HeadThis ->
case actions of
ActionDispatch a : as -> go (ThisDispatch a) as
_ -> error "impossible: this object without dispatch!"
HeadTermination -> go Termination actions
where
go = foldl applyAction
applyAction object = \case
ActionDispatch attr -> ObjectDispatch object attr
ActionApplication bindings -> Application object bindings
11 changes: 11 additions & 0 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3553917

Please sign in to comment.