Exemple #1
0
  /*
   * toplevelObject
   *   : namespace
   *   : class
   *   : extension
   *   : function
   *   : property
   *   : typedef
   *   : object
   *   ;
   */
  private void parseTopLevelObject() {
    PsiBuilder.Marker decl = mark();

    TokenDetector detector = new TokenDetector(ENUM_KEYWORD);
    parseModifierList(MODIFIER_LIST, detector, true);

    IElementType keywordToken = tt();
    IElementType declType = null;
    //        if (keywordToken == PACKAGE_KEYWORD) {
    //            declType = parseNamespaceBlock();
    //        }
    //        else
    if (keywordToken == CLASS_KEYWORD || keywordToken == TRAIT_KEYWORD) {
      declType = parseClass(detector.isDetected());
    } else if (keywordToken == FUN_KEYWORD) {
      declType = parseFunction();
    } else if (keywordToken == VAL_KEYWORD || keywordToken == VAR_KEYWORD) {
      declType = parseProperty();
    } else if (keywordToken == TYPE_KEYWORD) {
      declType = parseTypeDef();
    } else if (keywordToken == OBJECT_KEYWORD) {
      parseObject(true, true);
      declType = OBJECT_DECLARATION;
    }

    if (declType == null) {
      errorAndAdvance("Expecting package directive or top level declaration");
      decl.drop();
    } else {
      decl.done(declType);
    }
  }
Exemple #2
0
  /*
   * memberDeclaration
   *   : modifiers memberDeclaration'
   *   ;
   *
   * memberDeclaration'
   *   : classObject
   *   : constructor
   *   : function
   *   : property
   *   : class
   *   : extension
   *   : typedef
   *   : anonymousInitializer
   *   : object
   *   ;
   */
  private void parseMemberDeclaration() {
    PsiBuilder.Marker decl = mark();

    TokenDetector enumDetector = new TokenDetector(ENUM_KEYWORD);
    parseModifierList(MODIFIER_LIST, enumDetector, true);

    IElementType declType = parseMemberDeclarationRest(enumDetector.isDetected());

    if (declType == null) {
      errorWithRecovery("Expecting member declaration", TokenSet.create(RBRACE));
      decl.drop();
    } else {
      decl.done(declType);
    }
  }
Exemple #3
0
  /*
   * enumClassBody
   *   : "{" enumEntry* "}"
   *   ;
   */
  private void parseEnumClassBody() {
    if (!at(LBRACE)) return;

    PsiBuilder.Marker classBody = mark();

    myBuilder.enableNewlines();
    advance(); // LBRACE

    if (!parseIdeTemplate()) {
      while (!eof() && !at(RBRACE)) {
        PsiBuilder.Marker entryOrMember = mark();

        TokenSet constructorNameFollow = TokenSet.create(SEMICOLON, COLON, LPAR, LT, LBRACE);
        int lastId = findLastBefore(ENUM_MEMBER_FIRST, constructorNameFollow, false);
        TokenDetector enumDetector = new TokenDetector(ENUM_KEYWORD);
        createTruncatedBuilder(lastId).parseModifierList(MODIFIER_LIST, enumDetector, false);

        IElementType type;
        if (at(IDENTIFIER)) {
          parseEnumEntry();
          type = ENUM_ENTRY;
        } else {
          type = parseMemberDeclarationRest(enumDetector.isDetected());
        }

        if (type == null) {
          errorAndAdvance("Expecting an enum entry or member declaration");
          entryOrMember.drop();
        } else {
          entryOrMember.done(type);
        }
      }
    }

    expect(RBRACE, "Expecting '}' to close enum class body");
    myBuilder.restoreNewlinesState();

    classBody.done(CLASS_BODY);
  }