From 14270bf67a0d2196882b1eacf09116cf60f3b268 Mon Sep 17 00:00:00 2001 From: Nikolai Kudasov Date: Fri, 22 Dec 2023 01:07:10 +0300 Subject: [PATCH] Make a simpler, non-ambiguous grammar --- eo-phi-normalizer/grammar/EO/Phi/Syntax.cf | 32 ++---- .../grammar/EO/Phi/Syntax.old.cf | 49 ++++++++ .../src/Language/EO/Phi/Syntax/Abs.hs | 64 +---------- .../src/Language/EO/Phi/Syntax/Doc.txt | 30 ++--- .../src/Language/EO/Phi/Syntax/Lex.x | 16 +-- .../src/Language/EO/Phi/Syntax/Par.y | 106 ++---------------- .../src/Language/EO/Phi/Syntax/Print.hs | 44 +------- .../src/Language/EO/Phi/Syntax/Skel.hs | 31 +---- 8 files changed, 95 insertions(+), 277 deletions(-) create mode 100644 eo-phi-normalizer/grammar/EO/Phi/Syntax.old.cf diff --git a/eo-phi-normalizer/grammar/EO/Phi/Syntax.cf b/eo-phi-normalizer/grammar/EO/Phi/Syntax.cf index 10db3d72e..b0d038675 100644 --- a/eo-phi-normalizer/grammar/EO/Phi/Syntax.cf +++ b/eo-phi-normalizer/grammar/EO/Phi/Syntax.cf @@ -8,42 +8,24 @@ token Bytes ({"--"} | ["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 AlphaIndex ({"α0"} | {"α"} (digit - ["0"]) (digit)* ) ; Program. Program ::= "{" [Binding] "}" ; Formation. Object ::= "{" [Binding] "}" ; -Application. Object ::= AbstractObject "{" [Binding] "}" [Bindings]; -Dispatch. Object ::= Dispatch ; -Termination. Object ::= "⊥"; - -AbstractFormation. AbstractObject ::= "{" [Binding] "}" ; -AbstractDispatch. AbstractObject ::= Dispatch ; -AbstractTermination. AbstractObject ::= "⊥" ; - -DispatchedFormation. DispatchedObject ::= "{" [Binding] "}" ; -DispatchedTermination. DispatchedObject ::= "⊥" ; +Application. Object ::= Object "{" [Binding] "}" ; +Dispatch. Object ::= Object "." Attribute ; +Termination. Object ::= "⊥" ; AlphaBinding. Binding ::= Attribute "↦" Object ; EmptyBinding. Binding ::= Attribute "↦" "∅" ; -DeltaBinding. Binding ::= "Δ" "⤍" Bytes; -LambdaBinding. Binding ::= "λ" "⤍" ; +DeltaBinding. Binding ::= "Δ" "⤍" Bytes ; +LambdaBinding. Binding ::= "λ" "⤍" Function ; separator Binding "," ; -Bindings. Bindings ::= "{" [Binding] "}" ; -separator Bindings "" ; - -ObjectDispatch. Dispatch ::= DispatchedObject [Bindings] "." [Attribute] [Disp] ; -HomeDispatch. Dispatch ::= "Φ" "." [Attribute] [Disp] ; -ThisDispatch. Dispatch ::= "ξ" "." [Attribute] [Disp] ; - Phi. Attribute ::= "φ" ; -- decoratee object Rho. Attribute ::= "ρ" ; -- parent object -Sigma. Attribute ::= "σ" ; -- ??? +Sigma. Attribute ::= "σ" ; -- home object VTX. Attribute ::= "ν" ; -- ??? Label. Attribute ::= LabelId ; Alpha. Attribute ::= AlphaIndex ; -separator nonempty Attribute "." ; - -Disp. Disp ::= "{" [Binding] "}" Bindings "." [Attribute] ; -separator Disp "" ; diff --git a/eo-phi-normalizer/grammar/EO/Phi/Syntax.old.cf b/eo-phi-normalizer/grammar/EO/Phi/Syntax.old.cf new file mode 100644 index 000000000..72a2f0c4a --- /dev/null +++ b/eo-phi-normalizer/grammar/EO/Phi/Syntax.old.cf @@ -0,0 +1,49 @@ +-- ========================================================== +-- BNFC grammar for φ-programs (translated from EO) +-- ========================================================== +-- +-- This grammar is a (manual) translation of Phi.g4 grammar from objectionary/eo: +-- https://github.com/objectionary/eo/blob/fa24c7cc47e1ac473fb930f3a08ccc4d88d9d1e3/eo-parser/src/main/antlr4/org/eolang/parser/Phi.g4 + +token Bytes ({"--"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] ({"-"} ["0123456789ABCDEF"] ["0123456789ABCDEF"])* {"--"}) ; +token Function upper (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ; +token LabelId lower (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ; +token AlphaIndex ({"α0"} | {"α"} (digit - ["0"]) (digit)* ) ; + +Program. Program ::= "{" [Binding] "}" ; + +Formation. Object ::= "{" [Binding] "}" ; +Application. Object ::= AbstractObject "{" [Binding] "}" [Bindings] ; +Dispatch. Object ::= Dispatch ; +Termination. Object ::= "⊥"; + +AbstractFormation. AbstractObject ::= "{" [Binding] "}" ; +AbstractDispatch. AbstractObject ::= Dispatch ; +AbstractTermination. AbstractObject ::= "⊥" ; + +DispatchedFormation. DispatchedObject ::= "{" [Binding] "}" ; +DispatchedTermination. DispatchedObject ::= "⊥" ; + +AlphaBinding. Binding ::= Attribute "↦" Object ; +EmptyBinding. Binding ::= Attribute "↦" "∅" ; +DeltaBinding. Binding ::= "Δ" "⤍" Bytes ; +LambdaBinding. Binding ::= "λ" "⤍" Function ; +separator Binding "," ; + +Bindings. Bindings ::= "{" [Binding] "}" ; +separator Bindings "" ; + +ObjectDispatch. Dispatch ::= DispatchedObject [Bindings] "." [Attribute] [Disp] ; +HomeDispatch. Dispatch ::= "Φ" "." [Attribute] [Disp] ; +ThisDispatch. Dispatch ::= "ξ" "." [Attribute] [Disp] ; + +Phi. Attribute ::= "φ" ; -- decoratee object +Rho. Attribute ::= "ρ" ; -- parent object +Sigma. Attribute ::= "σ" ; -- ??? +VTX. Attribute ::= "ν" ; -- ??? +Label. Attribute ::= LabelId ; +Alpha. Attribute ::= AlphaIndex ; +separator nonempty Attribute "." ; + +Disp. Disp ::= "{" [Binding] "}" Bindings "." [Attribute] ; +separator Disp "" ; diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs index b234f3e8e..9bdc7c7d5 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs @@ -30,40 +30,17 @@ data Program' a = Program a [Binding' a] type Object = Object' BNFC'Position data Object' a = Formation a [Binding' a] - | Application a (AbstractObject' a) [Binding' a] [Bindings' a] - | Dispatch a (Dispatch' a) + | Application a (Object' a) [Binding' a] + | Dispatch a (Object' a) (Attribute' a) | Termination a deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable, C.Data, C.Typeable, C.Generic) -type AbstractObject = AbstractObject' BNFC'Position -data AbstractObject' a - = AbstractFormation a [Binding' a] - | AbstractDispatch a (Dispatch' a) - | AbstractTermination a - deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable, C.Data, C.Typeable, C.Generic) - -type DispatchedObject = DispatchedObject' BNFC'Position -data DispatchedObject' a - = DispatchedFormation a [Binding' a] | DispatchedTermination a - deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable, C.Data, C.Typeable, C.Generic) - type Binding = Binding' BNFC'Position data Binding' a = AlphaBinding a (Attribute' a) (Object' a) | EmptyBinding a (Attribute' a) | DeltaBinding a Bytes - | LambdaBinding a - deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable, C.Data, C.Typeable, C.Generic) - -type Bindings = Bindings' BNFC'Position -data Bindings' a = Bindings a [Binding' a] - deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable, C.Data, C.Typeable, C.Generic) - -type Dispatch = Dispatch' BNFC'Position -data Dispatch' a - = ObjectDispatch a (DispatchedObject' a) [Bindings' a] [Attribute' a] [Disp' a] - | HomeDispatch a [Attribute' a] [Disp' a] - | ThisDispatch a [Attribute' a] [Disp' a] + | LambdaBinding a Function deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable, C.Data, C.Typeable, C.Generic) type Attribute = Attribute' BNFC'Position @@ -76,10 +53,6 @@ data Attribute' a | Alpha a AlphaIndex deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable, C.Data, C.Typeable, C.Generic) -type Disp = Disp' BNFC'Position -data Disp' a = Disp a [Binding' a] (Bindings' a) [Attribute' a] - deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable, 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) @@ -114,37 +87,16 @@ instance HasPosition Program where instance HasPosition Object where hasPosition = \case Formation p _ -> p - Application p _ _ _ -> p - Dispatch p _ -> p + Application p _ _ -> p + Dispatch p _ _ -> p Termination p -> p -instance HasPosition AbstractObject where - hasPosition = \case - AbstractFormation p _ -> p - AbstractDispatch p _ -> p - AbstractTermination p -> p - -instance HasPosition DispatchedObject where - hasPosition = \case - DispatchedFormation p _ -> p - DispatchedTermination p -> p - instance HasPosition Binding where hasPosition = \case AlphaBinding p _ _ -> p EmptyBinding p _ -> p DeltaBinding p _ -> p - LambdaBinding p -> p - -instance HasPosition Bindings where - hasPosition = \case - Bindings p _ -> p - -instance HasPosition Dispatch where - hasPosition = \case - ObjectDispatch p _ _ _ _ -> p - HomeDispatch p _ _ -> p - ThisDispatch p _ _ -> p + LambdaBinding p _ -> p instance HasPosition Attribute where hasPosition = \case @@ -155,7 +107,3 @@ instance HasPosition Attribute where Label p _ -> p Alpha p _ -> p -instance HasPosition Disp where - hasPosition = \case - Disp p _ _ _ -> p - diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt index 2f1238ec4..8eb276aed 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt @@ -35,12 +35,12 @@ AlphaIndex literals are recognized by the regular expression The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions. The reserved words used in Syntax are the following: - | ``Δ`` | ``Φ`` | ``λ`` | ``ν`` - | ``ξ`` | ``ρ`` | ``σ`` | ``φ`` + | ``Δ`` | ``λ`` | ``ν`` | ``ρ`` + | ``σ`` | ``φ`` | | The symbols used in Syntax are the following: - | { | } | ⊥ | ↦ - | ∅ | ⤍ | , | . + | { | } | . | ⊥ + | ↦ | ∅ | ⤍ | , ===Comments=== There are no single-line comments in the grammar.There are no multiple-line comments in the grammar. @@ -53,38 +53,22 @@ All other symbols are terminals. | //Program// | -> | ``{`` //[Binding]// ``}`` | //Object// | -> | ``{`` //[Binding]// ``}`` - | | **|** | //AbstractObject// ``{`` //[Binding]// ``}`` //[Bindings]// - | | **|** | //Dispatch// - | | **|** | ``⊥`` - | //AbstractObject// | -> | ``{`` //[Binding]// ``}`` - | | **|** | //Dispatch// - | | **|** | ``⊥`` - | //DispatchedObject// | -> | ``{`` //[Binding]// ``}`` + | | **|** | //Object// ``{`` //[Binding]// ``}`` + | | **|** | //Object// ``.`` //Attribute// | | **|** | ``⊥`` | //Binding// | -> | //Attribute// ``↦`` //Object// | | **|** | //Attribute// ``↦`` ``∅`` | | **|** | ``Δ`` ``⤍`` //Bytes// - | | **|** | ``λ`` ``⤍`` + | | **|** | ``λ`` ``⤍`` //Function// | //[Binding]// | -> | **eps** | | **|** | //Binding// | | **|** | //Binding// ``,`` //[Binding]// - | //Bindings// | -> | ``{`` //[Binding]// ``}`` - | //[Bindings]// | -> | **eps** - | | **|** | //Bindings// //[Bindings]// - | //Dispatch// | -> | //DispatchedObject// //[Bindings]// ``.`` //[Attribute]// //[Disp]// - | | **|** | ``Φ`` ``.`` //[Attribute]// //[Disp]// - | | **|** | ``ξ`` ``.`` //[Attribute]// //[Disp]// | //Attribute// | -> | ``φ`` | | **|** | ``ρ`` | | **|** | ``σ`` | | **|** | ``ν`` | | **|** | //LabelId// | | **|** | //AlphaIndex// - | //[Attribute]// | -> | //Attribute// - | | **|** | //Attribute// ``.`` //[Attribute]// - | //Disp// | -> | ``{`` //[Binding]// ``}`` //Bindings// ``.`` //[Attribute]// - | //[Disp]// | -> | **eps** - | | **|** | //Disp// //[Disp]// diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x index e36054bde..d2b6608f1 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x @@ -28,7 +28,7 @@ $u = [. \n] -- universal: any character -- Symbols and non-identifier-like reserved words -@rsyms = \Δ | \λ | \Φ | \ξ | \φ | \ρ | \σ | \ν | \{ | \} | \⊥ | \↦ | \∅ | \⤍ | \, | \. +@rsyms = \Δ | \λ | \φ | \ρ | \σ | \ν | \{ | \} | \. | \⊥ | \↦ | \∅ | \⤍ | \, :- @@ -168,13 +168,13 @@ eitherResIdent tv s = treeFind resWords -- | The keywords and symbols of the language organized as binary search tree. resWords :: BTree resWords = - b "\958" 9 - (b "\916" 5 - (b "{" 3 (b "." 2 (b "," 1 N N) N) (b "}" 4 N N)) - (b "\955" 7 (b "\934" 6 N N) (b "\957" 8 N N))) - (b "\8614" 13 - (b "\963" 11 (b "\961" 10 N N) (b "\966" 12 N N)) - (b "\8869" 15 (b "\8709" 14 N N) (b "\10509" 16 N N))) + b "\961" 8 + (b "}" 4 + (b "." 2 (b "," 1 N N) (b "{" 3 N N)) + (b "\955" 6 (b "\916" 5 N N) (b "\957" 7 N N))) + (b "\8709" 12 + (b "\966" 10 (b "\963" 9 N N) (b "\8614" 11 N N)) + (b "\10509" 14 (b "\8869" 13 N N) N)) where b s n = B bs (TS bs n) where diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y index 382664649..ef49762fc 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y @@ -10,17 +10,9 @@ module Language.EO.Phi.Syntax.Par , myLexer , pProgram , pObject - , pAbstractObject - , pDispatchedObject , pBinding , pListBinding - , pBindings - , pListBindings - , pDispatch , pAttribute - , pListAttribute - , pDisp - , pListDisp ) where import Prelude @@ -32,17 +24,9 @@ import Language.EO.Phi.Syntax.Lex %name pProgram_internal Program %name pObject_internal Object -%name pAbstractObject_internal AbstractObject -%name pDispatchedObject_internal DispatchedObject %name pBinding_internal Binding %name pListBinding_internal ListBinding -%name pBindings_internal Bindings -%name pListBindings_internal ListBindings -%name pDispatch_internal Dispatch %name pAttribute_internal Attribute -%name pListAttribute_internal ListAttribute -%name pDisp_internal Disp -%name pListDisp_internal ListDisp -- no lexer declaration %monad { Err } { (>>=) } { return } %tokentype {Token} @@ -52,17 +36,15 @@ import Language.EO.Phi.Syntax.Lex '{' { PT _ (TS _ 3) } '}' { PT _ (TS _ 4) } 'Δ' { PT _ (TS _ 5) } - 'Φ' { PT _ (TS _ 6) } - 'λ' { PT _ (TS _ 7) } - 'ν' { PT _ (TS _ 8) } - 'ξ' { PT _ (TS _ 9) } - 'ρ' { PT _ (TS _ 10) } - 'σ' { PT _ (TS _ 11) } - 'φ' { PT _ (TS _ 12) } - '↦' { PT _ (TS _ 13) } - '∅' { PT _ (TS _ 14) } - '⊥' { PT _ (TS _ 15) } - '⤍' { PT _ (TS _ 16) } + 'λ' { PT _ (TS _ 6) } + 'ν' { PT _ (TS _ 7) } + 'ρ' { PT _ (TS _ 8) } + 'σ' { PT _ (TS _ 9) } + 'φ' { PT _ (TS _ 10) } + '↦' { PT _ (TS _ 11) } + '∅' { PT _ (TS _ 12) } + '⊥' { PT _ (TS _ 13) } + '⤍' { PT _ (TS _ 14) } L_Bytes { PT _ (T_Bytes _) } L_Function { PT _ (T_Function _) } L_LabelId { PT _ (T_LabelId _) } @@ -89,27 +71,16 @@ Program Object :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, Language.EO.Phi.Syntax.Abs.Object) } Object : '{' ListBinding '}' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.Formation (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $2)) } - | AbstractObject '{' ListBinding '}' ListBindings { (fst $1, Language.EO.Phi.Syntax.Abs.Application (fst $1) (snd $1) (snd $3) (snd $5)) } - | Dispatch { (fst $1, Language.EO.Phi.Syntax.Abs.Dispatch (fst $1) (snd $1)) } + | Object '{' ListBinding '}' { (fst $1, Language.EO.Phi.Syntax.Abs.Application (fst $1) (snd $1) (snd $3)) } + | Object '.' Attribute { (fst $1, Language.EO.Phi.Syntax.Abs.Dispatch (fst $1) (snd $1) (snd $3)) } | '⊥' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.Termination (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1))) } -AbstractObject :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, Language.EO.Phi.Syntax.Abs.AbstractObject) } -AbstractObject - : '{' ListBinding '}' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.AbstractFormation (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $2)) } - | Dispatch { (fst $1, Language.EO.Phi.Syntax.Abs.AbstractDispatch (fst $1) (snd $1)) } - | '⊥' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.AbstractTermination (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1))) } - -DispatchedObject :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, Language.EO.Phi.Syntax.Abs.DispatchedObject) } -DispatchedObject - : '{' ListBinding '}' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.DispatchedFormation (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $2)) } - | '⊥' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.DispatchedTermination (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1))) } - Binding :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, Language.EO.Phi.Syntax.Abs.Binding) } Binding : Attribute '↦' Object { (fst $1, Language.EO.Phi.Syntax.Abs.AlphaBinding (fst $1) (snd $1) (snd $3)) } | Attribute '↦' '∅' { (fst $1, Language.EO.Phi.Syntax.Abs.EmptyBinding (fst $1) (snd $1)) } | 'Δ' '⤍' Bytes { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.DeltaBinding (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $3)) } - | 'λ' '⤍' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.LambdaBinding (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1))) } + | 'λ' '⤍' Function { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.LambdaBinding (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $3)) } ListBinding :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, [Language.EO.Phi.Syntax.Abs.Binding]) } ListBinding @@ -117,21 +88,6 @@ ListBinding | Binding { (fst $1, (:[]) (snd $1)) } | Binding ',' ListBinding { (fst $1, (:) (snd $1) (snd $3)) } -Bindings :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, Language.EO.Phi.Syntax.Abs.Bindings) } -Bindings - : '{' ListBinding '}' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.Bindings (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $2)) } - -ListBindings :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, [Language.EO.Phi.Syntax.Abs.Bindings]) } -ListBindings - : {- empty -} { (Language.EO.Phi.Syntax.Abs.BNFC'NoPosition, []) } - | Bindings ListBindings { (fst $1, (:) (snd $1) (snd $2)) } - -Dispatch :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, Language.EO.Phi.Syntax.Abs.Dispatch) } -Dispatch - : DispatchedObject ListBindings '.' ListAttribute ListDisp { (fst $1, Language.EO.Phi.Syntax.Abs.ObjectDispatch (fst $1) (snd $1) (snd $2) (snd $4) (snd $5)) } - | 'Φ' '.' ListAttribute ListDisp { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.HomeDispatch (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $3) (snd $4)) } - | 'ξ' '.' ListAttribute ListDisp { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.ThisDispatch (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $3) (snd $4)) } - Attribute :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, Language.EO.Phi.Syntax.Abs.Attribute) } Attribute : 'φ' { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.Phi (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1))) } @@ -141,20 +97,6 @@ Attribute | LabelId { (fst $1, Language.EO.Phi.Syntax.Abs.Label (fst $1) (snd $1)) } | AlphaIndex { (fst $1, Language.EO.Phi.Syntax.Abs.Alpha (fst $1) (snd $1)) } -ListAttribute :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, [Language.EO.Phi.Syntax.Abs.Attribute]) } -ListAttribute - : Attribute { (fst $1, (:[]) (snd $1)) } - | Attribute '.' ListAttribute { (fst $1, (:) (snd $1) (snd $3)) } - -Disp :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, Language.EO.Phi.Syntax.Abs.Disp) } -Disp - : '{' ListBinding '}' Bindings '.' ListAttribute { (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1), Language.EO.Phi.Syntax.Abs.Disp (uncurry Language.EO.Phi.Syntax.Abs.BNFC'Position (tokenLineCol $1)) (snd $2) (snd $4) (snd $6)) } - -ListDisp :: { (Language.EO.Phi.Syntax.Abs.BNFC'Position, [Language.EO.Phi.Syntax.Abs.Disp]) } -ListDisp - : {- empty -} { (Language.EO.Phi.Syntax.Abs.BNFC'NoPosition, []) } - | Disp ListDisp { (fst $1, (:) (snd $1) (snd $2)) } - { type Err = Either String @@ -178,37 +120,13 @@ pProgram = fmap snd . pProgram_internal pObject :: [Token] -> Err Language.EO.Phi.Syntax.Abs.Object pObject = fmap snd . pObject_internal -pAbstractObject :: [Token] -> Err Language.EO.Phi.Syntax.Abs.AbstractObject -pAbstractObject = fmap snd . pAbstractObject_internal - -pDispatchedObject :: [Token] -> Err Language.EO.Phi.Syntax.Abs.DispatchedObject -pDispatchedObject = fmap snd . pDispatchedObject_internal - pBinding :: [Token] -> Err Language.EO.Phi.Syntax.Abs.Binding pBinding = fmap snd . pBinding_internal pListBinding :: [Token] -> Err [Language.EO.Phi.Syntax.Abs.Binding] pListBinding = fmap snd . pListBinding_internal -pBindings :: [Token] -> Err Language.EO.Phi.Syntax.Abs.Bindings -pBindings = fmap snd . pBindings_internal - -pListBindings :: [Token] -> Err [Language.EO.Phi.Syntax.Abs.Bindings] -pListBindings = fmap snd . pListBindings_internal - -pDispatch :: [Token] -> Err Language.EO.Phi.Syntax.Abs.Dispatch -pDispatch = fmap snd . pDispatch_internal - pAttribute :: [Token] -> Err Language.EO.Phi.Syntax.Abs.Attribute pAttribute = fmap snd . pAttribute_internal - -pListAttribute :: [Token] -> Err [Language.EO.Phi.Syntax.Abs.Attribute] -pListAttribute = fmap snd . pListAttribute_internal - -pDisp :: [Token] -> Err Language.EO.Phi.Syntax.Abs.Disp -pDisp = fmap snd . pDisp_internal - -pListDisp :: [Token] -> Err [Language.EO.Phi.Syntax.Abs.Disp] -pListDisp = fmap snd . pListDisp_internal } diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs index 8be1ef5c4..3335b9e01 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs @@ -152,47 +152,22 @@ instance Print (Language.EO.Phi.Syntax.Abs.Program' a) where instance Print (Language.EO.Phi.Syntax.Abs.Object' a) where prt i = \case Language.EO.Phi.Syntax.Abs.Formation _ bindings -> prPrec i 0 (concatD [doc (showString "{"), prt 0 bindings, doc (showString "}")]) - Language.EO.Phi.Syntax.Abs.Application _ abstractobject bindings bindingss -> prPrec i 0 (concatD [prt 0 abstractobject, doc (showString "{"), prt 0 bindings, doc (showString "}"), prt 0 bindingss]) - Language.EO.Phi.Syntax.Abs.Dispatch _ dispatch -> prPrec i 0 (concatD [prt 0 dispatch]) + Language.EO.Phi.Syntax.Abs.Application _ object bindings -> prPrec i 0 (concatD [prt 0 object, doc (showString "{"), prt 0 bindings, doc (showString "}")]) + Language.EO.Phi.Syntax.Abs.Dispatch _ object attribute -> prPrec i 0 (concatD [prt 0 object, doc (showString "."), prt 0 attribute]) Language.EO.Phi.Syntax.Abs.Termination _ -> prPrec i 0 (concatD [doc (showString "\8869")]) -instance Print (Language.EO.Phi.Syntax.Abs.AbstractObject' a) where - prt i = \case - Language.EO.Phi.Syntax.Abs.AbstractFormation _ bindings -> prPrec i 0 (concatD [doc (showString "{"), prt 0 bindings, doc (showString "}")]) - Language.EO.Phi.Syntax.Abs.AbstractDispatch _ dispatch -> prPrec i 0 (concatD [prt 0 dispatch]) - Language.EO.Phi.Syntax.Abs.AbstractTermination _ -> prPrec i 0 (concatD [doc (showString "\8869")]) - -instance Print (Language.EO.Phi.Syntax.Abs.DispatchedObject' a) where - prt i = \case - Language.EO.Phi.Syntax.Abs.DispatchedFormation _ bindings -> prPrec i 0 (concatD [doc (showString "{"), prt 0 bindings, doc (showString "}")]) - Language.EO.Phi.Syntax.Abs.DispatchedTermination _ -> prPrec i 0 (concatD [doc (showString "\8869")]) - instance Print (Language.EO.Phi.Syntax.Abs.Binding' a) where prt i = \case Language.EO.Phi.Syntax.Abs.AlphaBinding _ attribute object -> prPrec i 0 (concatD [prt 0 attribute, doc (showString "\8614"), prt 0 object]) Language.EO.Phi.Syntax.Abs.EmptyBinding _ attribute -> prPrec i 0 (concatD [prt 0 attribute, doc (showString "\8614"), doc (showString "\8709")]) Language.EO.Phi.Syntax.Abs.DeltaBinding _ bytes -> prPrec i 0 (concatD [doc (showString "\916"), doc (showString "\10509"), prt 0 bytes]) - Language.EO.Phi.Syntax.Abs.LambdaBinding _ -> prPrec i 0 (concatD [doc (showString "\955"), doc (showString "\10509")]) + Language.EO.Phi.Syntax.Abs.LambdaBinding _ function -> prPrec i 0 (concatD [doc (showString "\955"), doc (showString "\10509"), prt 0 function]) instance Print [Language.EO.Phi.Syntax.Abs.Binding' a] where prt _ [] = concatD [] prt _ [x] = concatD [prt 0 x] prt _ (x:xs) = concatD [prt 0 x, doc (showString ","), prt 0 xs] -instance Print (Language.EO.Phi.Syntax.Abs.Bindings' a) where - prt i = \case - Language.EO.Phi.Syntax.Abs.Bindings _ bindings -> prPrec i 0 (concatD [doc (showString "{"), prt 0 bindings, doc (showString "}")]) - -instance Print [Language.EO.Phi.Syntax.Abs.Bindings' a] where - prt _ [] = concatD [] - prt _ (x:xs) = concatD [prt 0 x, prt 0 xs] - -instance Print (Language.EO.Phi.Syntax.Abs.Dispatch' a) where - prt i = \case - Language.EO.Phi.Syntax.Abs.ObjectDispatch _ dispatchedobject bindingss attributes disps -> prPrec i 0 (concatD [prt 0 dispatchedobject, prt 0 bindingss, doc (showString "."), prt 0 attributes, prt 0 disps]) - Language.EO.Phi.Syntax.Abs.HomeDispatch _ attributes disps -> prPrec i 0 (concatD [doc (showString "\934"), doc (showString "."), prt 0 attributes, prt 0 disps]) - Language.EO.Phi.Syntax.Abs.ThisDispatch _ attributes disps -> prPrec i 0 (concatD [doc (showString "\958"), doc (showString "."), prt 0 attributes, prt 0 disps]) - instance Print (Language.EO.Phi.Syntax.Abs.Attribute' a) where prt i = \case Language.EO.Phi.Syntax.Abs.Phi _ -> prPrec i 0 (concatD [doc (showString "\966")]) @@ -201,16 +176,3 @@ instance Print (Language.EO.Phi.Syntax.Abs.Attribute' a) where Language.EO.Phi.Syntax.Abs.VTX _ -> prPrec i 0 (concatD [doc (showString "\957")]) Language.EO.Phi.Syntax.Abs.Label _ labelid -> prPrec i 0 (concatD [prt 0 labelid]) Language.EO.Phi.Syntax.Abs.Alpha _ alphaindex -> prPrec i 0 (concatD [prt 0 alphaindex]) - -instance Print [Language.EO.Phi.Syntax.Abs.Attribute' a] where - prt _ [] = concatD [] - prt _ [x] = concatD [prt 0 x] - prt _ (x:xs) = concatD [prt 0 x, doc (showString "."), prt 0 xs] - -instance Print (Language.EO.Phi.Syntax.Abs.Disp' a) where - prt i = \case - Language.EO.Phi.Syntax.Abs.Disp _ bindings1 bindings2 attributes -> prPrec i 0 (concatD [doc (showString "{"), prt 0 bindings1, doc (showString "}"), prt 0 bindings2, doc (showString "."), prt 0 attributes]) - -instance Print [Language.EO.Phi.Syntax.Abs.Disp' a] where - prt _ [] = concatD [] - prt _ (x:xs) = concatD [prt 0 x, prt 0 xs] diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Skel.hs b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Skel.hs index 735fb29e0..2cfe2f044 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Skel.hs +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Skel.hs @@ -38,37 +38,16 @@ transProgram x = case x of transObject :: Show a => Language.EO.Phi.Syntax.Abs.Object' a -> Result transObject x = case x of Language.EO.Phi.Syntax.Abs.Formation _ bindings -> failure x - Language.EO.Phi.Syntax.Abs.Application _ abstractobject bindings bindingss -> failure x - Language.EO.Phi.Syntax.Abs.Dispatch _ dispatch -> failure x + Language.EO.Phi.Syntax.Abs.Application _ object bindings -> failure x + Language.EO.Phi.Syntax.Abs.Dispatch _ object attribute -> failure x Language.EO.Phi.Syntax.Abs.Termination _ -> failure x -transAbstractObject :: Show a => Language.EO.Phi.Syntax.Abs.AbstractObject' a -> Result -transAbstractObject x = case x of - Language.EO.Phi.Syntax.Abs.AbstractFormation _ bindings -> failure x - Language.EO.Phi.Syntax.Abs.AbstractDispatch _ dispatch -> failure x - Language.EO.Phi.Syntax.Abs.AbstractTermination _ -> failure x - -transDispatchedObject :: Show a => Language.EO.Phi.Syntax.Abs.DispatchedObject' a -> Result -transDispatchedObject x = case x of - Language.EO.Phi.Syntax.Abs.DispatchedFormation _ bindings -> failure x - Language.EO.Phi.Syntax.Abs.DispatchedTermination _ -> failure x - transBinding :: Show a => Language.EO.Phi.Syntax.Abs.Binding' a -> Result transBinding x = case x of Language.EO.Phi.Syntax.Abs.AlphaBinding _ attribute object -> failure x Language.EO.Phi.Syntax.Abs.EmptyBinding _ attribute -> failure x Language.EO.Phi.Syntax.Abs.DeltaBinding _ bytes -> failure x - Language.EO.Phi.Syntax.Abs.LambdaBinding _ -> failure x - -transBindings :: Show a => Language.EO.Phi.Syntax.Abs.Bindings' a -> Result -transBindings x = case x of - Language.EO.Phi.Syntax.Abs.Bindings _ bindings -> failure x - -transDispatch :: Show a => Language.EO.Phi.Syntax.Abs.Dispatch' a -> Result -transDispatch x = case x of - Language.EO.Phi.Syntax.Abs.ObjectDispatch _ dispatchedobject bindingss attributes disps -> failure x - Language.EO.Phi.Syntax.Abs.HomeDispatch _ attributes disps -> failure x - Language.EO.Phi.Syntax.Abs.ThisDispatch _ attributes disps -> failure x + Language.EO.Phi.Syntax.Abs.LambdaBinding _ function -> failure x transAttribute :: Show a => Language.EO.Phi.Syntax.Abs.Attribute' a -> Result transAttribute x = case x of @@ -78,7 +57,3 @@ transAttribute x = case x of Language.EO.Phi.Syntax.Abs.VTX _ -> failure x Language.EO.Phi.Syntax.Abs.Label _ labelid -> failure x Language.EO.Phi.Syntax.Abs.Alpha _ alphaindex -> failure x - -transDisp :: Show a => Language.EO.Phi.Syntax.Abs.Disp' a -> Result -transDisp x = case x of - Language.EO.Phi.Syntax.Abs.Disp _ bindings1 bindings2 attributes -> failure x