Example #1
0
  /*
   * Parses Groovy-style 'in' clause
   */
  private static boolean forInClauseParse(PsiBuilder builder, GroovyParser parser) {

    PsiBuilder.Marker marker = builder.mark();

    PsiBuilder.Marker declMarker = builder.mark();

    if (ParserUtils.lookAhead(builder, mIDENT, kIN)) {
      ParserUtils.eatElement(builder, PARAMETER);
      declMarker.drop();
      ParserUtils.getToken(builder, kIN);
      if (!ShiftExpression.parse(builder, parser)) {
        builder.error(GroovyBundle.message("expression.expected"));
      }
      marker.done(FOR_IN_CLAUSE);
      return true;
    }

    if (DeclarationStart.parse(builder, parser)) {
      if (Modifiers.parse(builder, parser)) {
        TypeSpec.parse(builder);
        return singleDeclNoInitParse(builder, marker, declMarker, parser);
      }
    }

    if (TypeSpec.parse(builder)) {
      return singleDeclNoInitParse(builder, marker, declMarker, parser);
    }

    declMarker.drop();
    marker.drop();
    return false;
  }
Example #2
0
 private static boolean singleDeclNoInitParse(
     PsiBuilder builder,
     PsiBuilder.Marker marker,
     PsiBuilder.Marker declMarker,
     GroovyParser parser) {
   if (ParserUtils.getToken(builder, mIDENT)) {
     if (kIN.equals(builder.getTokenType()) || mCOLON.equals(builder.getTokenType())) {
       declMarker.done(PARAMETER);
       builder.advanceLexer();
       if (!ShiftExpression.parse(builder, parser)) {
         builder.error(GroovyBundle.message("expression.expected"));
       }
       marker.done(FOR_IN_CLAUSE);
       return true;
     } else {
       marker.rollbackTo();
       return false;
     }
   } else {
     declMarker.drop();
     marker.rollbackTo();
     return false;
   }
 }