-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Parse and sketch conversion for user-defined rule sets
- Loading branch information
Showing
13 changed files
with
1,203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
-- ========================================================== | ||
-- BNFC grammar for φ-programs (translated from EO) | ||
-- ========================================================== | ||
-- | ||
-- This is a non-ambiguous grammar for φ-programs. | ||
|
||
token Bytes ({"--"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] {"-"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] ({"-"} ["0123456789ABCDEF"] ["0123456789ABCDEF"])+) ; | ||
token Function upper (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ; | ||
token LabelId lower (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ; | ||
token AlphaIndex ({"α0"} | {"α"} (digit - ["0"]) (digit)* ) ; | ||
token MetaId {"!"} (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ; | ||
|
||
Program. Program ::= "{" [Binding] "}" ; | ||
|
||
Formation. Object ::= "⟦" [Binding] "⟧" ; | ||
Application. Object ::= Object "(" [Binding] ")" ; | ||
ObjectDispatch. Object ::= Object "." Attribute ; | ||
GlobalDispatch. Object ::= "Φ" "." Attribute ; | ||
ThisDispatch. Object ::= "ξ" "." Attribute ; | ||
Termination. Object ::= "⊥" ; | ||
MetaObject. Object ::= MetaId ; | ||
|
||
AlphaBinding. Binding ::= Attribute "↦" Object ; | ||
EmptyBinding. Binding ::= Attribute "↦" "∅" ; | ||
DeltaBinding. Binding ::= "Δ" "⤍" Bytes ; | ||
LambdaBinding. Binding ::= "λ" "⤍" Function ; | ||
MetaBindings. Binding ::= MetaId ; | ||
separator Binding "," ; | ||
|
||
Phi. Attribute ::= "φ" ; -- decoratee object | ||
Rho. Attribute ::= "ρ" ; -- parent object | ||
Sigma. Attribute ::= "σ" ; -- home object | ||
VTX. Attribute ::= "ν" ; -- the vertex identifier (an object that represents the unique identifier of the containing object) | ||
Label. Attribute ::= LabelId ; | ||
Alpha. Attribute ::= AlphaIndex ; | ||
MetaAttr. Attribute ::= MetaId ; | ||
|
||
PeeledObject. PeeledObject ::= ObjectHead [ObjectAction] ; | ||
|
||
HeadFormation. ObjectHead ::= "⟦" [Binding] "⟧" ; | ||
HeadGlobal. ObjectHead ::= "Φ" ; | ||
HeadThis. ObjectHead ::= "ξ" ; | ||
HeadTermination. ObjectHead ::= "⊥" ; | ||
|
||
ActionApplication. ObjectAction ::= "(" [Binding] ")" ; | ||
ActionDispatch. ObjectAction ::= "." Attribute ; | ||
separator ObjectAction "" ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
-- File generated by the BNF Converter (bnfc 2.9.5). | ||
|
||
{-# LANGUAGE DeriveDataTypeable #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
|
||
-- | The abstract syntax of language Syntax. | ||
|
||
module Language.EO.Phi.Rules.Syntax.Abs where | ||
|
||
import Prelude (String) | ||
import qualified Prelude as C (Eq, Ord, Show, Read) | ||
import qualified Data.String | ||
|
||
import qualified Data.Data as C (Data, Typeable) | ||
import qualified GHC.Generics as C (Generic) | ||
|
||
data Program = Program [Binding] | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic) | ||
|
||
data Object | ||
= Formation [Binding] | ||
| Application Object [Binding] | ||
| ObjectDispatch Object Attribute | ||
| GlobalDispatch Attribute | ||
| ThisDispatch Attribute | ||
| Termination | ||
| MetaObject MetaId | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic) | ||
|
||
data Binding | ||
= AlphaBinding Attribute Object | ||
| EmptyBinding Attribute | ||
| DeltaBinding Bytes | ||
| LambdaBinding Function | ||
| MetaBindings MetaId | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic) | ||
|
||
data Attribute | ||
= Phi | ||
| Rho | ||
| Sigma | ||
| VTX | ||
| Label LabelId | ||
| Alpha AlphaIndex | ||
| MetaAttr MetaId | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic) | ||
|
||
data PeeledObject = PeeledObject ObjectHead [ObjectAction] | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic) | ||
|
||
data ObjectHead | ||
= HeadFormation [Binding] | HeadGlobal | HeadThis | HeadTermination | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic) | ||
|
||
data ObjectAction | ||
= ActionApplication [Binding] | ActionDispatch Attribute | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic) | ||
|
||
newtype Bytes = Bytes String | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic, Data.String.IsString) | ||
|
||
newtype Function = Function String | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic, Data.String.IsString) | ||
|
||
newtype LabelId = LabelId String | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic, Data.String.IsString) | ||
|
||
newtype AlphaIndex = AlphaIndex String | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic, Data.String.IsString) | ||
|
||
newtype MetaId = MetaId String | ||
deriving (C.Eq, C.Ord, C.Show, C.Read, C.Data, C.Typeable, C.Generic, Data.String.IsString) | ||
|
95 changes: 95 additions & 0 deletions
95
eo-phi-normalizer/src/Language/EO/Phi/Rules/Syntax/Doc.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
eo-phi-normalizer/src/Language/EO/Phi/Rules/Syntax/ErrM.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
-- File generated by the BNF Converter (bnfc 2.9.5). | ||
|
||
{-# LANGUAGE CPP #-} | ||
|
||
#if __GLASGOW_HASKELL__ >= 708 | ||
--------------------------------------------------------------------------- | ||
-- Pattern synonyms exist since ghc 7.8. | ||
|
||
-- | BNF Converter: Error Monad. | ||
-- | ||
-- Module for backwards compatibility. | ||
-- | ||
-- The generated parser now uses @'Either' String@ as error monad. | ||
-- This module defines a type synonym 'Err' and pattern synonyms | ||
-- 'Bad' and 'Ok' for 'Left' and 'Right'. | ||
|
||
{-# LANGUAGE PatternSynonyms #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
|
||
module Language.EO.Phi.Rules.Syntax.ErrM where | ||
|
||
import Prelude (id, const, Either(..), String) | ||
|
||
import Control.Monad (MonadPlus(..)) | ||
import Control.Applicative (Alternative(..)) | ||
#if __GLASGOW_HASKELL__ >= 808 | ||
import Control.Monad (MonadFail(..)) | ||
#endif | ||
|
||
-- | Error monad with 'String' error messages. | ||
type Err = Either String | ||
|
||
pattern Bad msg = Left msg | ||
pattern Ok a = Right a | ||
|
||
#if __GLASGOW_HASKELL__ >= 808 | ||
instance MonadFail Err where | ||
fail = Bad | ||
#endif | ||
|
||
instance Alternative Err where | ||
empty = Left "Err.empty" | ||
(<|>) Left{} = id | ||
(<|>) x@Right{} = const x | ||
|
||
instance MonadPlus Err where | ||
mzero = empty | ||
mplus = (<|>) | ||
|
||
#else | ||
--------------------------------------------------------------------------- | ||
-- ghc 7.6 and before: use old definition as data type. | ||
|
||
-- | BNF Converter: Error Monad | ||
|
||
-- Copyright (C) 2004 Author: Aarne Ranta | ||
-- This file comes with NO WARRANTY and may be used FOR ANY PURPOSE. | ||
|
||
module Language.EO.Phi.Rules.Syntax.ErrM where | ||
|
||
-- the Error monad: like Maybe type with error msgs | ||
|
||
import Control.Applicative (Applicative(..), Alternative(..)) | ||
import Control.Monad (MonadPlus(..), liftM) | ||
|
||
data Err a = Ok a | Bad String | ||
deriving (Read, Show, Eq, Ord) | ||
|
||
instance Monad Err where | ||
return = Ok | ||
Ok a >>= f = f a | ||
Bad s >>= _ = Bad s | ||
|
||
instance Applicative Err where | ||
pure = Ok | ||
(Bad s) <*> _ = Bad s | ||
(Ok f) <*> o = liftM f o | ||
|
||
instance Functor Err where | ||
fmap = liftM | ||
|
||
instance MonadPlus Err where | ||
mzero = Bad "Err.mzero" | ||
mplus (Bad _) y = y | ||
mplus x _ = x | ||
|
||
instance Alternative Err where | ||
empty = mzero | ||
(<|>) = mplus | ||
|
||
#endif |
Oops, something went wrong.