module Casl-Struct

%% written/changed by Bjarke Wedemeijer (January 1998)
%% adapted by Mark van den Brand (June 1999)
%% adapted by Mark van den Brand (November 2000)
%% adapted by Christian Maeder (January 2002)
%% adapted by Christian Maeder (February 2004)

imports Casl-BasicItems
exports
  sorts
    Spec Spec-Defn View-Defn Spec-Name Symb-Map-Items Group-Spec 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

