@Nullable
  public PsiBuilder.Marker parseConditional(final PsiBuilder builder) {
    final PsiBuilder.Marker condition = parseExpression(builder, ExprType.CONDITIONAL_OR);
    if (condition == null) return null;

    if (builder.getTokenType() != JavaTokenType.QUEST) return condition;
    final PsiBuilder.Marker ternary = condition.precede();
    builder.advanceLexer();

    final PsiBuilder.Marker truePart = parse(builder);
    if (truePart == null) {
      error(builder, JavaErrorMessages.message("expected.expression"));
      ternary.done(JavaElementType.CONDITIONAL_EXPRESSION);
      return ternary;
    }

    if (builder.getTokenType() != JavaTokenType.COLON) {
      error(builder, JavaErrorMessages.message("expected.colon"));
      ternary.done(JavaElementType.CONDITIONAL_EXPRESSION);
      return ternary;
    }
    builder.advanceLexer();

    final PsiBuilder.Marker falsePart = parseConditional(builder);
    if (falsePart == null) {
      error(builder, JavaErrorMessages.message("expected.expression"));
      ternary.done(JavaElementType.CONDITIONAL_EXPRESSION);
      return ternary;
    }

    ternary.done(JavaElementType.CONDITIONAL_EXPRESSION);
    return ternary;
  }
 private void parseListLiteralExpression(final PsiBuilder builder, boolean isTargetExpression) {
   LOG.assertTrue(builder.getTokenType() == PyTokenTypes.LBRACKET);
   final PsiBuilder.Marker expr = builder.mark();
   builder.advanceLexer();
   if (builder.getTokenType() == PyTokenTypes.RBRACKET) {
     builder.advanceLexer();
     expr.done(PyElementTypes.LIST_LITERAL_EXPRESSION);
     return;
   }
   if (!parseSingleExpression(isTargetExpression)) {
     builder.error(message("PARSE.expected.expression"));
   }
   if (builder.getTokenType() == PyTokenTypes.FOR_KEYWORD) {
     parseComprehension(expr, PyTokenTypes.RBRACKET, PyElementTypes.LIST_COMP_EXPRESSION);
   } else {
     while (builder.getTokenType() != PyTokenTypes.RBRACKET) {
       if (!matchToken(PyTokenTypes.COMMA)) {
         builder.error("expected ',' or ']'");
       }
       if (atToken(PyTokenTypes.RBRACKET)) {
         break;
       }
       if (!parseSingleExpression(isTargetExpression)) {
         builder.error(message("PARSE.expected.expr.or.comma.or.bracket"));
         break;
       }
     }
     checkMatches(PyTokenTypes.RBRACKET, message("PARSE.expected.rbracket"));
     expr.done(PyElementTypes.LIST_LITERAL_EXPRESSION);
   }
 }
Exemplo n.º 3
0
  private static boolean tradForClauseParse(PsiBuilder builder, GroovyParser parser) {

    PsiBuilder.Marker marker = builder.mark();

    if (ParserUtils.getToken(builder, mSEMI)
        || (Declaration.parse(builder, false, parser) && ParserUtils.getToken(builder, mSEMI))) {
      StrictContextExpression.parse(builder, parser);
      ParserUtils.getToken(builder, mSEMI, GroovyBundle.message("semi.expected"));
      ParserUtils.getToken(builder, mNLS);
      if (!mRPAREN.equals(builder.getTokenType())) {
        controlExpressionListParse(builder, parser);
      }
    } else {
      marker.rollbackTo();
      marker = builder.mark();
      controlExpressionListParse(builder, parser);
      ParserUtils.getToken(builder, mSEMI, GroovyBundle.message("semi.expected"));
      StrictContextExpression.parse(builder, parser);
      ParserUtils.getToken(builder, mSEMI, GroovyBundle.message("semi.expected"));
      ParserUtils.getToken(builder, mNLS);
      if (!mRPAREN.equals(builder.getTokenType())) {
        controlExpressionListParse(builder, parser);
      }
    }

    marker.done(FOR_TRADITIONAL_CLAUSE);
    return true;
  }
 private void passEOLsAndIndents(final PsiBuilder builder) {
   IElementType tokenType = builder.getTokenType();
   while (tokenType == myEolTokenType || tokenType == myIndentTokenType) {
     builder.advanceLexer();
     tokenType = builder.getTokenType();
   }
 }
  public static void parseDefine(PsiBuilder builder) {
    PsiBuilder.Marker maker = builder.mark();

    // #define
    advanceLexerAndSkipLines(builder);

    // var name
    doneOneToken(builder, CPsiCompilerVariable.class);

    PsiBuilder.Marker valueMarker = builder.mark();

    while (!builder.eof()) {
      if (builder.getTokenType() == NEW_LINE) break;

      if (builder.getTokenType() == NEXT_LINE) builder.advanceLexer();

      builder.advanceLexer();
    }

    done(valueMarker, CPsiSharpDefineValue.class);

    done(maker, CPsiSharpDefine.class);

    skipLines(builder);
  }
  private static IElementType parseMethod(
      PsiBuilder builder,
      boolean isAnnotationMember,
      boolean hasModifiers,
      GroovyParser parser,
      boolean constructor) {
    // if we have no modifiers and current method is not constructor there is something wrong
    if (!hasModifiers && !constructor) {
      builder.error(GroovyBundle.message("method.definition.without.modifier"));
      return GroovyElementTypes.WRONGWAY;
    }

    builder.advanceLexer();

    ParameterList.parse(builder, GroovyTokenTypes.mRPAREN, parser);

    ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
    if (!ParserUtils.getToken(builder, GroovyTokenTypes.mRPAREN)) {
      builder.error(GroovyBundle.message("rparen.expected"));
      ThrowClause.parse(builder);
      return methodType(isAnnotationMember, constructor);
    }

    if (isAnnotationMember && builder.getTokenType() == GroovyTokenTypes.kDEFAULT) {
      ParserUtils.getToken(builder, GroovyTokenTypes.kDEFAULT);
      ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);

      if (!AnnotationArguments.parseAnnotationMemberValueInitializer(builder, parser)) {
        builder.error(GroovyBundle.message("annotation.initializer.expected"));
      }
    }

    if (ParserUtils.lookAhead(builder, GroovyTokenTypes.mNLS, GroovyTokenTypes.kTHROWS)
        || ParserUtils.lookAhead(builder, GroovyTokenTypes.mNLS, GroovyTokenTypes.mLCURLY)) {
      ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
    }

    if (isAnnotationMember && builder.getTokenType() == GroovyTokenTypes.kTHROWS) {
      builder.error(GroovyBundle.message("throws.clause.is.not.allowed.in.at.interface"));
    }
    ThrowClause.parse(builder);

    if (builder.getTokenType() == GroovyTokenTypes.mLCURLY
        || ParserUtils.lookAhead(builder, GroovyTokenTypes.mNLS, GroovyTokenTypes.mLCURLY)) {
      ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
      if (isAnnotationMember) {
        builder.error(GroovyBundle.message("separator.or.rcurly.expected"));
      }
      if (constructor) {
        ConstructorBody.parseConstructorBody(builder, parser);
      } else {
        OpenOrClosableBlock.parseOpenBlock(builder, parser);
      }
    }

    return methodType(isAnnotationMember, constructor);
  }
  @Nullable
  private PsiBuilder.Marker parseUnary(final PsiBuilder builder) {
    final IElementType tokenType = builder.getTokenType();

    if (PREFIX_OPS.contains(tokenType)) {
      final PsiBuilder.Marker unary = builder.mark();
      builder.advanceLexer();

      final PsiBuilder.Marker operand = parseUnary(builder);
      if (operand == null) {
        error(builder, JavaErrorMessages.message("expected.expression"));
      }

      unary.done(JavaElementType.PREFIX_EXPRESSION);
      return unary;
    } else if (tokenType == JavaTokenType.LPARENTH) {
      final PsiBuilder.Marker typeCast = builder.mark();
      builder.advanceLexer();

      ReferenceParser.TypeInfo typeInfo =
          myParser
              .getReferenceParser()
              .parseTypeInfo(
                  builder,
                  ReferenceParser.EAT_LAST_DOT
                      | ReferenceParser.WILDCARD
                      | ReferenceParser.CONJUNCTIONS
                      | ReferenceParser.INCOMPLETE_ANNO);
      if (typeInfo == null || !expect(builder, JavaTokenType.RPARENTH)) {
        typeCast.rollbackTo();
        return parsePostfix(builder);
      }

      if (PREF_ARITHMETIC_OPS.contains(builder.getTokenType()) && !typeInfo.isPrimitive) {
        typeCast.rollbackTo();
        return parsePostfix(builder);
      }

      final PsiBuilder.Marker expr = parseUnary(builder);
      if (expr == null) {
        if (!typeInfo
            .isParameterized) { // cannot parse correct parenthesized expression after correct
                                // parameterized type
          typeCast.rollbackTo();
          return parsePostfix(builder);
        } else {
          error(builder, JavaErrorMessages.message("expected.expression"));
        }
      }

      typeCast.done(JavaElementType.TYPE_CAST_EXPRESSION);
      return typeCast;
    } else {
      return parsePostfix(builder);
    }
  }
Exemplo n.º 8
0
 /**
  * Checks for version token and convert if necessary
  *
  * @param b PerlBuilder
  * @param l parsing level
  * @return parsing result
  */
 public static boolean parsePerlVersion(PsiBuilder b, int l) {
   if (b.getTokenType() == NUMBER_VERSION) return consumeToken(b, NUMBER_VERSION);
   else if (VERSION_TOKENS.contains(b.getTokenType())) {
     PsiBuilder.Marker m = b.mark();
     b.advanceLexer();
     m.collapse(NUMBER_VERSION);
     return true;
   }
   return false;
 }
  @Nullable
  private PsiBuilder.Marker parseArrayInitializer(final PsiBuilder builder) {
    if (builder.getTokenType() != JavaTokenType.LBRACE) return null;

    final PsiBuilder.Marker arrayInit = builder.mark();
    builder.advanceLexer();

    boolean expressionMissed = false;
    PsiBuilder.Marker lastComma = null;
    while (true) {
      if (builder.getTokenType() == JavaTokenType.RBRACE) {
        builder.advanceLexer();
        break;
      }

      if (builder.getTokenType() == null) {
        error(builder, JavaErrorMessages.message("expected.rbrace"));
        break;
      }

      if (expressionMissed && lastComma != null) {
        // before comma must be an expression
        lastComma
            .precede()
            .errorBefore(JavaErrorMessages.message("expected.expression"), lastComma);
        lastComma.drop();
        lastComma = null;
      }

      final PsiBuilder.Marker arg = parse(builder);
      if (arg == null) {
        if (builder.getTokenType() == JavaTokenType.COMMA) {
          expressionMissed = true;
          lastComma = builder.mark();
        } else {
          error(builder, JavaErrorMessages.message("expected.rbrace"));
          break;
        }
      }

      final IElementType tokenType = builder.getTokenType();
      if (tokenType == JavaTokenType.COMMA) {
        builder.advanceLexer();
      } else if (tokenType != JavaTokenType.RBRACE) {
        error(builder, JavaErrorMessages.message("expected.comma"));
      }
    }

    if (lastComma != null) {
      lastComma.drop();
    }

    arrayInit.done(JavaElementType.ARRAY_INITIALIZER_EXPRESSION);
    return arrayInit;
  }
Exemplo n.º 10
0
  /**
   * Joining several regex tokens into one to lighten PSI tree. Temporary solution, until regex
   * parsing is implemented
   *
   * @param b PerlBuilder
   * @param l parsing level
   * @return parsing result
   */
  public static boolean joinRegexTokens(PsiBuilder b, int l) {
    if (b.getTokenType() == REGEX_TOKEN) {
      PsiBuilder.Marker m = b.mark();

      while (b.getTokenType() == REGEX_TOKEN) b.advanceLexer();

      m.collapse(REGEX_TOKEN);
      return true;
    }
    return false;
  }
 public boolean parseStringLiteralExpression() {
   final PsiBuilder builder = myContext.getBuilder();
   if (PyTokenTypes.STRING_NODES.contains(builder.getTokenType())) {
     final PsiBuilder.Marker marker = builder.mark();
     while (PyTokenTypes.STRING_NODES.contains(builder.getTokenType())) {
       nextToken();
     }
     marker.done(PyElementTypes.STRING_LITERAL_EXPRESSION);
     return true;
   }
   return false;
 }
Exemplo n.º 12
0
  public static boolean parseSubPrototype(PsiBuilder b, int l) {
    PsiBuilder.Marker m = null;

    IElementType tokenType = b.getTokenType();
    while (!b.eof() && (tokenType != RIGHT_PAREN)) {
      if (m == null) m = b.mark();

      b.advanceLexer();
      tokenType = b.getTokenType();
    }
    if (m != null) m.collapse(SUB_PROTOTYPE_TOKEN);

    return true;
  }
Exemplo n.º 13
0
  /**
   * Statement recovery function. Should not consume token, only check;
   *
   * @param b PerlBuilder
   * @param l parsing level
   * @return parsing result
   */
  public static boolean recoverStatement(PsiBuilder b, int l) {
    assert b instanceof PerlBuilder;

    if (!((PerlBuilder) b).isRecoveringStatement()) ((PerlBuilder) b).startRecovery();

    IElementType currentTokenType = b.getTokenType();

    //		System.err.println("Checking " + b.getTokenText() + currentTokenType);

    if (currentTokenType == null // got end of file
        || ((PerlBuilder) b).getBracesLevel() == 0
            && ( // we are not in braced statement
            UNCONDITIONAL_STATEMENT_RECOVERY_TOKENS.contains(
                    currentTokenType) // got semi, package, end of regex, use, compound or suffix
                || currentTokenType == RESERVED_SUB
                    && STATEMENT_RECOVERY_SUB_SUFFIX.contains(b.lookAhead(1)) // got sub definition
            )) {
      ((PerlBuilder) b).stopRecovery();
      return false;
    }

    if (currentTokenType == LEFT_BRACE) ((PerlBuilder) b).openBrace();
    else if (currentTokenType == RIGHT_BRACE) ((PerlBuilder) b).closeBrace();

    return true;
  }
Exemplo n.º 14
0
  /**
   * Named list operators
   *
   * @param b PerlBuilder
   * @param l Parsing level
   * @return parsing result
   */
  public static boolean isListOperator(PsiBuilder b, int l) {
    PerlTokenData prevTokenData = ((PerlBuilder) b).lookupToken(-1);

    if (prevTokenData != null && prevTokenData.getTokenType() == OPERATOR_DEREFERENCE) return false;

    IElementType tokenType = b.getTokenType();
    IElementType nextTokenType = b.lookAhead(1);

    if (CONVERTABLE_TOKENS.contains(tokenType)
        && nextTokenType != LEFT_PAREN // not function call
        && !PACKAGE_TOKENS.contains(nextTokenType) // not method Package::
        && !(nextTokenType == IDENTIFIER
            && ((PerlBuilder) b)
                .isKnownPackage(
                    ((PerlBuilder) b).lookupToken(1).getTokenText())) // not Method Package
    )
      // todo we should check current namespace here
      return !PerlSubUtil.BUILT_IN_UNARY.contains(b.getTokenText());
    else if (PACKAGE_TOKENS.contains(tokenType)
        && CONVERTABLE_TOKENS.contains(nextTokenType)
        && b.lookAhead(2) != LEFT_PAREN)
      return !PerlSubUtil.isUnary(
          b.getTokenText(), ((PerlBuilder) b).lookupToken(1).getTokenText());

    return false;
  }
Exemplo n.º 15
0
  public static boolean parse(
      PsiBuilder builder, boolean isInClass, boolean isInAnnotation, GroovyParser parser) {
    PsiBuilder.Marker declMarker = builder.mark();
    // allows error messages
    boolean modifiersParsed = Modifiers.parse(builder, parser);

    final boolean methodStart = mLT == builder.getTokenType();
    final IElementType type =
        parseAfterModifiers(
            builder, isInClass, isInAnnotation, parser, declMarker, modifiersParsed);
    if (type == WRONGWAY) {
      if (modifiersParsed && methodStart) {
        declMarker.error(GroovyBundle.message("method.definitions.expected"));
        return false;
      }

      declMarker.rollbackTo();
      if (modifiersParsed) {
        builder.error(GroovyBundle.message("variable.definitions.expected"));
      }

      return false;
    }

    if (type != null) {
      declMarker.done(type);
    } else {
      declMarker.drop();
    }
    return true;
  }
Exemplo n.º 16
0
  // @todo this is really raw
  public static boolean parseSubAttributes(PsiBuilder b, int l) {

    PsiBuilder.Marker m = null;
    IElementType tokenType = b.getTokenType();
    while (!b.eof()
        && tokenType != LEFT_BRACE
        && tokenType != SEMICOLON
        && tokenType != EMBED_MARKER_SEMICOLON) {
      if (m == null) m = b.mark();
      b.advanceLexer();
      tokenType = b.getTokenType();
    }
    if (m != null) m.collapse(SUB_ATTRIBUTE);

    return true;
  }
 private void getNextTokenValue(PsiBuilder builder) {
   PsiBuilder.Marker rb = builder.mark();
   builder.advanceLexer();
   nextToken = builder.getTokenType();
   nextTokenText = builder.getTokenText();
   rb.rollbackTo();
 }
 public static boolean nextTokenIsFast(PsiBuilder builder, IElementType... tokens) {
   IElementType tokenType = builder.getTokenType();
   for (IElementType token : tokens) {
     if (token == tokenType) return true;
   }
   return false;
 }
  public static boolean parseMasonMethod(
      PsiBuilder b, int l, IElementType closeToken, IElementType statementTokenType) {
    boolean r = false;

    PsiBuilder.Marker methodMarker = b.mark();
    b.advanceLexer();
    PsiBuilder.Marker subMarker = b.mark();
    if (PerlParserUtil.consumeToken(b, IDENTIFIER)) {
      subMarker.collapse(SUB);
      PerlParserImpl.method_signature(b, l);
      if (PerlParserUtil.consumeToken(b, MASON_TAG_CLOSER)) {
        PsiBuilder.Marker blockMarker = b.mark();
        PerlParserImpl.block_content(b, l);

        if (b.getTokenType() == closeToken) {
          blockMarker.done(BLOCK);
          blockMarker.setCustomEdgeTokenBinders(
              WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
          b.advanceLexer();
          methodMarker.done(statementTokenType);
          r = true;
        }
      }
    }

    if (!r) {
      methodMarker.rollbackTo();
    }

    return r || recoverToGreedy(b, closeToken, "Error");
  }
  @Nullable
  private PsiBuilder.Marker parseLambdaExpression(
      final PsiBuilder builder, final boolean typed, @Nullable final PsiBuilder.Marker typeList) {
    final PsiBuilder.Marker start = typeList != null ? typeList.precede() : builder.mark();

    myParser.getDeclarationParser().parseLambdaParameterList(builder, typed);

    if (!expect(builder, JavaTokenType.ARROW)) {
      start.rollbackTo();
      return null;
    }

    final PsiBuilder.Marker body;
    if (builder.getTokenType() == JavaTokenType.LBRACE) {
      body = myParser.getStatementParser().parseCodeBlock(builder);
    } else {
      body = parse(builder);
    }

    if (body == null) {
      builder.error(JavaErrorMessages.message("expected.lbrace"));
    }

    start.done(JavaElementType.LAMBDA_EXPRESSION);
    return start;
  }
 @Override
 public boolean parseStatementModifier(PsiBuilder b, int l) {
   if (b.getTokenType() == MASON_FILTERED_BLOCK_OPENER) {
     return parsePerlBlock(b, l, MASON_FILTERED_BLOCK_CLOSER, MASON_FILTERED_BLOCK);
   }
   return super.parseStatementModifier(b, l);
 }
 private void parseReprExpression(PsiBuilder builder) {
   LOG.assertTrue(builder.getTokenType() == PyTokenTypes.TICK);
   final PsiBuilder.Marker expr = builder.mark();
   builder.advanceLexer();
   parseExpression();
   checkMatches(PyTokenTypes.TICK, message("PARSE.expected.tick"));
   expr.done(PyElementTypes.REPR_EXPRESSION);
 }
Exemplo n.º 23
0
  /**
   * Smart parser for ->, makes }->[ optional
   *
   * @param b PerlBuilder
   * @param l parsing level
   * @return parsing result
   */
  public static boolean parseArrowSmart(PsiBuilder b, int l) {
    IElementType tokenType = b.getTokenType();
    if (b.getTokenType() == OPERATOR_DEREFERENCE) {
      return consumeToken(b, OPERATOR_DEREFERENCE);
    } else {
      assert b instanceof PerlBuilder;
      PerlTokenData prevToken = ((PerlBuilder) b).lookupToken(-1);
      IElementType prevTokenType = prevToken == null ? null : prevToken.getTokenType();

      // optional }->[ or ]->{
      if ((prevTokenType == RIGHT_BRACE || prevTokenType == RIGHT_BRACKET)
          && (tokenType == LEFT_BRACE || tokenType == LEFT_BRACKET || tokenType == LEFT_PAREN))
        return true;
    }

    return false;
  }
Exemplo n.º 24
0
  @NotNull
  public static PsiBuilder.Marker parseArgumentList(final PsiBuilder builder) {
    final PsiBuilder.Marker list = builder.mark();
    builder.advanceLexer();

    boolean first = true;
    while (true) {
      final IElementType tokenType = builder.getTokenType();
      if (first && (ARGS_LIST_END.contains(tokenType) || builder.eof())) break;
      if (!first && !ARGS_LIST_CONTINUE.contains(tokenType)) break;

      boolean hasError = false;
      if (!first) {
        if (builder.getTokenType() == JavaTokenType.COMMA) {
          builder.advanceLexer();
        } else {
          hasError = true;
          error(builder, JavaErrorMessages.message("expected.comma.or.rparen"));
          emptyExpression(builder);
        }
      }
      first = false;

      final PsiBuilder.Marker arg = parse(builder);
      if (arg == null) {
        if (!hasError) {
          error(builder, JavaErrorMessages.message("expected.expression"));
          emptyExpression(builder);
        }
        if (!ARGS_LIST_CONTINUE.contains(builder.getTokenType())) break;
        if (builder.getTokenType() != JavaTokenType.COMMA && !builder.eof()) {
          builder.advanceLexer();
        }
      }
    }

    final boolean closed =
        JavaParserUtil.expectOrError(
            builder, JavaTokenType.RPARENTH, JavaErrorMessages.message("expected.rparen"));

    list.done(JavaElementType.EXPRESSION_LIST);
    if (!closed) {
      list.setCustomEdgeTokenBinders(null, GREEDY_RIGHT_EDGE_PROCESSOR);
    }
    return list;
  }
Exemplo n.º 25
0
 public static boolean parse(final PsiBuilder builder) {
   boolean result = false;
   while (!builder.eof() && SEPARATOR.contains(builder.getTokenType())) {
     builder.advanceLexer();
     result = true;
   }
   return result;
 }
  public static void parse(@NotNull PsiBuilder builder, int f) {
    while (!builder.eof()) {
      skipLines(builder);

      if (builder.getTokenType() == S_INCLUDE_KEYWORD) parseInclude(builder);
      else if (builder.getTokenType() == S_DEFINE_KEYWORD) parseDefine(builder);
      else if (builder.getTokenType() == S_IFNDEF_KEYWORD
          || builder.getTokenType() == S_IFDEF_KEYWORD) parseIf(builder);
      else if (builder.getTokenType() == S_ENDIF_KEYWORD
          || builder.getTokenType() == S_ELSE_KEYWORD) {
        if (isSet(f, EAT_LAST_END_IF)) {
          error(builder, "S_IFDEF.or.S_IFNDEF.expected");
          advanceLexerAndSkipLines(builder);
        } else break;
      } else builder.advanceLexer();
    }
  }
Exemplo n.º 27
0
  /*
   * Parses list of control expression in for condition
   */
  private static void controlExpressionListParse(PsiBuilder builder, GroovyParser parser) {

    if (!StrictContextExpression.parse(builder, parser)) return;

    while (mCOMMA.equals(builder.getTokenType())) {

      if (ParserUtils.lookAhead(builder, mCOMMA, mNLS, mRPAREN)
          || ParserUtils.lookAhead(builder, mCOMMA, mRPAREN)) {
        ParserUtils.getToken(builder, mCOMMA);
        builder.error(GroovyBundle.message("expression.expected"));
      } else {
        ParserUtils.getToken(builder, mCOMMA);
      }
      ParserUtils.getToken(builder, mNLS);
      if (!StrictContextExpression.parse(builder, parser)) {
        ParserUtils.getToken(builder, mNLS);
        if (!mRPAREN.equals(builder.getTokenType()) && !mSEMI.equals(builder.getTokenType())) {
          builder.error(GroovyBundle.message("expression.expected"));
        }
        if (!mRPAREN.equals(builder.getTokenType())
            && !mSEMI.equals(builder.getTokenType())
            && !mCOMMA.equals(builder.getTokenType())
            && !mNLS.equals(builder.getTokenType())) {
          builder.advanceLexer();
        }
      }
    }
  }
  @Nullable
  private PsiBuilder.Marker parseLambdaAfterParenth(
      final PsiBuilder builder, @Nullable final PsiBuilder.Marker typeList) {
    final boolean isLambda;
    final boolean isTyped;

    final IElementType nextToken1 = builder.lookAhead(1);
    final IElementType nextToken2 = builder.lookAhead(2);
    if (nextToken1 == JavaTokenType.RPARENTH && nextToken2 == JavaTokenType.ARROW) {
      isLambda = true;
      isTyped = false;
    } else if (nextToken1 == JavaTokenType.AT
        || ElementType.MODIFIER_BIT_SET.contains(nextToken1)
        || ElementType.PRIMITIVE_TYPE_BIT_SET.contains(nextToken1)) {
      isLambda = true;
      isTyped = true;
    } else if (nextToken1 == JavaTokenType.IDENTIFIER) {
      if (nextToken2 == JavaTokenType.COMMA
          || nextToken2 == JavaTokenType.RPARENTH && builder.lookAhead(3) == JavaTokenType.ARROW) {
        isLambda = true;
        isTyped = false;
      } else if (nextToken2 == JavaTokenType.ARROW) {
        isLambda = false;
        isTyped = false;
      } else {
        boolean arrow = false;

        final PsiBuilder.Marker marker = builder.mark();
        while (!builder.eof()) {
          builder.advanceLexer();
          final IElementType tokenType = builder.getTokenType();
          if (tokenType == JavaTokenType.ARROW) {
            arrow = true;
            break;
          }
          if (tokenType == JavaTokenType.RPARENTH) {
            arrow = builder.lookAhead(1) == JavaTokenType.ARROW;
            break;
          } else if (tokenType == JavaTokenType.LPARENTH
              || tokenType == JavaTokenType.SEMICOLON
              || tokenType == JavaTokenType.LBRACE
              || tokenType == JavaTokenType.RBRACE) {
            break;
          }
        }
        marker.rollbackTo();

        isLambda = arrow;
        isTyped = true;
      }
    } else {
      isLambda = false;
      isTyped = false;
    }

    return isLambda ? parseLambdaExpression(builder, isTyped, typeList) : null;
  }
Exemplo n.º 29
0
 public static boolean nextTokenIsInner(PsiBuilder builder_, IElementType token, boolean force) {
   ErrorState state = ErrorState.get(builder_);
   if (state.completionState != null && !force) return true;
   IElementType tokenType = builder_.getTokenType();
   if (!state.suppressErrors && state.predicateCount < 2) {
     addVariant(state, builder_, token);
   }
   return token == tokenType;
 }
 protected static boolean recoverTo(PsiBuilder b, IElementType toElement, String errorMessage) {
   // recover bad code
   PsiBuilder.Marker errorMarker = b.mark();
   while (!b.eof() && b.getTokenType() != toElement) {
     b.advanceLexer();
     ;
   }
   errorMarker.error(errorMessage);
   return b.eof();
 }