definition

module Stratego-Sugar-Overlays
imports Stratego-Core-Identifiers Stratego-Sugar-Terms

exports
  sorts WATER WATERTOKEN WATERTOKENSTART WATERTOKENSEPARATOR WATERTOKENSTAR

  lexical syntax
    ~[A-Za-z0-9\_]                 -> WATERTOKENSTART     {recover, avoid}
    WATERTOKENSTART [A-Za-z0-9\_]* -> WATERTOKEN          
    ~[A-Za-z0-9\_\ \t\12\r\n\*]    -> WATERTOKENSEPARATOR {recover, avoid}
    "*"                            -> WATERTOKENSTAR      {recover, avoid}
    WATERTOKEN                     -> WATER               
    WATERTOKENSEPARATOR            -> WATER               
    WATERTOKENSTAR                 -> WATER               
                                   -> WATEREOF            

  lexical restrictions
    WATERTOKEN -/- [A-Za-z0-9\_]
    WATERTOKENSTAR -/- [\/]

  context-free syntax
    WATER -> LAYOUT {cons("WATER")}

  (

  sorts WATEREOF

  lexical restrictions
    WATEREOF -/- ~[]

  lexical syntax
    %% Lexical insertion recovery rules                     
                                        -> "|}"             {recover, cons("INSERTION")}
                                        -> ">"              {recover, cons("INSERTION")}
                                        -> "\\"             {recover, cons("INSERTION")}
                                        -> "]"              {recover, cons("INSERTION")}
                                        -> "sorts"          {recover, cons("INSERTION")}
                                        -> "constructors"   {recover, cons("INSERTION")}
                                        -> ":"              {recover, cons("INSERTION")}
                                        -> "*"              {recover, cons("INSERTION")}
                                        -> "end"            {recover, cons("INSERTION")}
                                        -> "}"              {recover, cons("INSERTION")}
                                        -> ","              {recover, cons("INSERTION")}
                                        -> ")"              {recover, cons("INSERTION")}
                                        -> "module"         {recover, cons("INSERTION")}
                                        -> "specification"  {recover, cons("INSERTION")}
                                        -> "imports"        {recover, cons("INSERTION")}
                                        -> "strategies"     {recover, cons("INSERTION")}
                                        -> "signature"      {recover, cons("INSERTION")}
                                        -> "overlays"       {recover, cons("INSERTION")}
    "\""                                -> INSERTOPENQUOTE1 {recover}
    INSERTOPENQUOTE1 StrChar* "\n"      -> String           {cons("INSERTEND")}
    INSERTOPENQUOTE1 StrChar* WATEREOF  -> String           {cons("INSERTEND")}
    "'"                                 -> INSERTOPENQUOTE0 {recover}
    INSERTOPENQUOTE0 CharChar "\n"      -> Char             {cons("INSERTEND")}
    INSERTOPENQUOTE0 CharChar WATEREOF  -> Char             {cons("INSERTEND")}
    "/*"                                -> INSERTSTART0     {recover}
    INSERTSTART0 CommChar* WATEREOF     -> LongCom          {cons("INSERTEND")}

  syntax
    %% Kernel syntax insertion recovery rules   

  )

  (

  sorts Overlay

  context-free syntax
    Id "=" Term                   -> Overlay {cons("OverlayNoArgs")}
    Id "(" {Id ","}* ")" "=" Term -> Overlay {cons("Overlay")}

  )

module Stratego-Sugar-DynamicRules
imports Stratego-Core-Identifiers Stratego-Sugar-Strategies Stratego-Sugar-Rules

exports
  sorts ScopeLabels

  context-free syntax
    "{|" ScopeLabels ":" Strategy "|}" -> Strategy    {cons("DynRuleScope")}
    {DynRuleScopeId ","}*              -> ScopeLabels 
    "~" Term                           -> ScopeLabels {cons("ScopeLabels")}

  sorts DynRuleDef DynRuleId DynRuleScopeId RuleDec

  context-free syntax
    "rules" "(" DynRuleDef* ")"            -> Strategy       {cons("GenDynRules")}
    Id "+" Term                            -> DynRuleDef     {cons("AddScopeLabel")}
    DynRuleId ":-" Term                    -> DynRuleDef     {cons("UndefineDynRule")}
    DynRuleId ":" Rule                     -> DynRuleDef     {cons("SetDynRule")}
    DynRuleId ":+" Rule                    -> DynRuleDef     {cons("AddDynRule")}
    DynRuleId ":" Term                     -> DynRuleDef     {cons("SetDynRuleMatch")}
    DynRuleId ":=" Term                    -> DynRuleDef     {cons("DynRuleAssign")}
    DynRuleId ":+=" Term                   -> DynRuleDef     {cons("DynRuleAssignAdd")}
    DynRuleId ":" Rule "depends" "on" Term -> DynRuleDef     {cons("SetDynRuleDepends")}
    RuleDec "." Term                       -> DynRuleId      {cons("LabeledDynRuleId")}
    RuleDec "+" Term                       -> DynRuleId      {cons("AddLabelDynRuleId")}
    RuleDec                                -> DynRuleId      {cons("DynRuleId")}
    Id "." Term                            -> DynRuleScopeId {cons("LabeledDynRuleScopeId")}
    Id                                     -> DynRuleScopeId {cons("DynRuleScopeId")}

  context-free syntax
    Id                                           -> RuleDec {cons("RDecNoArgs")}
    Id "(" {Typedid ","}* ")"                    -> RuleDec {cons("RDec")}
    Id "(" {Typedid ","}* "|" {Typedid ","}* ")" -> RuleDec {cons("RDecT")}

  sorts RuleNames

  context-free syntax
    {Id ","}*                    -> RuleNames 
    "~" Term                     -> RuleNames {cons("RuleNames")}
    "/" RuleNames "\\*" Strategy -> Strategy  {cons("DynRuleIntersectFix")}

  syntax
    "\\" <LAYOUT?-CF> <RuleNames-CF> "/*" <LAYOUT?-CF> <Strategy-CF>                                               -> <Strategy-CF> {cons("DynRuleUnionFix")}
    "\\" <LAYOUT?-CF> <RuleNames-CF> " /*" <LAYOUT?-CF> <Strategy-CF>                                              -> <Strategy-CF> {cons("DynRuleUnionFix")}
    "/" <LAYOUT?-CF> <RuleNames-CF> <LAYOUT?-CF> "\\" <LAYOUT?-CF> <RuleNames-CF> "/*" <LAYOUT?-CF> <Strategy-CF>  -> <Strategy-CF> {cons("DynRuleIntersectUnionFix")}
    "/" <LAYOUT?-CF> <RuleNames-CF> <LAYOUT?-CF> "\\" <LAYOUT?-CF> <RuleNames-CF> " /*" <LAYOUT?-CF> <Strategy-CF> -> <Strategy-CF> {cons("DynRuleIntersectUnionFix")}

  context-free syntax
    Strategy "/" RuleNames "\\" Strategy               -> Strategy {cons("DynRuleIntersect"), right}
    Strategy "\\" RuleNames "/" Strategy               -> Strategy {cons("DynRuleUnion"), right}
    Strategy "/" RuleNames "\\" RuleNames "/" Strategy -> Strategy {cons("DynRuleIntersectUnion"), right}

  priorities
    <StrategyAngle-CF> <LAYOUT?-CF> <Term-CF> -> <Strategy-CF> {cons("BA")} >
    { "\\" <LAYOUT?-CF> <RuleNames-CF> "/*" <LAYOUT?-CF> <Strategy-CF> ->
      <Strategy-CF> {cons("DynRuleUnionFix")}
      "\\" <LAYOUT?-CF> <RuleNames-CF> " /*" <LAYOUT?-CF> <Strategy-CF> ->
      <Strategy-CF> {cons("DynRuleUnionFix")}
      
      "/" <LAYOUT?-CF> <RuleNames-CF> <LAYOUT?-CF> "\\" <LAYOUT?-CF> <RuleNames-CF> "/*" <LAYOUT?-CF> <Strategy-CF>
      -> <Strategy-CF> {cons("DynRuleIntersectUnionFix")}
      
      "/" <LAYOUT?-CF> <RuleNames-CF> <LAYOUT?-CF> "\\" <LAYOUT?-CF> <RuleNames-CF> " /*" <LAYOUT?-CF> <Strategy-CF>
      -> <Strategy-CF> {cons("DynRuleIntersectUnionFix")} } >
    <Strategy-CF> <LAYOUT?-CF> "=>" <LAYOUT?-CF> <Term-CF> -> <Strategy-CF>
    {cons("AM")}

  context-free priorities
    StrategyAngle Term -> Strategy {cons("BA")} >
    "/" RuleNames "\\*" Strategy -> Strategy {cons("DynRuleIntersectFix")} >
    Strategy "=>" Term -> Strategy {cons("AM")} >
    Strategy "/" RuleNames "\\" Strategy -> Strategy
    {cons("DynRuleIntersect"), right} >
    Strategy "\\" RuleNames "/" Strategy -> Strategy
    {cons("DynRuleUnion"), right} >
    Strategy "/" RuleNames "\\" RuleNames "/" Strategy -> Strategy
    {cons("DynRuleIntersectUnion"), right} >
    Strategy ";" Strategy -> Strategy {cons("Seq"), right}

module Stratego-Sugar-Rules
imports Stratego-Sugar-Strategies

exports
  sorts RuleDef

  context-free syntax
    Id ":" Rule                                           -> RuleDef {cons("RDefNoArgs")}
    Id "(" {Typedid ","}* ")" ":" Rule                    -> RuleDef {cons("RDef")}
    Id "(" {Typedid ","}* "|" {Typedid ","}* ")" ":" Rule -> RuleDef {cons("RDefT")}

  sorts Rule RuleCond

  context-free syntax
    Term "->" Term                  -> Rule     {cons("RuleNoCond")}
    Term "->" Term "where" Strategy -> Rule     {cons("Rule")}
    Term "->" Term RuleCond+        -> Rule     {cons("Rule"), avoid}
    "where" Strategy                -> RuleCond {cons("WhereClause")}
    "with" Strategy                 -> RuleCond {cons("WithClause")}

module Stratego-Sugar-Strategies
imports Stratego-Core-Strategies Stratego-Sugar-Terms Stratego-Sugar-Constants
        Stratego-Sugar-Signatures

exports
  context-free syntax
    Id "=" Strategy                        -> StrategyDef {cons("SDefNoArgs")}
    Id "(" {Typedid ","}* ")" "=" Strategy -> StrategyDef {cons("SDef")}

  context-free syntax
    ID -> Typedid {cons("DefaultVarDec")}

  sorts Rule

  sorts StrategyParen StrategyCurly StrategyAngle

  context-free syntax
    SVar "(" {Strategy ","}* ")"          -> Strategy      {cons("Call")}
    "{" Strategy "}"                      -> Strategy      {cons("ScopeDefault")}
    StrategyAngle Term                    -> Strategy      {cons("BA")}
    "<" Strategy ">"                      -> StrategyAngle {bracket}
    Strategy "<+" Strategy                -> Strategy      {cons("LChoice"), right}
    "rec" Id "(" Strategy ")"             -> Strategy      {cons("Rec")}
    "not" "(" Strategy ")"                -> Strategy      {cons("Not")}
    "where" "(" Strategy ")"              -> Strategy      {cons("Where")}
    "with" "(" Strategy ")"               -> Strategy      {cons("With"), prefer}
    "test" "(" Strategy ")"               -> Strategy      {cons("Test")}
    "prim" "(" String ")"                 -> Strategy      {cons("PrimNoArgs")}
    "prim" "(" String "," {Term ","}* ")" -> Strategy      {cons("Prim")}
    String                                -> Strategy      {cons("StrCong")}
    Int                                   -> Strategy      {cons("IntCong")}
    Real                                  -> Strategy      {cons("RealCong")}
    Char                                  -> Strategy      {cons("CharCong")}
    String "(" {Strategy ","}* ")"        -> Strategy      {cons("CongQ")}
    Strategy StrategyCurly                -> Strategy      {cons("AnnoCong")}
    "{" Strategy "}"                      -> StrategyCurly {cons("StrategyCurly")}
    "(" ")"                               -> Strategy      {cons("EmptyTupleCong")}
    "(" Strategy ")"                      -> Strategy      {bracket}
    "(" Strategy "," {Strategy ","}+ ")"  -> Strategy      {cons("TupleCong")}
    "[" {Strategy ","}* "]"               -> Strategy      {cons("ListCongNoTail")}
    "[" {Strategy ","}* "|" Strategy "]"  -> Strategy      {cons("ListCong")}
    Strategy "#" StrategyParen            -> Strategy      {cons("ExplodeCong")}

  sorts SwitchCase

  context-free syntax
    SVar                                                         -> Strategy   {cons("CallNoArgs")}
    "\\" Rule "\\"                                               -> Strategy   {cons("LRule")}
    "(" Rule ")"                                                 -> Strategy   {cons("SRule")}
    Strategy "+" Strategy                                        -> Strategy   {cons("Choice"), right}
    Strategy "+>" Strategy                                       -> Strategy   {cons("RChoice"), right}
    "if" Strategy "then" Strategy "else" Strategy "end"          -> Strategy   {cons("CondChoice")}
    "if" Strategy "then" Strategy "end"                          -> Strategy   {cons("IfThen")}
    "switch" Strategy SwitchCase* "end"                          -> Strategy   {cons("SwitchChoiceNoOtherwise")}
    "switch" Strategy SwitchCase* "otherwise" ":" Strategy "end" -> Strategy   {cons("SwitchChoice")}
    "case" Strategy ":" Strategy                                 -> SwitchCase {cons("SwitchCase")}
    Strategy "=>" Term                                           -> Strategy   {cons("AM")}
    Term ":=" Term                                               -> Strategy   {cons("Assign")}

  context-free priorities
    { Strategy StrategyCurly -> Strategy 
      Strategy "#" StrategyParen -> Strategy  } >
    { "!" Term -> Strategy 
      "?" Term -> Strategy  } >
    StrategyAngle Term -> Strategy  >
    Strategy "=>" Term -> Strategy  >
    Strategy ";" Strategy -> Strategy  >
    {right:
      Strategy "+" Strategy -> Strategy 
      Strategy "<+" Strategy -> Strategy 
      Strategy "+>" Strategy -> Strategy 
      Strategy "<" StrategyMid "+" Strategy -> Strategy 
    }

  context-free priorities
    Strategy -> StrategyMid  >
    Strategy "+" Strategy -> Strategy 

  context-free priorities
    { Strategy StrategyCurly -> Strategy 
      Strategy "#" StrategyParen -> Strategy  } . >
    Term ":=" Term -> Strategy 

module Stratego-Sugar-Terms
imports Stratego-Core-Terms Stratego-Sugar-Strategies

exports
  sorts LID

  context-free syntax
    LId -> LID {cons("ListVar")}
    LID -> Var {cons("Var")}
    LID -> ID  

  context-free syntax
    "_" PreTerm                  -> PreTerm {cons("BuildDefaultPT")}
    "_" Term                     -> Term    {cons("BuildDefault"), prefer}
    Char                         -> PreTerm {cons("Char")}
    PreTerm "{" {Term ","}* "}"  -> Term    {cons("AnnoList")}
    PreTerm                      -> Term    {cons("NoAnnoList")}
    "<" Strategy ">" Term        -> PreTerm {cons("App")}
    "<" Strategy ">" Term        -> Term    {cons("App"), prefer}
    StrategyAngle                -> PreTerm {cons("RootApp")}
    StrategyAngle                -> Term    {cons("RootApp"), prefer}
    "(" {Term ","}* ")"          -> PreTerm {cons("Tuple")}
    "[" {Term ","}* "]"          -> PreTerm {cons("List")}
    "[" {Term ","}* "|" Term "]" -> PreTerm {cons("ListTail")}

  context-free priorities
    Term "#" "(" Term ")" -> PreTerm {cons("Explode")} >
    PreTerm "{" {Term ","}* "}" -> Term {cons("AnnoList")} >
    Var "@" Term -> Term {cons("As")}

module Stratego-Sugar-Signatures
imports Stratego-Core-Signatures Stratego-Sugar-Constants

exports
  sorts Sort

  context-free syntax
    "[" {Sort ","}* "]"          -> Sort {cons("SortList")}
    "[" {Sort ","}* "|" Sort "]" -> Sort {cons("SortListTl")}
    "(" {Sort ","}* ")"          -> Sort {cons("SortTuple")}

  sorts Kind

  context-free syntax
    "*"  -> Kind {cons("Star")}
    "**" -> Kind {cons("StarStar")}

module Stratego-Core-Signatures
imports Stratego-Core-Identifiers Stratego-Core-Constants

exports
  sorts Sdecl

  context-free syntax
    "sorts" Sort*          -> Sdecl {cons("Sorts")}
    "constructors" Opdecl* -> Sdecl {cons("Constructors")}

  sorts Sort

  context-free syntax
    LCID                   -> Sort {cons("SortVar")}
    UCID                   -> Sort {cons("SortNoArgs")}
    Id "(" {Sort ","}* ")" -> Sort {cons("Sort")}

  sorts Opdecl

  context-free syntax
    Id ":" Type     -> Opdecl {cons("OpDecl")}
    String ":" Type -> Opdecl {cons("OpDeclQ")}
    ":" Type        -> Opdecl {cons("OpDeclInj")}

  context-free syntax
    "external" Id ":" Type     -> Opdecl {cons("ExtOpDecl")}
    "external" String ":" Type -> Opdecl {cons("ExtOpDeclQ")}
    "external" ":" Type        -> Opdecl {cons("ExtOpDeclInj")}

  sorts Type ArgType ConstType FunType RetType

  context-free syntax
    Sort                        -> ConstType {cons("ConstType")}
    {ArgType "*"}+ "->" RetType -> FunType   {cons("FunType")}
    "(" Type ")"                -> ArgType   {bracket}
    ConstType                   -> ArgType   
    Type                        -> RetType   
    FunType                     -> RetType   {reject}
    FunType                     -> Type      
    ConstType                   -> Type      

  context-free restrictions
    Sort -/- [\(]

module Stratego-Core-Terms
imports Stratego-Core-Identifiers Stratego-Core-Constants

exports
  sorts ID Var Wld

  context-free syntax
    Id -> Var {cons("Var")}
    Id -> ID  

  sorts Term PreTerm

  context-free syntax
    Var                        -> PreTerm 
    Var                        -> Term    {prefer}
    "_"                        -> Wld     {cons("Wld")}
    Wld                        -> PreTerm 
    Wld                        -> Term    {prefer}
    Int                        -> PreTerm {cons("Int")}
    Real                       -> PreTerm {cons("Real")}
    String                     -> PreTerm {cons("Str")}
    Id "(" {Term ","}* ")"     -> PreTerm {cons("Op")}
    String "(" {Term ","}* ")" -> PreTerm {cons("OpQ")}
    Term "#" "(" Term ")"      -> PreTerm {cons("Explode")}
    PreTerm "{^" PreTerm "}"   -> Term    {cons("Anno")}
    Var "@" Term               -> Term    {cons("As"), prefer}
    Var "@" PreTerm            -> PreTerm {cons("As")}

  context-free priorities
    Term "#" "(" Term ")" -> PreTerm {cons("Explode")} >
    Var "@" Term -> Term {cons("As")}

module Stratego-Core-Strategies
imports Stratego-Core-Terms Stratego-Core-Constants Stratego-Core-Signatures

exports
  sorts Def

  context-free syntax
    StrategyDef                                             -> Def      
    Id                                                      -> SVar     {cons("SVar")}
    "let" Def* "in" Strategy "end"                          -> Strategy {cons("Let")}
    SVar "(" {Strategy ","}* "|" {Term ","}* ")"            -> Strategy {cons("CallT")}
    "call" "(" Term "|" {Strategy ","}* "|" {Term ","}* ")" -> Strategy {cons("CallDynamic")}

  sorts StrategyDef

  context-free syntax
    Id "(" {Typedid ","}* "|" {Typedid ","}* ")" "=" Strategy            -> StrategyDef {cons("SDefT")}
    "external" Id "(" {Typedid ","}* "|" {Typedid ","}* ")" "=" Strategy -> StrategyDef {cons("ExtSDefInl")}
    "external" Id "(" {Typedid ","}* "|" {Typedid ","}* ")"              -> StrategyDef {cons("ExtSDef")}

  sorts Typedid

  context-free syntax
    ID ":" Type -> Typedid {cons("VarDec")}

  sorts Strategy SVar StrategyParen StrategyMid

  context-free syntax
    "(" Strategy ")"                                          -> StrategyParen {cons("ParenStrat")}
    "fail"                                                    -> Strategy      {cons("Fail")}
    "id"                                                      -> Strategy      {cons("Id")}
    "?" Term                                                  -> Strategy      {cons("Match")}
    "!" Term                                                  -> Strategy      {cons("Build")}
    "{" {ID ","}* ":" Strategy "}"                            -> Strategy      {cons("Scope")}
    Strategy ";" Strategy                                     -> Strategy      {cons("Seq"), right}
    Strategy "<" StrategyMid "+" Strategy                     -> Strategy      {cons("GuardedLChoice"), right}
    Strategy                                                  -> StrategyMid   
    "prim" "(" String "," {Strategy ","}* "|" {Term ","}* ")" -> Strategy      {cons("PrimT")}
    "some" "(" Strategy ")"                                   -> Strategy      {cons("Some")}
    "one" "(" Strategy ")"                                    -> Strategy      {cons("One")}
    "all" "(" Strategy ")"                                    -> Strategy      {cons("All")}

  context-free priorities
    { "!" Term -> Strategy {cons("Build")}
      "?" Term -> Strategy {cons("Match")} } >
    Strategy ";" Strategy -> Strategy {cons("Seq"), right} >
    {right:
      Strategy "<" StrategyMid "+" Strategy -> Strategy
      {cons("GuardedLChoice"), right}
    }

  context-free syntax
    "import-term" "(" ModName ")" -> Strategy {cons("ImportTerm")}

module Stratego-Core-Modules
imports Stratego-Core-Identifiers Stratego-Core-Strategies
        Stratego-Core-Signatures

exports
  sorts Module

  context-free syntax
    "module" ModName Decl* -> Module {cons("Module")}
    "specification" Decl*  -> Module {cons("Specification")}

  sorts Decl

  context-free syntax
    "imports" ImportModName* -> Decl {cons("Imports")}
    "strategies" Def*        -> Decl {cons("Strategies")}
    "signature" Sdecl*       -> Decl {cons("Signature")}

  sorts ImportModName

  context-free syntax
    ModName -> ImportModName {cons("Import")}

  syntax
    <ModName-CF> "/" "-" -> <ImportModName-CF> {cons("ImportWildcard")}

module Stratego-Sugar-Modules
imports Stratego-Core-Modules Stratego-Sugar-Strategies
        Stratego-Sugar-Signatures Stratego-Sugar-Overlays Stratego-Sugar-Rules

exports
  sorts Decl Def

  context-free syntax
    "rules" Def*        -> Decl {cons("Rules")}
    "overlays" Overlay* -> Decl {cons("Overlays")}
    RuleDef             -> Def  

module Stratego-Core-Constants
exports
  sorts Int Real String StrChar

  lexical syntax
    [\-]? [0-9]+             -> Int     
    [\-]? [0-9]+ [\.] [0-9]+ -> Real    
    "\"" StrChar* "\""       -> String  
    ~[\"\\]                  -> StrChar 
    [\\] [\"tnr\\]           -> StrChar 

module Stratego-Sugar-Constants
imports Stratego-Core-Identifiers Stratego-Core-Constants

exports
  sorts Char CharChar

  lexical syntax
    "'" CharChar "'" -> Char     
    ~[\']            -> CharChar 
    [\\] [\'ntr\ ]   -> CharChar 
    Char             -> Id       {reject}

module Stratego-Core-Identifiers
exports
  sorts ModName ModNamePart

  lexical syntax
    {ModNamePart "/"}+                -> ModName     
    [a-zA-Z\.\_] [a-zA-Z0-9\'\.\-\_]* -> ModNamePart 

  lexical restrictions
    ModName -/- [a-zA-Z0-9\'\.\-\_]

  lexical syntax
    "imports"    -> ModName {reject}
    "overlays"   -> ModName {reject}
    "rules"      -> ModName {reject}
    "signature"  -> ModName {reject}
    "strategies" -> ModName {reject}

  sorts Id LId LCID UCID Wld

  lexical syntax
    [a-zA-Z\_] [a-zA-Z0-9\'\-\_]*     -> Id   
    [a-zA-Z\_] [a-zA-Z0-9\'\-\_]* "*" -> LId  
    [\'] [a-z]+                       -> Id   
    [a-z] [a-zA-Z0-9\'\-\_]*          -> LCID 
    [A-Z] [a-zA-Z0-9\'\-\_]*          -> UCID 

  lexical restrictions
    Id -/- [a-zA-Z0-9\'\-\_\*]
    LId -/- [a-zA-Z0-9\'\-\_]
    LCID -/- [a-zA-Z0-9\'\-\_]
    UCID -/- [a-zA-Z0-9\'\-\_]

  lexical syntax
    "_"     -> Id   {reject}
    "'"     -> Id   {reject}
    Keyword -> Id   {reject}
    Keyword -> LId  {reject}
    Keyword -> LCID {reject}
    Keyword -> UCID {reject}

  lexical restrictions
    "all" "case" "constructors" "else" "end" "external" "fail" "id" "if" "in"
    "imports" "let" "module" "not" "one" "overlays" "otherwise" "prim" "rec"
    "rules" "script" "signature" "some" "sorts" "strategies" "stratego" "switch"
    "test" "then" "where" "import-term" -/- [a-zA-Z0-9\'\-\_]

  context-free restrictions
    Wld -/- [a-zA-Z0-9\'\-\_]

  sorts Keyword

  lexical syntax
    "all"          -> Keyword 
    "constructors" -> Keyword 
    "fail"         -> Keyword 
    "id"           -> Keyword 
    "in"           -> Keyword 
    "let"          -> Keyword 
    "module"       -> Keyword 
    "not"          -> Keyword 
    "one"          -> Keyword 
    "overlays"     -> Keyword 
    "prim"         -> Keyword 
    "rules"        -> Keyword 
    "script"       -> Keyword 
    "signature"    -> Keyword 
    "some"         -> Keyword 
    "sorts"        -> Keyword 
    "strategies"   -> Keyword 
    "stratego"     -> Keyword 
    "test"         -> Keyword 
    "where"        -> Keyword 
    "import-term"  -> Keyword 

module Stratego-Core-Layout
exports
  sorts Ws ShortCom LongCom CommChar Asterisk Eof

  lexical syntax
    [\t\ \n\r]             -> Ws       
    "//" ~[\n]* [\n] | Eof -> ShortCom 
    "/*" CommChar* "*/"    -> LongCom  
                           -> Eof      
    ~[\*]                  -> CommChar 
    "*"                    -> Asterisk 
    Asterisk               -> CommChar 

  lexical restrictions
    Asterisk -/- [\/]
    Eof -/- ~[]

  lexical syntax
    ShortCom -> LAYOUT 
    LongCom  -> LAYOUT 
%%    Ws       -> LAYOUT 

  context-free restrictions
    LAYOUT? -/- [\ \t\n\r]
    LAYOUT? -/- [\/] . [\*]
    LAYOUT? -/- [\/] . [\/]

module Stratego-Sugar-Layout
imports Stratego-Core-Layout

module Stratego-Sugar
imports Stratego-Sugar-Layout Stratego-Core-Identifiers Stratego-Sugar-Constants
        Stratego-Sugar-Modules Stratego-Sugar-Signatures Stratego-Sugar-Terms
        Stratego-Sugar-Strategies Stratego-Sugar-Rules
        Stratego-Sugar-DynamicRules Stratego-Sugar-Overlays

module Stratego
imports Stratego-Sugar

module org/sugarj/languages/Stratego
imports Stratego
          [ RuleNames      => StrategoRuleNames
            RuleDec        => StrategoRuleDec
            DynRuleScopeId => StrategoDynRuleScopeId
            DynRuleId      => StrategoDynRuleId
            DynRuleDef     => StrategoDynRuleDef
            ScopeLabels    => StrategoScopeLabels
            RuleCond       => StrategoRuleCond
            Rule           => StrategoRule
            RuleDef        => StrategoRuleDef
            Overlay        => StrategoOverlay
            SwitchCase     => StrategoSwitchCase
            StrategyCurly  => StrategoStrategyCurly
            StrategyAngle  => StrategoStrategyAngle
            Kind           => StrategoKind
            LID            => StrategoLID
            ImportModName  => StrategoImportModName
            Decl           => StrategoDecl
            Module         => StrategoModule
            StrategyParen  => StrategoStrategyParen
            Typedid        => StrategoTypedid
            StrategyDef    => StrategoStrategyDef
            SVar           => StrategoSVar
            Def            => StrategoDef
            Type           => StrategoType
            RetType        => StrategoRetType
            ArgType        => StrategoArgType
            FunType        => StrategoFunType
            ConstType      => StrategoConstType
            Opdecl         => StrategoOpdecl
            Sort           => StrategoSort
            Sdecl          => StrategoSdecl
            Wld            => StrategoWld
            ID             => StrategoID
            Var            => StrategoVar
            CharChar       => StrategoCharChar
            Char           => StrategoChar
            StrChar        => StrategoStrChar
            String         => StrategoString
            Real           => StrategoReal
            Int            => StrategoInt
            Keyword        => StrategoKeyword
            UCID           => StrategoUCID
            LCID           => StrategoLCID
            LId            => StrategoLId
            Id             => StrategoId
            ModNamePart    => StrategoModNamePart
            ModName        => StrategoModName
            Asterisk       => StrategoAsterisk
            CommChar       => StrategoCommChar
            Eof            => StrategoEof
            LongCom        => StrategoLongCom
            ShortCom       => StrategoShortCom
            Ws             => StrategoWs
            PreTerm        => StrategoPreTerm
            Term           => StrategoTerm
            StrategyMid    => StrategoStrategyMid
            Strategy       => StrategoStrategy ]

exports
  context-free start-symbols
    StrategoModule