definition

module org/sugarj/languages/SugarProlog
imports org/sugarj/languages/Prolog 
        org/sugarj/languages/Sdf2
        org/sugarj/languages/Stratego
        org/sugarj/languages/EditorServices
        org/sugarj/languages/Plain

exports
  lexical syntax
    PrologLayoutText          -> LAYOUT


  context-free syntax
    SugarModuleDec PrologModuleImport* SugarBody   -> SugarCompilationUnit {cons("CompilationUnit")}     
    PrologProgram                                -> SugarCompilationUnit {cons("CompilationUnit")}

  context-free syntax
    ":-" "sugar_module(" PrologWord ")" "."             -> SugarModuleDec   {cons("SugarModuleDec")}         %% used like module(...)
   lexical syntax
    "sugar_module"  -> PrologWord {reject}

  lexical restrictions
    "sugar" -/- [a-zA-Z0-9\'\-\_]

  context-free syntax
    ":-" SugarDef "."   -> SugarBody       {cons("SugarBody")}

  sorts Grammar Transformation Desugaring SugarDef SugarDefElem

  context-free syntax
    Grammar        -> SugarDefElem {cons("grammar-elem")}
    Transformation -> SugarDefElem {cons("transformation-elem")}
    SugarDefElem+  -> SugarDef     

  context-free syntax
    "sorts" Sdf2Symbols                            -> Grammar {cons("sorts")}
    "syntax" Sdf2Productions                       -> Grammar {cons("syntax")}
    "lexical" "syntax" Sdf2Productions             -> Grammar {cons("lexical-syntax")}
    "context-free" "syntax" Sdf2Productions        -> Grammar {cons("context-free-syntax")}
    "variables" Sdf2Productions                    -> Grammar {cons("variables")}
    "lexical" "variables" Sdf2Productions          -> Grammar {cons("lexical-variables")}
    "priorities" Sdf2Priorities                    -> Grammar {cons("priorities")}
    "lexical" "priorities" Sdf2Priorities          -> Grammar {cons("lexical-priorities")}
    "context-free" "priorities" Sdf2Priorities     -> Grammar {cons("context-free-priorities")}
    "restrictions" Sdf2Restrictions                -> Grammar {cons("restrictions")}
    "lexical" "restrictions" Sdf2Restrictions      -> Grammar {cons("lexical-restrictions")}
    "context-free" "restrictions" Sdf2Restrictions -> Grammar {cons("context-free-restrictions")}
    "aliases" Sdf2Aliases                          -> Grammar {cons("aliases")}

  lexical syntax
    "sorts"        -> StrategoId {reject}
    "lexical"      -> StrategoId {reject}
    "context-free" -> StrategoId {reject}
    "variables"    -> StrategoId {reject}
    "priorities"   -> StrategoId {reject}
    "restrictions" -> StrategoId {reject}
    "aliases"      -> StrategoId {reject}

  context-free syntax
    "strategies" StrategoDef*   -> Transformation {cons("Strategies")}
    "signature" StrategoSdecl*  -> Transformation {cons("Signature")}
    "rules" StrategoDef*        -> Transformation {cons("Rules")}
    "overlays" StrategoOverlay* -> Transformation {cons("Overlays")}

  lexical syntax
    "desugarings" -> StrategoKeyword 

  context-free syntax
    "desugarings" Desugaring* -> Transformation {cons("Desugarings")}

  context-free syntax
    StrategoStrategy                                               -> Desugaring {cons("PureDesugaring")}
    StrategoStrategy ":" Sdf2Symbol "->" Sdf2Symbol Sdf2Attributes -> Desugaring {cons("InjectDesugaring")}

  lexical restrictions
    "desugarings" -/- [a-zA-Z0-9\'\-\_]

%%  sorts EditorServicesDecHead EditorServicesBody

%%  context-free syntax
%%    EditorServicesDecHead EditorServicesBody   -> SugarDec              {cons("EditorServicesDec")}
    %%AnnoOrSugarMod* "editor" "services" JavaId -> EditorServicesDecHead {cons("EditorServicesDecHead")}
%%    "editor_services" Name                      -> EditorServicesDecHead {cons("EditorServicesDecHead")}
%%    ":-" EditorServiceSection* "."              -> EditorServicesBody    {cons("EditorServicesBody")}       %% replaced '{' and '}' by ':-' and '.'

%%  context-free syntax
%%    ChecksDecHead ChecksBody   -> ToplevelDeclaration              {cons("ChecksDec")}              %% modify here
%%    AnnoOrSugarMod* "analysis" JavaId -> ChecksDecHead {cons("ChecksDecHead")}
%%    AnnoOrSugarMod* "checks" JavaId -> ChecksDecHead {cons("ChecksDecHead")}
%%    ":-" CheckingRule* "."              -> ChecksBody    {cons("ChecksBody")}                        %% replaced '{' and '}' by ':-' and '.'

%%  context-free syntax
%%    "errors" CheckingRuleBody*                          -> CheckingRule     {cons("CheckingRuleErrors")}
%%    "warnings" CheckingRuleBody*                        -> CheckingRule     {cons("CheckingRuleWarnings")}
%%    "notes" CheckingRuleBody*                           -> CheckingRule     {cons("CheckingRuleNotes")}
%%    StrategoTerm "=" StrategoTerm                          -> CheckingRuleBody {cons("RuleNoCond")}
%%    StrategoTerm "=" StrategoTerm "where" StrategoStrategy -> CheckingRuleBody {cons("Rule")}
%%    StrategoTerm "=" StrategoTerm StrategoRuleCond+        -> CheckingRuleBody {cons("Rule"), avoid}

%%    "rules" StrategoDef*        -> CheckingRule {cons("Rules")}

  lexical syntax
         -> "." {recover, reject}           %% replaced '}' by '.'



  %% moved from initgrammar
  
  context-free syntax %% ToplevelDeclaration
    PrologModuleDec -> ToplevelDeclaration
    PrologModuleImport -> ToplevelDeclaration
    PrologModuleReexport -> ToplevelDeclaration       %% needed?
    PrologSentence -> ToplevelDeclaration
    SugarModuleDec -> ToplevelDeclaration
    SugarBody   -> ToplevelDeclaration
  
  