definition
module org/sugarj/languages/SugarHaskell
imports org/sugarj/languages/Haskell
        org/sugarj/languages/Sdf2
        org/sugarj/languages/Stratego
        org/sugarj/languages/EditorServices
        org/sugarj/languages/Plain

exports
  context-free start-symbols
  	SugarCompilationUnit

  context-free syntax
    HaskellModuleDec HaskellImportdecl* SugarHaskellBody -> SugarCompilationUnit {cons("CompilationUnit")}

    "module" HaskellModid HaskellExports? "where" -> HaskellModuleDec {cons("ModuleDec")}

    HaskellOffsideTopdeclList LAYOUT?  -> SugarHaskellBody {cons("HaskellBody")}
    SugarDefElem*             LAYOUT? -> SugarHaskellBody {cons("SugarBody")}
    EditorServiceSection*     LAYOUT? -> SugarHaskellBody {cons("EditorBody")}

  context-free restrictions
    SugarHaskellBody -/- ~[]

  context-free syntax
    HaskellModuleDec LAYOUT?    -> LayoutedToplevelDeclaration
    HaskellImportdecl LAYOUT?   -> LayoutedToplevelDeclaration {enforce-newline, layout(gt(col(left(1)), col(first(1))))}
    SugarHaskellBody LAYOUT?    -> LayoutedToplevelDeclaration

    LayoutedToplevelDeclaration Rest
      -> NextToplevelDeclaration {cons("NextToplevelDeclaration"), layout(eq(col(first(1)), col(first(2))))}


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

  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\'\-\_]

