module languages/casl/syntax/Struct
imports languages/casl/syntax/BasicItems
exports
  sorts
    Spec Spec-Defn View-Defn Spec-Name Symb-Map-Items Group-Spec Opt-End
%%    Spec-Name Spec-Defn Spec-1 Spec-2 AnnotSpec-1
%%    View-Name View-Defn View-Type Some-Generics
%%    Spec Group-Spec Renaming Restriction
%%    Fit Fit-Arg Symb-Items Symb-Map-Items
%%    Some-Symb-Kind Type
%%    Symb Symb-Map Symb-Or-Map Some-Params Some-Imports
%%    Param Opt-End

  context-free syntax

%% Spec
    Spec-3                         -> Spec-2
    Spec-2                         -> Spec-1
    Spec-1                         -> Spec

    Basic-Spec                     -> Spec-3
    Spec-3 Renaming                -> Spec-3
    Spec-3 Restriction             -> Spec-3

    Spec-2 "and" {Spec-2 "and"}+   -> Spec-1
    Spec-1 "then" {Spec-1 "then"}+ -> Spec
    Ann "free" Group-Spec              -> Spec-3
    Ann "local" Spec "within" Spec-2   -> Spec-2
    Ann "closed" Group-Spec            -> Spec-3
    Ann Group-Spec                     -> Spec-3

%% Group-Spec
    Spec-Name       -> Group-Spec
    "{" Spec "}"    -> Group-Spec
    Spec-Name Fit+  -> Group-Spec

%% new Fit, not in concrete syntax
    "[" Fit-Arg "]" -> Fit

%% Renaming
    "with" {Symb-Map-Items ","}+ -> Renaming

%% Restriction
    "hide" {Symb-Items ","}+       -> Restriction
    "reveal" {Symb-Map-Items ","}+ -> Restriction

%% Spec-Defn
    "spec" Spec-Name "=" Spec Opt-End               -> Spec-Defn
    "spec" Spec-Name Some-Generics "=" Spec Opt-End -> Spec-Defn

%% Some-Generics
    Some-Params              -> Some-Generics
    Some-Params Some-Imports -> Some-Generics

%% Some-Params
    Param+       -> Some-Params
    "[" Spec "]" -> Param

%% Imports
    "given" {Group-Spec ","}+ -> Some-Imports

%% Fit-Arg
    Spec "fit" {Symb-Map-Items ","}+ -> Fit-Arg
    Spec                             -> Fit-Arg
    "view" View-Name                 -> Fit-Arg
    "view" View-Name Fit+            -> Fit-Arg

%% View-Defn
    "view" View-Name ":" 
      View-Type Opt-End                            -> View-Defn
    "view" View-Name ":" 
      View-Type "=" {Symb-Map-Items ","}+ Opt-End  -> View-Defn
    "view" View-Name Some-Generics ":" 
      View-Type Opt-End                            -> View-Defn
    "view" View-Name Some-Generics ":" 
      View-Type "=" {Symb-Map-Items ","}+ Opt-End  -> View-Defn

%% View-Type
    Group-Spec "to" Group-Spec  -> View-Type

%% Symb-Items
   Symb                       -> Symb-Items
   Some-Symb-Kind {Symb ","}+ -> Symb-Items

%% Symb-Map-Items
    Symb-Or-Map                       -> Symb-Map-Items
    Some-Symb-Kind {Symb-Or-Map ","}+ -> Symb-Map-Items

%% Some-Symb-Kind
    Sort-S -> Some-Symb-Kind
    Op-S   -> Some-Symb-Kind
    Pred-S -> Some-Symb-Kind

%% Symb
    Id          -> Symb
    Id ":" Type -> Symb

%% Type
    Op-Type   -> Type
    Pred-Type -> Type

%% Symb-Map
    Symb "|->" Symb -> Symb-Map

%% Symb-Or-Map
    Symb            -> Symb-Or-Map
    Symb-Map        -> Symb-Or-Map

    Simple-Id       -> Spec-Name
    Simple-Id       -> View-Name


%% Opt-End
   ("end" Ann)? -> Opt-End

