scala.editing/src/org/netbeans/modules/scala/editing/rats/ParserScala.rats
author Caoyuan Deng <dcaoyuan@netbeans.org>
Mon Jun 09 16:50:29 2008 +0800 (3 weeks ago)
changeset 13249 d638cbfa3c9b
parent 1324503c3e007e485
permissions -rw-r--r--
Syntax: only one TypeArgs allowed in SimpleType
        1 /*
        2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
        3  * 
        4  * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
        5  * 
        6  * The contents of this file are subject to the terms of either the GNU
        7  * General Public License Version 2 only ("GPL") or the Common
        8  * Development and Distribution License("CDDL") (collectively, the
        9  * "License"). You may not use this file except in compliance with the
       10  * License. You can obtain a copy of the License at
       11  * http://www.netbeans.org/cddl-gplv2.html
       12  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
       13  * specific language governing permissions and limitations under the
       14  * License.  When distributing the software, include this License Header
       15  * Notice in each file and include the License file at
       16  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
       17  * particular file as subject to the "Classpath" exception as provided
       18  * by Sun in the GPL Version 2 section of the License file that
       19  * accompanied this code. If applicable, add the following below the
       20  * License Header, with the fields enclosed by brackets [] replaced by
       21  * your own identifying information:
       22  * "Portions Copyrighted [year] [name of copyright owner]"
       23  * 
       24  * If you wish your version of this file to be governed by only the CDDL
       25  * or only the GPL Version 2, indicate your decision by adding
       26  * "[Contributor] elects to include this software in this distribution
       27  * under the [CDDL or GPL Version 2] license." If you do not indicate a
       28  * single choice of license, a recipient has the option to distribute
       29  * your version of this file under either the CDDL, the GPL Version 2 or
       30  * to extend the choice of license to its licensees as provided above.
       31  * However, if you add GPL Version 2 code and therefore, elected the GPL
       32  * Version 2 license, then the option applies only if the new code is
       33  * made subject to such option by the copyright holder.
       34  * 
       35  * Contributor(s):
       36  * 
       37  * Portions Copyrighted 2008 Sun Microsystems, Inc.
       38  */
       39 
       40 /*
       41  * Definition of Scala Grammar Definition.
       42  * 
       43  * @author Caoyuan Deng
       44  */
       45 module org.netbeans.modules.scala.editing.rats.ParserScala;
       46 
       47 import org.netbeans.modules.scala.editing.rats.Character;
       48 import org.netbeans.modules.scala.editing.rats.Identifier;
       49 import org.netbeans.modules.scala.editing.rats.Keyword;
       50 import org.netbeans.modules.scala.editing.rats.Literal;
       51 import org.netbeans.modules.scala.editing.rats.Spacing;
       52 import org.netbeans.modules.scala.editing.rats.Symbol;
       53 import org.netbeans.modules.scala.editing.rats.Xml;
       54 
       55 import org.netbeans.modules.scala.editing.rats.State;
       56 
       57 modify org.netbeans.modules.scala.editing.rats.Xml;
       58 
       59 option withLocation;
       60 
       61 /* @Note: Modified productions should always be put at the beginning */
       62 
       63 // ----- Modify XmlContent in Xml.rats
       64 generic XmlContent +=
       65   <ScalaExpr> ScalaExpr
       66 / <XmlCDSect> ...
       67 ;
       68 
       69 // ----- Modify XmlAttValue in Xml.rats
       70 generic XmlAttValue +=
       71   <XmlAttValue> ...
       72 / <ScalaExpr>   ScalaExpr
       73 ;
       74 
       75 // ----- Modify XmlCharData in Xml.rats
       76 generic XmlCharData := xmlCharDataInScala;
       77 
       78 /* @Note: If we modify xmlCharDataChar in Xml.rats, we cannot add transient */
       79 transient String xmlCharDataInScala = xmlCharDataCharInScala+;
       80 transient String xmlCharDataCharInScala =
       81   "{{"
       82 / "}}"
       83 / !( [<&] / "]]>" / [{}] ) _ 
       84 ;
       85 
       86 
       87 /* @Note: We cannot consumer every token's tail whitespace (leave it for XmlExpr 
       88  * to detect a preceding whitespace, instead, we consumer every token's preceding
       89  * whitespace and ignore it. 
       90  */
       91 generic XmlExpr =
       92   void:w       XmlElement
       93 / void:"(":sep XmlElement void:")":sep 
       94 / void:"{":sep XmlElement void:"}":sep
       95 ;
       96 
       97 // ----- XmlPattern
       98 
       99 generic XmlPattern = 
      100   void:w       XmlElementP
      101 / void:"(":sep XmlElementP void:")":sep 
      102 / void:"{":sep XmlElementP void:"}":sep
      103 ;
      104 
      105 generic XmlContentP = 
      106   <ScalaPatterns> ScalaPatterns
      107 / <XmlCDSect>     XmlCDSect
      108 / <XmlPI>         XmlPI        
      109 / <XmlCharData>   XmlCharData
      110 / <XmlElement>    XmlElementP
      111 / <XmlReference>  XmlReference
      112 / <XmlComment>    XmlComment
      113 ;
      114 
      115 generic XmlElementP =
      116   XmlEmptyElemTagP
      117 / XmlSTagP XmlContentP* XmlETag
      118 ;
      119 
      120 transient generic XmlEmptyElemTagP = XmlLt XmlEmptyTagName XmlWs? XmlSlashGt ;
      121 transient generic XmlSTagP = XmlLt XmlSTagName XmlWs? XmlGt ;
      122 
      123 /* @DocError in ScalaReference: ScalaExpr ::= '{' expr '}' */
      124 transient generic ScalaExpr     = void:"{":sep !( void:"{":sep ) Block    void:"}":sep !( void:"}":sep );
      125 transient generic ScalaPatterns = void:"{":sep !( void:"{":sep ) Patterns void:"}":sep !( void:"}":sep );
      126 
      127 
      128 // ----- Literal
      129 
      130 generic Literal =
      131   SKIP ( "-":op )? FloatingPointLiteral 
      132 / SKIP ( "-":op )? IntegerLiteral
      133 / SKIP             BooleanLiteral
      134 / SKIP             NullLiteral          
      135 / SKIP             CharacterLiteral     
      136 / SKIP             StringLiteral        
      137 / SKIP             SymbolLiteral
      138 ;
      139 
      140 transient generic BooleanLiteral = "true":key / "false":key;
      141 transient generic NullLiteral = "null" ;
      142 
      143 transient void SEMI = void:";":sep N* / N+ ;
      144 
      145 transient generic QualId = Id ( void:".":sep Id )* ;
      146 transient generic Ids    = Id ( void:",":sep Id )* ;
      147 
      148 generic Path =
      149   StableId
      150 / ( Id void:".":sep )? ThisKey 
      151 ;
      152 
      153 generic StableId = 
      154   ( Id void:".":sep )? ThisKey                  ( void:".":sep Id )* ( void:"." SKIP ErrorIdExpected )?
      155 / ( Id void:".":sep )? SuperKey ClassQualifier? ( void:".":sep Id )* ( void:"." SKIP ErrorIdExpected )?
      156 /                      Id                       ( void:".":sep Id )* ( void:"." SKIP ErrorIdExpected )?
      157 ;
      158 
      159 /* StableId may be followed by '{' '_' in Import, and "type", so should considerate this case */
      160 transient generic ErrorIdExpected = !( [{_] / "type":key ) { yyValue = GNode.create("Error", "Id expected"); } ;
      161 
      162 transient generic ClassQualifier = void:"[":sep Id void:"]":sep;
      163 
      164 generic Type = 
      165   FunType
      166 / NotFunType
      167 ;
      168 
      169 generic FunType =
      170   void:"(":sep ( void:"=>":key Type )? void:")":sep void:"=>":key Type @CallByNameFunType
      171 / InfixType void:"=>":key Type                                         @NormalFunType
      172 ;
      173 
      174 /* in CaseClause, we should leave the latest "=>" for ( "=>" Block ) */
      175 generic FunTypeInCaseClause =
      176   void:"(":sep ( void:"=>":key Type )? void:")":sep void:"=>":key ( NotFunType void:"=>":key )*
      177 / InfixType void:"=>":key ( NotFunType void:"=>":key )*
      178 ;
      179 
      180 transient generic NotFunType = InfixType ExistentialClause? ;
      181 
      182 transient generic ExistentialClause = "forSome":key void:"{":sep ExistentialDcl ( SEMI ExistentialDcl )* void:"}":sep;
      183 
      184 transient generic ExistentialDcl = 
      185   void:"type":key TypeDcl
      186 / void:"val" :key ValDcl
      187 ;
      188 
      189 generic InfixType = CompoundType InfixTypeRest* ;
      190 generic InfixTypeRest = Id N? CompoundType ;
      191 
      192 generic CompoundType = 
      193   AnnotType ( void:"with":key AnnotType )* Refinement?
      194 / Refinement
      195 ;
      196 
      197 generic AnnotType = Annotation* SimpleType ;
      198 
      199 generic SimpleType = 
      200   Path void:".":sep void:"type":key                 TypeArgs? ( void:"#":key Id )* @SimpleSingletonType
      201 / StableId                                          TypeArgs? ( void:"#":key Id )* @SimpleIdType
      202 / void:"(":sep Types ( void:",":sep )? void:")":sep TypeArgs? ( void:"#":key Id )* @SimpleTupleType
      203 ;
      204 
      205 transient generic TypeArgs = void:"[":sep Types void:"]":sep ;
      206 
      207 /* @DocError in ScalaReference: Type in Types can be "_" */
      208 transient generic Types = ( Type / WildKey) ( void:",":sep ( Type / WildKey) )* ;
      209 
      210 transient generic Refinement = N? void:"{":sep RefineStat? ( SEMI RefineStat? )* void:"}":sep ;
      211 
      212 generic RefineStat = 
      213   void:"type":key TypeDef
      214 / Dcl
      215 ;
      216 
      217 generic Ascription = 
      218   void:":":key CompoundType
      219 / void:":":key Annotation Annotation*
      220 / void:":":key "_":key "*":op
      221 ;
      222 
      223 generic Expr = 
      224   ( Bindings / Id ) void:"=>":key Expr
      225 / NotFunExpr;
      226 
      227 generic NotFunExpr = 
      228   void:"if"    :key void:"(":sep ENTER_NL_DISABLE Expr EXIT_NL_DISABLE void:")":sep N* Expr ( SEMI? void:"else":key Expr )?                  @IfExpr
      229 / void:"while" :key void:"(":sep ENTER_NL_DISABLE Expr EXIT_NL_DISABLE void:")":sep N* Expr                                                  @WhileExpr
      230 / void:"try"   :key void:"{":sep Block void:"}":sep ( void:"catch":key void:"{":sep CaseClauses void:"}":sep )? ( void:"finally":key Expr )? @TryExpr
      231 / void:"do"    :key Expr SEMI? void:"while":key void:"(":sep ENTER_NL_DISABLE Expr EXIT_NL_DISABLE void:")":sep                              @DoExpr
      232 / void:"for"   :key ( void:"(":sep Enumerators void:")":sep / void:"{":sep Enumerators void:"}":sep ) N* ( void:"yield":key )? Expr          @ForExpr
      233 / void:"throw" :key Expr         @ThrowExpr
      234 / void:"return":key Expr?        @ReturnExpr
      235 / SimpleExpr   void:"=":key Expr @AssignmentExpr
      236 / PostfixExpr  Ascription        @AscriptionExpr
      237 / PostfixExpr  void:"match":key void:"{":sep CaseClauses void:"}":sep  @MatchExpr
      238 / PostfixExpr
      239 ;
      240 
      241 /*
      242 generic AssignmentExpr = 
      243   ( SimpleExpr void:".":sep )? Id void:"=":key Expr
      244 / SimpleExpr ArgumentExprs void:"=":key Expr
      245 ;
      246 */
      247 
      248 /* @DocError in ScalaReference: InfixExpr ( Id N? )? */
      249 generic PostfixExpr = InfixExpr Id? ;
      250 
      251 generic InfixExpr = PrefixExpr InfixExprRest* ;
      252 generic InfixExprRest = Id N? PrefixExpr;
      253 
      254 generic PrefixExpr = ( "-":op / "+":op / "~":op / "!":op )? SimpleExpr ;
      255 
      256 /* @DocError in ScalaReference : There is non SimpleExpr with ( void:":":key Type ) */
      257 generic SimpleExpr = 
      258   XmlExpr   TypeArgs?                Member* ( void:"." SKIP ErrorIdExpected )?                      
      259 / Literal   TypeArgs?                Member* ( void:"." SKIP ErrorIdExpected )?                       
      260 / Path      TypeArgs? ArgumentExprs? Member* ( void:"." SKIP ErrorIdExpected )? ( void:":":key Type )? 
      261 / WildKey   TypeArgs?                Member* ( void:"." SKIP ErrorIdExpected )?                          
      262 / ParenExpr TypeArgs?                Member* ( void:"." SKIP ErrorIdExpected )? ( void:":":key Type )? 
      263 / BlockExpr TypeArgs?                Member* ( void:"." SKIP ErrorIdExpected )?                          
      264 / NewExpr   TypeArgs?                Member* ( void:"." SKIP ErrorIdExpected )?                       
      265 ;
      266 
      267 generic Member = 
      268   void:".":sep Id TypeArgs? ArgumentExprs?
      269 / ArgumentExprs // apply
      270 / WildKey;
      271 
      272 transient generic NewExpr = 
      273   void:"new":key ( ClassTemplate / TemplateBody)
      274 / SKIP void:"new" SKIP ErrorClassTemplateExpected 
      275 ;
      276 
      277 transient generic ErrorClassTemplateExpected = { yyValue = GNode.create("Error", "ClassTemplate expected"); } ;
      278 
      279 transient generic Exprs = Expr ( void:",":sep Expr )*;
      280 
      281 generic ArgumentExprs =
      282   ParenExpr
      283 / N? BlockExpr
      284 ;
      285 
      286 generic ParenExpr = 
      287   void:"(":sep ENTER_NL_DISABLE
      288   ( Exprs ( void:",":sep )? )? 
      289   EXIT_NL_DISABLE void:")":sep 
      290 ;
      291 
      292 generic BlockExpr = 
      293   void:"{":sep CaseClauses void:"}":sep
      294 / void:"{":sep Block       void:"}":sep
      295 ;
      296 
      297 generic Block = 
      298   ENTER_NL_ENABLE 
      299   ( BlockStat SEMI )* ResultExpr?
      300   EXIT_NL_ENABLE 
      301 ;
      302 
      303 transient generic BlockStat = 
      304   Import
      305 / ( "implicit":key / "lazy":key )* Def
      306 / LocalModifier* TmplDef
      307 / !ResultFunExpr NotFunExpr
      308 / 
      309 ;
      310 
      311 generic ResultExpr =
      312   ResultFunExpr
      313 / NotFunExpr
      314 ;
      315 
      316 generic ResultFunExpr = ( Bindings / ResultBinding ) void:"=>":key Block ;
      317 /* @DocError in ScalaReference: Id void:":":key CompoundType */
      318 generic ResultBinding = Id ( void:":":key CompoundType )? ;
      319 
      320 transient generic Enumerators = Generator ( SEMI Enumerator )*;
      321 
      322 transient generic Enumerator = 
      323   Generator
      324 / Guard
      325 / void:"val":key Pattern1 void:"=":key Expr
      326 ;
      327 
      328 /* @Note "val" is deprecated */
      329 transient generic Generator = ( void:"val":key )? Pattern1 void:"<-":key Expr Guard? ;
      330 
      331 transient generic CaseClauses = CaseClause CaseClause* ;
      332 /* @Hacking greedy Pattern will consumer latest "=>" to try to recognize as FunType,
      333  * we should leave lastest "=>" for Block by define a FunTypeInCaseClause 
      334  * 
      335  * A case token can begin a statement only if followed by a class or object token
      336  * @Todo nl in case clause
      337  */
      338 generic CaseClause =   
      339   SKIP_N void:"case":key ENTER_NL_DISABLE
      340   ( ( VarId / "_":key ) void:":" :key FunTypeInCaseClause EXIT_NL_DISABLE Block
      341   / Pattern N* Guard?   void:"=>":key                     EXIT_NL_DISABLE Block 
      342   )
      343 ;
      344 
      345 transient generic Guard = void:"if":key PostfixExpr ;
      346 
      347 generic Pattern = 
      348   AlternatePattern
      349 / Pattern1 
      350 ;
      351 
      352 transient generic AlternatePattern = Pattern1 void:"|":sep Pattern1 ( void:"|":sep Pattern1 )* ;
      353 
      354 generic Pattern1 =
      355   TypedPattern
      356 / NoTypedPattern
      357 ;
      358 
      359 generic TypedPattern =
      360   VarId   void:":":key Type
      361 / "_":key void:":":key Type
      362 ;
      363 
      364 // ----- Pattern2
      365 generic NoTypedPattern =
      366   AtPattern
      367 / Pattern3
      368 ;
      369 
      370 generic AtPattern = VarId void:"@":key Pattern3 ;
      371 
      372 generic Pattern3 = 
      373   SimplePattern InfixPatternTail InfixPatternTail*
      374 / SimplePattern;
      375 
      376 transient generic InfixPatternTail = Id N? SimplePattern ;
      377 
      378 /* @DocError in ScalaReference: "_":key */
      379 generic SimplePattern =
      380   XmlPattern            @SimpleXmlPattern
      381 / "_":key ( "*":op )?   @SimpleWildcardPattern
      382 / Literal               @SimpleLiteralPattern
      383 / TuplePattern          @SimpleTuplePattern
      384 / StableId TuplePattern @SimpleCallPattern
      385 / StableId              @SimpleIdPattern
      386 ;
      387 
      388 transient generic TuplePattern = void:"(":sep Patterns? void:")":sep ;
      389 
      390 transient generic Patterns = 
      391   Pattern ( void:",":sep Pattern )* ( ",":sep "_":key "*":op / ",":sep )? 
      392 / "_":key "*":op
      393 ;
      394 
      395 transient generic TypeParamClause = void:"[":sep VariantTypeParam ( void:",":sep VariantTypeParam )* void:"]":sep ;
      396 
      397 transient generic FunTypeParamClause = void:"[":sep TypeParam ( void:",":sep TypeParam )* void:"]":sep ;
      398 
      399 transient generic VariantTypeParam = ( "+":op / "-":op )? TypeParam ;
      400 
      401 transient generic TypeParam = ( Id / WildKey ) TypeParamClause? ( void:">:":key Type )? ( void:"<:":key Type )? ( void:"<%":key Type )? ;
      402 
      403 transient generic ParamClauses = ParamClause* ( N? void:"(":sep void:"implicit":key Params void:")":sep )? ;
      404 
      405 transient generic ParamClause = N? void:"(":sep Params? void:")":sep ;
      406 
      407 transient generic Params = Param ( void:",":sep Param )* ;
      408 
      409 transient generic Param = Annotation* Id ( void:":":key ParamType )? ;
      410 
      411 transient generic ParamType = 
      412   Type "*":op
      413 / Type
      414 / "=>":key Type
      415 ;
      416 
      417 transient generic ClassParamClauses = ClassParamClause* ( N? void:"(":sep void:"implicit":key ClassParams void:")":sep )? ;
      418 
      419 transient generic ClassParamClause = N? void:"(":sep ClassParams? void:")":sep ;
      420 
      421 transient generic ClassParams = ClassParam ( void:",":sep ClassParam )* ;
      422 
      423 transient generic ClassParam = Annotation* ( Modifier* ( void:"val":key / void:"var":key ) )? Id ( void:":":key ParamType )? ;
      424 
      425 /* @DocError in ScalaReference: void:"(":sep Binding ( void:",":sep Binding )* void:")":sep */
      426 transient generic Bindings = void:"(":sep Binding? ( void:",":sep Binding )* void:")":sep ;
      427 transient generic Binding = Id ( void:":":key Type )? ;
      428 
      429 generic Modifier = 
      430   LocalModifier
      431 / AccessModifier
      432 / "override":key
      433 ;
      434 
      435 generic LocalModifier = 
      436   "abstract":key
      437 / "final"   :key
      438 / "sealed"  :key
      439 / "implicit":key
      440 / "lazy"    :key
      441 ;
      442 
      443 transient generic AccessModifier = ( "private":key / "protected":key ) AccessQualifier? ;
      444 
      445 transient generic AccessQualifier = void:"[":sep ( Id / ThisKey ) void:"]":sep ;
      446 
      447 generic Annotation = "@":key AnnotationExpr N? ;
      448 
      449 /* @DocError in ScalaReference: AnnotationExpr = Constr ( N? void:"{":sep NameValuePair* void:"}":sep )? */
      450 generic AnnotationExpr = Constr ( N? void:"{":sep NameValuePairs* void:"}":sep )?;
      451 
      452 generic NameValuePairs = NameValuePair ( void:",":sep NameValuePair )* ;
      453 generic NameValuePair = void:"val":key Id void:"=":key PrefixExpr;
      454 
      455 generic TemplateBody = N? void:"{":sep SelfType? TemplateStat ( SEMI TemplateStat )* void:"}":sep ;
      456 
      457 generic TemplateStat = 
      458   Import
      459 / Annotation* Modifier* Def
      460 / Annotation* Modifier* Dcl
      461 / Expr
      462 / 
      463 ;
      464 
      465 generic SelfType = 
      466   Id     ( void:":":key Type )? void:"=>":key
      467 / ThisKey  void:":":key Type    void:"=>":key
      468 ;
      469 
      470 transient generic Import = 
      471   void:"import":key ImportExpr ( void:",":sep ImportExpr )* 
      472 / void:"import" SKIP ErrorStableIdExpected
      473 ;
      474 
      475 transient generic ErrorStableIdExpected = { yyValue = GNode.create("Error", "StableId expected"); } ;
      476 
      477 transient generic ImportExpr = StableId ( void:".":sep ( WildKey / ImportSelectors ) )?;
      478 
      479 transient generic ImportSelectors = void:"{":sep ( ImportSelector void:",":sep )* ( ImportSelector / WildKey ) void:"}":sep ;
      480 
      481 transient generic ImportSelector = Id ( void:"=>":key ( Id / WildKey ) )? ;
      482 
      483 generic Dcl = 
      484   void:"val" :key ValDcl
      485 / void:"var" :key VarDcl
      486 / void:"def" :key FunDcl
      487 / void:"type":key N* TypeDcl
      488 ;
      489 
      490 transient generic ValDcl = Ids      void:":":key Type ;
      491 transient generic VarDcl = Ids      void:":":key Type ;
      492 transient generic FunDcl = FunSig ( void:":":key Type )? ;
      493 
      494 transient generic FunSig = Id FunTypeParamClause? ParamClauses ;
      495 
      496 transient generic TypeDcl = Id TypeParamClause? ( void:">:":key Type )? ( void:"<:":key Type )? ;
      497 
      498 generic PatVarDef = 
      499   void:"val":key ValDef
      500 / void:"var":key VarDef
      501 ;
      502 
      503 generic Def = 
      504   PatVarDef
      505 / void:"def" :key FunDef
      506 / void:"type":key N* TypeDef
      507 / TmplDef
      508 ;
      509 
      510 transient generic PatDef = NoTypedPattern ( void:",":sep NoTypedPattern )* ( void:":":key Type )? void:"=":key Expr ;
      511 
      512 transient generic ValDef = PatDef ;
      513 
      514 generic VarDef = 
      515   PatDef
      516 / Ids void:":":key Type "=":key "_":key
      517 ;
      518 
      519 generic FunDef = 
      520   FunSig ( void:":":key Type )? void:"=":key Expr
      521 / FunSig N? void:"{":sep Block void:"}":sep
      522 / ThisKey ParamClause ParamClauses ( void:"=":key ConstrExpr / N? ConstrBlock ) @ConstructorFunDef
      523 ;
      524 
      525 generic TypeDef = Id TypeParamClause? void:"=":key Type ;
      526 
      527 generic TmplDef =
      528   ( "case":key )? void:"class" :key ClassDef
      529 / ( "case":key )? void:"object":key ObjectDef
      530 /                 void:"trait" :key TraitDef
      531 ;
      532 
      533 transient generic ClassDef  = Id TypeParamClause? Annotation* AccessModifier? ClassParamClauses ClassTemplateOpt ;
      534 transient generic TraitDef  = Id TypeParamClause?                                               TraitTemplateOpt ;
      535 transient generic ObjectDef = Id                                                                ClassTemplateOpt ;
      536 
      537 generic ClassTemplateOpt = 
      538   Extends  ClassTemplate 
      539 / Extends? TemplateBody
      540 / 
      541 ;
      542 
      543 generic TraitTemplateOpt =
      544   Extends  TraitTemplate 
      545 / Extends? TemplateBody
      546 / 
      547 ;
      548 
      549 generic Extends = "extends":key / "<:":key ;
      550 
      551 transient generic ClassTemplate = ( void:"{":sep EarlyDefs? void:"}":sep void:"with":key )? ClassParents TemplateBody? ;
      552 transient generic TraitTemplate = ( void:"{":sep EarlyDefs? void:"}":sep void:"with":key )? TraitParents TemplateBody? ;
      553 
      554 transient generic ClassParents = Constr    ( void:"with":key AnnotType )* ;
      555 transient generic TraitParents = AnnotType ( void:"with":key AnnotType )* ;
      556 
      557 transient generic Constr = AnnotType ArgumentExprs* ;
      558 
      559 transient generic EarlyDefs = EarlyDef ( SEMI EarlyDef )* ;
      560 transient generic EarlyDef = Annotation* Modifier* PatVarDef ;
      561 
      562 generic ConstrExpr = 
      563   SelfInvocation
      564 / ConstrBlock
      565 ;
      566 
      567 transient generic ConstrBlock = void:"{":sep SelfInvocation ( SEMI BlockStat )* void:"}":sep ;
      568 
      569 transient generic SelfInvocation = ThisKey ArgumentExprs ArgumentExprs* ;
      570 
      571 transient generic TopStatSeq = TopStat ( SEMI TopStat )* ;
      572 
      573 generic TopStat = 
      574   Import
      575 / Packaging
      576 / Annotation* Modifier* TmplDef
      577 / 
      578 ;
      579 
      580 transient generic Packaging = void:"package":key QualId N? void:"{":sep TopStatSeq void:"}":sep ;
      581 transient generic Package   = void:"package":key QualId SEMI !( "{":sep );
      582 
      583 public generic CompilationUnit = SKIP_N Package? TopStatSeq EOF;
      584