%%%
 %% Class Member Patterns
 %%
 %% @author  Martin Bravenboer <martin.bravenboer@gmail.com>
 %%%
module languages/aspectj/pattern/ClassMember[Ctx]
imports
  languages/aspectj/pattern/ClassName[Ctx]
  languages/aspectj/pattern/FormalParameter[Ctx]
  languages/aspectj/pattern/Type[Ctx]

exports
  sorts
    MethodConstrPattern
    MethodPattern
    ConstrPattern

  context-free syntax
    AnnoPattern MethodModPattern TypePattern ClassMemberNamePattern "(" {FormalPattern ","}* ")" ThrowsPattern? -> MethodPattern {cons("MethodPattern")}
    AnnoPattern ConstrModPattern             ConstrNamePattern      "(" {FormalPattern ","}* ")" ThrowsPattern? -> ConstrPattern {cons("ConstrPattern")}

    MethodPattern -> MethodConstrPattern
    ConstrPattern -> MethodConstrPattern

  sorts FieldPattern
  context-free syntax
    AnnoPattern FieldModPattern TypePattern ClassMemberNamePattern -> FieldPattern {cons("FieldPattern")}

  %%%
   %% @todo Parenthesized type pattern
   %%%
  sorts
    ClassMemberNamePattern
    ConstrNamePattern
  context-free syntax
                     IdPattern -> ClassMemberNamePattern {cons("MemberName")}
    TypePattern "."  IdPattern -> ClassMemberNamePattern {cons("MemberName")}
    TypePattern ".." IdPattern -> ClassMemberNamePattern {cons("WildcardMemberName")}

                     "new" -> ConstrNamePattern      {cons("ConstrName")}
    TypePattern "."  "new" -> ConstrNamePattern      {cons("ConstrName")}
    TypePattern ".." "new" -> ConstrNamePattern      {cons("WildcardConstrName")}

  sorts
    MethodModPattern
    ConstrModPattern
    FieldModPattern
  context-free syntax
    "!" MethodMod[[Ctx]] -> NotMethodMod {cons("Not")}
    "!" FieldMod[[Ctx]]  -> NotFieldMod  {cons("Not")}
    "!" ConstrMod[[Ctx]] -> NotConstrMod {cons("Not")}

    (MethodMod[[Ctx]] | NotMethodMod)* -> MethodModPattern {cons("ModPattern")}
    (ConstrMod[[Ctx]] | NotConstrMod)* -> ConstrModPattern {cons("ModPattern")}
    (FieldMod[[Ctx]]  | NotFieldMod )* -> FieldModPattern  {cons("ModPattern")}

  sorts ThrowsPattern ExceptionPattern
  context-free syntax
    "throws" {ExceptionPattern ","}+ -> ThrowsPattern {cons("ThrowsPattern")}

    %% a top-level not binds weaker than other nots.
    "!" ClassNamePattern -> ExceptionPattern {cons("NotThrowsCondition"), prefer}
    ClassNamePattern     -> ExceptionPattern {cons("ThrowsCondition")}

  sorts ElementPattern
  context-free syntax
    MethodConstrPattern -> ElementPattern
            TypePattern -> ElementPattern
           FieldPattern -> ElementPattern