예제 #1
0
  /*
   * SimpleName{,}
   */
  private void parseFunctionLiteralShorthandParameterList() {
    PsiBuilder.Marker parameterList = mark();

    while (!eof()) {
      PsiBuilder.Marker parameter = mark();

      //            int parameterNamePos = matchTokenStreamPredicate(new LastBefore(new
      // At(IDENTIFIER), new AtOffset(doubleArrowPos)));
      //            createTruncatedBuilder(parameterNamePos).parseModifierList(MODIFIER_LIST,
      // false);

      if (at(COLON)) {
        error("Expecting parameter name");
      } else {
        expect(IDENTIFIER, "Expecting parameter name", TokenSet.create(ARROW));
      }

      if (at(COLON)) {
        advance(); // COLON
        myJetParsing.parseTypeRef(TokenSet.create(ARROW, COMMA));
      }
      parameter.done(VALUE_PARAMETER);

      if (at(ARROW)) {
        break;
      } else if (at(COMMA)) {
        advance(); // COMMA
      } else {
        error("Expecting '->' or ','");
        break;
      }
    }

    parameterList.done(VALUE_PARAMETER_LIST);
  }
예제 #2
0
 @Inject
 public XtendTokenSetProvider(final TokenTypeProvider tokenTypeProvider) {
   IElementType _iElementType =
       tokenTypeProvider.getIElementType(PsiInternalXtendParser.RULE_SL_COMMENT);
   TokenSet _create = TokenSet.create(_iElementType);
   this.slCommentTokens = _create;
   IElementType _iElementType_1 =
       tokenTypeProvider.getIElementType(PsiInternalXtendParser.RULE_RICH_TEXT);
   IElementType _iElementType_2 =
       tokenTypeProvider.getIElementType(PsiInternalXtendParser.RULE_RICH_TEXT_START);
   IElementType _iElementType_3 =
       tokenTypeProvider.getIElementType(PsiInternalXtendParser.RULE_RICH_TEXT_END);
   IElementType _iElementType_4 =
       tokenTypeProvider.getIElementType(PsiInternalXtendParser.RULE_RICH_TEXT_INBETWEEN);
   IElementType _iElementType_5 =
       tokenTypeProvider.getIElementType(PsiInternalXtendParser.RULE_COMMENT_RICH_TEXT_END);
   IElementType _iElementType_6 =
       tokenTypeProvider.getIElementType(PsiInternalXtendParser.RULE_COMMENT_RICH_TEXT_INBETWEEN);
   TokenSet _create_1 =
       TokenSet.create(
           _iElementType_1,
           _iElementType_2,
           _iElementType_3,
           _iElementType_4,
           _iElementType_5,
           _iElementType_6);
   this.richStringLiteralTokens = _create_1;
 }
/** Created by Michal on 18.11.2015. */
public class VaadinDesignParserDefinition implements ParserDefinition {

  public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE);
  public static final TokenSet STRING_LITERALS = TokenSet.create(VDTypes.ATTR_VALUE);
  //    public static final TokenSet COMMENTS = TokenSet.create(SimpleTypes.COMMENT);

  public static final IFileElementType FILE =
      new IFileElementType(
          Language.<VaadinDeclarativeLanguage>findInstance(VaadinDeclarativeLanguage.class));

  @NotNull
  @Override
  public Lexer createLexer(Project project) {
    return new FlexAdapter(new VaadinDesignLexer(null));
  }

  @Override
  public PsiParser createParser(Project project) {
    return new VaadinDesignParser();
  }

  @Override
  public IFileElementType getFileNodeType() {
    return FILE;
  }

  @NotNull
  @Override
  public TokenSet getWhitespaceTokens() {
    return WHITE_SPACES;
  }

  @NotNull
  @Override
  public TokenSet getCommentTokens() {
    return TokenSet.EMPTY;
  }

  @NotNull
  @Override
  public TokenSet getStringLiteralElements() {
    return STRING_LITERALS;
  }

  @NotNull
  @Override
  public PsiElement createElement(ASTNode node) {
    return VDTypes.Factory.createElement(node);
  }

  @Override
  public PsiFile createFile(FileViewProvider viewProvider) {
    return new VaadinDesignFile(viewProvider);
  }

  @Override
  public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
    return SpaceRequirements.MAY;
  }
}
예제 #4
0
  private boolean parseFunctionTypeDotParametersAndType() {
    PsiBuilder.Marker rollbackMarker = mark();

    // True when it's confirmed that body of literal can't be simple expressions and we prefer to
    // parse
    // it to function params if possible.
    boolean preferParamsToExpressions = false;

    // Last dot before ARROW and RPAR, but also stop at top-level keywords and '{', '}'
    int lastDot =
        matchTokenStreamPredicate(
            new LastBefore(
                new At(DOT),
                new AtSet(
                    TokenSet.orSet(
                        TokenSet.create(ARROW, RPAR),
                        TokenSet.orSet(
                            TokenSet.create(LBRACE, RBRACE),
                            TokenSet.andNot(
                                KEYWORDS, TokenSet.create(CAPITALIZED_THIS_KEYWORD)))))));

    if (lastDot >= 0) {
      createTruncatedBuilder(lastDot).parseTypeRef();
      if (at(DOT)) {
        advance(); // DOT
        preferParamsToExpressions = parseFunctionLiteralParametersAndType();
      }
    }

    return preferParamsToExpressions
        ? rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE)
        : rollbackOrDropAt(rollbackMarker, ARROW);
  }
예제 #5
0
  /*
   * object
   *   : "object" SimpleName? ":" delegationSpecifier{","}? classBody?
   *   ;
   */
  void parseObject(boolean named, boolean optionalBody) {
    assert _at(OBJECT_KEYWORD);

    advance(); // OBJECT_KEYWORD

    if (named) {
      PsiBuilder.Marker propertyDeclaration = mark();
      if (!parseIdeTemplate()) {
        expect(IDENTIFIER, "Expecting object name", TokenSet.create(LBRACE));
      }
      propertyDeclaration.done(OBJECT_DECLARATION_NAME);
    } else {
      if (at(IDENTIFIER)) {
        error("An object expression cannot bind a name");
      }
    }

    if (optionalBody) {
      if (at(COLON)) {
        advance(); // COLON
        parseDelegationSpecifierList();
      }
      if (at(LBRACE)) {
        parseClassBody();
      }
    } else {
      if (at(LBRACE)) {
        parseClassBody();
      } else {
        expect(COLON, "Expecting ':'", TokenSet.create(IDENTIFIER, PACKAGE_KEYWORD));
        parseDelegationSpecifierList();
        parseClassBody();
      }
    }
  }
/** Created by IntelliJ IDEA. User: Jon S Akhtar Date: 4/3/11 Time: 12:27 AM */
public class MoonParsingLexerMergingAdapter extends MergingLexerAdapterBase
    implements MoonTokenTypes {

  static final TokenSet tokensToMerge =
      TokenSet.create(LONGSTRING_BEGIN, LONGSTRING, LONGSTRING_END, NL_BEFORE_LONGSTRING);
  static final TokenSet tokensToMerge2 =
      TokenSet.create(LONGCOMMENT_BEGIN, LONGCOMMENT, LONGCOMMENT_END, NL_BEFORE_LONGSTRING);

  static final TokenSet allMergables = TokenSet.orSet(tokensToMerge, tokensToMerge2);

  public MoonParsingLexerMergingAdapter(Lexer original) {
    super(
        original,
        new MergeFunction() {

          @Override
          public IElementType merge(IElementType type, Lexer originalLexer) {
            if (!allMergables.contains(type)) {
              return type;
            }

            TokenSet merging = tokensToMerge.contains(type) ? tokensToMerge : tokensToMerge2;

            while (true) {
              final IElementType tokenType = originalLexer.getTokenType();
              if (!merging.contains(tokenType)) break;
              originalLexer.advance();
            }

            return merging == tokensToMerge ? LONGSTRING : LONGCOMMENT;
          }
        });
  }
}
public class PerlParserDefinition implements ParserDefinition {
  public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE);
  public static final TokenSet COMMENT = TokenSet.create(PerlTypes.COMMENT);
  public static final TokenSet LITERAL = TokenSet.create(PerlTypes.LITERAL);

  public static final IFileElementType FILE =
      new IFileElementType(Language.<PerlLanguage>findInstance(PerlLanguage.class));

  @NotNull
  @Override
  public Lexer createLexer(Project project) {
    return new FlexAdapter(new PerlLexer((Reader) null));
  }

  @NotNull
  public TokenSet getWhitespaceTokens() {
    return WHITE_SPACES;
  }

  @NotNull
  public TokenSet getCommentTokens() {
    return COMMENT;
  }

  @NotNull
  public TokenSet getStringLiteralElements() {
    return LITERAL;
  }

  @NotNull
  public PsiParser createParser(final Project project) {
    return new PerlParser();
  }

  @Override
  public IFileElementType getFileNodeType() {
    return FILE;
  }

  public PsiFile createFile(FileViewProvider viewProvider) {
    return new PerlFile(viewProvider);
  }

  public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
    return SpaceRequirements.MAY;
  }

  @NotNull
  public PsiElement createElement(ASTNode node) {
    return PerlTypes.Factory.createElement(node);
  }
}
예제 #8
0
/** @author Stepan Koltsov */
public class RustTokenTypes {
  static IElementType WHITE_SPACE = TokenType.WHITE_SPACE;
  static IElementType BAD_CHARACTER = TokenType.BAD_CHARACTER;
  static IElementType NUMBER = new RustElementType("number");

  static IElementType END_OF_LINE_COMMENT = new RustElementType("END_OF_LINE_COMMENT");
  static IElementType KEY_CHARACTERS = new RustElementType("KEY_CHARACTERS");
  static IElementType VALUE_CHARACTERS = new RustElementType("VALUE_CHARACTERS");
  static IElementType KEY_VALUE_SEPARATOR = new RustElementType("KEY_VALUE_SEPARATOR");

  static TokenSet COMMENTS = TokenSet.create(END_OF_LINE_COMMENT);
  static TokenSet WHITESPACES = TokenSet.create(WHITE_SPACE);
}
예제 #9
0
  /*
   * for
   *   : "for" "(" annotations ("val" | "var")? (multipleVariableDeclarations | variableDeclarationEntry) "in" expression ")" expression
   *   ;
   *
   *   TODO: empty loop body (at the end of the block)?
   */
  private void parseFor() {
    assert _at(FOR_KEYWORD);

    PsiBuilder.Marker loop = mark();

    advance(); // FOR_KEYWORD

    if (expect(LPAR, "Expecting '(' to open a loop range", EXPRESSION_FIRST)) {
      myBuilder.disableNewlines();

      if (!at(RPAR)) {
        PsiBuilder.Marker parameter = mark();

        if (!at(IN_KEYWORD)) {
          myJetParsing.parseModifierList(DEFAULT, TokenSet.create(IN_KEYWORD, RPAR, COLON));
        }

        if (at(VAL_KEYWORD) || at(VAR_KEYWORD)) advance(); // VAL_KEYWORD or VAR_KEYWORD

        if (at(LPAR)) {
          myJetParsing.parseMultiDeclarationName(TokenSet.create(IN_KEYWORD, LBRACE));
          parameter.done(DESTRUCTURING_DECLARATION);
        } else {
          expect(IDENTIFIER, "Expecting a variable name", TokenSet.create(COLON, IN_KEYWORD));

          if (at(COLON)) {
            advance(); // COLON
            myJetParsing.parseTypeRef(TokenSet.create(IN_KEYWORD));
          }
          parameter.done(VALUE_PARAMETER);
        }

        if (expect(IN_KEYWORD, "Expecting 'in'", TokenSet.create(LPAR, LBRACE, RPAR))) {
          PsiBuilder.Marker range = mark();
          parseExpression();
          range.done(LOOP_RANGE);
        }
      } else {
        error("Expecting a variable name");
      }

      expectNoAdvance(RPAR, "Expecting ')'");
      myBuilder.restoreNewlinesState();
    }

    parseControlStructureBody();

    loop.done(FOR);
  }
예제 #10
0
  /*
   * typeConstraint
   *   : attributes SimpleName ":" type
   *   : attributes "class" "object" SimpleName ":" type
   *   ;
   */
  private void parseTypeConstraint() {
    PsiBuilder.Marker constraint = mark();

    parseAnnotations(false);

    if (at(CLASS_KEYWORD)) {
      advance(); // CLASS_KEYWORD

      expect(OBJECT_KEYWORD, "Expecting 'object'", TYPE_REF_FIRST);
    }

    PsiBuilder.Marker reference = mark();
    if (expect(
        IDENTIFIER,
        "Expecting type parameter name",
        TokenSet.orSet(TokenSet.create(COLON, COMMA), TYPE_REF_FIRST))) {
      reference.done(REFERENCE_EXPRESSION);
    } else {
      reference.drop();
    }

    expect(COLON, "Expecting ':' before the upper bound", TYPE_REF_FIRST);

    parseTypeRef();

    constraint.done(TYPE_CONSTRAINT);
  }
  static {
    // in regular case, these tokens should be created in extension class
    TOKENS_MAP.put("inner", RESERVED_INNER);
    TOKENS_MAP.put("with", RESERVED_WITH);
    TOKENS_MAP.put("extends", RESERVED_EXTENDS);
    TOKENS_MAP.put("meta", RESERVED_META);
    TOKENS_MAP.put("override", RESERVED_OVERRIDE);
    TOKENS_MAP.put("around", RESERVED_AROUND);
    TOKENS_MAP.put("super", RESERVED_SUPER);
    TOKENS_MAP.put("augment", RESERVED_AUGMENT);
    TOKENS_MAP.put("after", RESERVED_AFTER);
    TOKENS_MAP.put("before", RESERVED_BEFORE);
    TOKENS_MAP.put("has", RESERVED_HAS);

    RESERVED_TO_STATEMENT_MAP.put(RESERVED_INNER, MOOSE_STATEMENT_INNER);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_WITH, MOOSE_STATEMENT_WITH);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_EXTENDS, MOOSE_STATEMENT_EXTENDS);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_META, MOOSE_STATEMENT_META);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_OVERRIDE, MOOSE_STATEMENT_OVERRIDE);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_AROUND, MOOSE_STATEMENT_AROUND);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_SUPER, MOOSE_STATEMENT_SUPER);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_AUGMENT, MOOSE_STATEMENT_AUGMENT);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_AFTER, MOOSE_STATEMENT_AFTER);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_BEFORE, MOOSE_STATEMENT_BEFORE);
    RESERVED_TO_STATEMENT_MAP.put(RESERVED_HAS, MOOSE_STATEMENT_HAS);

    MOOSE_TOKEN_SET =
        TokenSet.create(TOKENS_MAP.values().toArray(new IElementType[TOKENS_MAP.values().size()]));
  }
예제 #12
0
 public JetWordsScanner() {
   super(
       new JetLexer(),
       TokenSet.create(JetTokens.IDENTIFIER),
       JetTokens.COMMENTS,
       JetTokens.STRINGS);
 }
예제 #13
0
/** @author ilyas */
public interface LuaDocTokenTypes {

  IElementType LDOC_TAG_NAME = new LuaDocElementTypeImpl("LDOC_TAG_NAME");
  IElementType LDOC_TAG_PLAIN_VALUE_TOKEN = new LuaDocElementTypeImpl("LDOC_TAG_VALUE_TOKEN");
  IElementType LDOC_TAG_VALUE = new LuaDocTagValueTokenType();

  IElementType LDOC_COMMENT_START = new LuaDocElementTypeImpl("LDOC_COMMENT_START");

  IElementType LDOC_COMMENT_DATA = new LuaDocElementTypeImpl("LDOC_COMMENT_DATA");

  IElementType LDOC_WHITESPACE = new LuaDocElementTypeImpl("LDOC_WHITESPACE");
  IElementType LDOC_DASHES = new LuaDocElementTypeImpl("LDOC_DASHES");
  IElementType LDOC_COMMENT_BAD_CHARACTER = TokenType.BAD_CHARACTER;

  TokenSet LUA_DOC_TOKENS =
      TokenSet.create(
          LDOC_COMMENT_START,
          LDOC_COMMENT_DATA,
          LDOC_WHITESPACE,
          LDOC_DASHES,
          LDOC_TAG_NAME,
          LDOC_TAG_VALUE,
          LDOC_TAG_PLAIN_VALUE_TOKEN,
          LDOC_COMMENT_BAD_CHARACTER);
}
예제 #14
0
  /*
   * whenEntry
   *   // TODO : consider empty after ->
   *   : whenCondition{","} "->" element SEMI
   *   : "else" "->" element SEMI
   *   ;
   */
  private void parseWhenEntry() {
    PsiBuilder.Marker entry = mark();

    if (at(ELSE_KEYWORD)) {
      advance(); // ELSE_KEYWORD

      if (!at(ARROW)) {
        errorUntil("Expecting '->'", TokenSet.create(ARROW, RBRACE, EOL_OR_SEMICOLON));
      }

      if (at(ARROW)) {
        advance(); // ARROW

        if (atSet(WHEN_CONDITION_RECOVERY_SET)) {
          error("Expecting an element");
        } else {
          parseExpressionPreferringBlocks();
        }
      } else if (!atSet(WHEN_CONDITION_RECOVERY_SET)) {
        errorAndAdvance("Expecting '->'");
      }
    } else {
      parseWhenEntryNotElse();
    }

    entry.done(WHEN_ENTRY);
    consumeIf(SEMICOLON);
  }
예제 #15
0
  /*
   * expressions
   *   : SEMI* statement{SEMI+} SEMI*
   */
  public void parseStatements() {
    while (at(SEMICOLON)) advance(); // SEMICOLON
    while (!eof() && !at(RBRACE)) {
      if (!atSet(STATEMENT_FIRST)) {
        errorAndAdvance("Expecting an element");
      }
      if (atSet(STATEMENT_FIRST)) {
        parseStatement();
      }
      if (at(SEMICOLON)) {
        while (at(SEMICOLON)) advance(); // SEMICOLON
      } else if (at(RBRACE)) {
        break;
      } else if (!myBuilder.newlineBeforeCurrentToken()) {
        String severalStatementsError =
            "Unexpected tokens (use ';' to separate expressions on the same line)";

        if (atSet(STATEMENT_NEW_LINE_QUICK_RECOVERY_SET)) {
          error(severalStatementsError);
        } else {
          errorUntil(severalStatementsError, TokenSet.create(EOL_OR_SEMICOLON, LBRACE, RBRACE));
        }
      }
    }
  }
예제 #16
0
/** User: jansorg Date: 21.05.2009 Time: 10:36:06 */
public class BashWordImpl extends BashPsiElementImpl implements BashWord {
  private static final TokenSet nonWrappableChilds =
      TokenSet.create(BashElementTypes.STRING_ELEMENT, BashTokenTypes.STRING2, BashTokenTypes.WORD);

  public BashWordImpl(final ASTNode astNode) {
    super(astNode, "bash combined word");
  }

  @Override
  public void accept(@NotNull PsiElementVisitor visitor) {
    if (visitor instanceof BashVisitor) {
      ((BashVisitor) visitor).visitCombinedWord(this);
    } else {
      visitor.visitElement(this);
    }
  }

  public boolean isWrappable() {
    return findChildByType(nonWrappableChilds) == null;
  }

  public String getUnwrappedCharSequence() {
    return getText();
  }

  public boolean isStatic() {
    return BashPsiUtils.isStaticWordExpr(getFirstChild());
  }
}
class GoBinaryExpressionBlock extends GoBlock {
  public enum Mode {
    Normal,
    Compact
  }

  private static final TokenSet EMPTY_SPACE_TOKENS =
      TokenSet.create(oMUL, oQUOTIENT, oREMAINDER, oSHIFT_LEFT, oSHIFT_RIGHT);

  private final Spacing spacing;

  public GoBinaryExpressionBlock(
      ASTNode node, Alignment alignment, Wrap wrap, CommonCodeStyleSettings settings) {
    super(node, alignment, Indent.getNormalIndent(), wrap, settings);

    GoBinaryExpression psi = node.getPsi(GoBinaryExpression.class);
    if (psi != null && EMPTY_SPACE_TOKENS.contains(psi.getOperator())) {
      spacing = EMPTY_SPACING_KEEP_LINE_BREAKS;
    } else {
      spacing = BASIC_SPACING_KEEP_LINE_BREAKS;
    }
  }

  @Override
  protected Spacing getGoBlockSpacing(GoBlock child1, GoBlock child2) {
    return isCommentBlock(child1) || isCommentBlock(child2)
        ? BASIC_SPACING_KEEP_LINE_BREAKS
        : spacing;
  }

  @Override
  protected Indent getChildIndent(@Nullable PsiElement child) {
    return null;
  }
}
  @NotNull
  public Count getCount() {
    final ASTNode[] nodes = getNode().getChildren(RegExpTokens.QUANTIFIERS);
    assert nodes.length > 0;

    final IElementType type = nodes[0].getElementType();
    if (type == RegExpTokens.QUEST) {
      return SimpleCount.ONE_OR_ZERO;
    } else if (type == RegExpTokens.STAR) {
      return SimpleCount.ZERO_OR_MORE;
    } else if (type == RegExpTokens.PLUS) {
      return SimpleCount.ONE_OR_MORE;
    } else if (type == RegExpTokens.LBRACE) {
      final ASTNode[] numbers = getNode().getChildren(TokenSet.create(RegExpTokens.NUMBER));
      if (numbers.length >= 1) {
        final String min = numbers[0].getText();
        final String max;
        if (numbers.length == 2) {
          max = numbers[1].getText();
        } else if (getNode().findChildByType(RegExpTokens.COMMA) != null) {
          max = "";
        } else {
          max = min;
        }
        return new RepeatedCount(min, max);
      }
      // syntactically incorrect
      return new RepeatedCount("", "");
    }

    assert false;
    return null;
  }
예제 #19
0
  /*
   * initializer
   *   : attributes "this" valueArguments
   *   : attributes constructorInvocation // type parameters may (must?) be omitted
   *   ;
   */
  private void parseInitializer() {
    PsiBuilder.Marker initializer = mark();
    parseAnnotations(false);

    IElementType type;
    if (at(THIS_KEYWORD)) {
      PsiBuilder.Marker mark = mark();
      advance(); // THIS_KEYWORD
      mark.done(THIS_CONSTRUCTOR_REFERENCE);
      type = THIS_CALL;
    } else if (atSet(TYPE_REF_FIRST)) {
      PsiBuilder.Marker reference = mark();
      parseTypeRef();
      reference.done(CONSTRUCTOR_CALLEE);
      type = DELEGATOR_SUPER_CALL;
    } else {
      errorWithRecovery(
          "Expecting constructor call (this(...)) or supertype initializer",
          TokenSet.create(LBRACE, COMMA));
      initializer.drop();
      return;
    }
    myExpressionParsing.parseValueArgumentList();

    initializer.done(type);
  }
예제 #20
0
 @Override
 @NotNull
 public ASTNode getValOrVarNode() {
   ASTNode node = getNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD));
   assert node != null : "Val or var should always exist for property";
   return node;
 }
예제 #21
0
  /*
   * import
   *   : "import" ("namespace" ".")? SimpleName{"."} ("." "*" | "as" SimpleName)? SEMI?
   *   ;
   */
  private void parseImportDirective() {
    assert _at(IMPORT_KEYWORD);
    PsiBuilder.Marker importDirective = mark();
    advance(); // IMPORT_KEYWORD

    PsiBuilder.Marker qualifiedName = mark();
    if (at(PACKAGE_KEYWORD)) {
      advance(); // PACKAGE_KEYWORD
      expect(DOT, "Expecting '.'", TokenSet.create(IDENTIFIER, MUL, SEMICOLON));
    }

    PsiBuilder.Marker reference = mark();
    expect(IDENTIFIER, "Expecting qualified name");
    reference.done(REFERENCE_EXPRESSION);

    while (at(DOT) && lookahead(1) != MUL) {
      advance(); // DOT

      reference = mark();
      if (expect(
          IDENTIFIER,
          "Qualified name must be a '.'-separated identifier list",
          IMPORT_RECOVERY_SET)) {
        reference.done(REFERENCE_EXPRESSION);
      } else {
        reference.drop();
      }

      PsiBuilder.Marker precede = qualifiedName.precede();
      qualifiedName.done(DOT_QUALIFIED_EXPRESSION);
      qualifiedName = precede;
    }
    qualifiedName.drop();

    if (at(DOT)) {
      advance(); // DOT
      assert _at(MUL);
      advance(); // MUL
      handleUselessRename();
    }
    if (at(AS_KEYWORD)) {
      advance(); // AS_KEYWORD
      expect(IDENTIFIER, "Expecting identifier", TokenSet.create(SEMICOLON));
    }
    consumeIf(SEMICOLON);
    importDirective.done(IMPORT_DIRECTIVE);
  }
예제 #22
0
 static {
   Set<IElementType> operations = new HashSet<IElementType>();
   Precedence[] values = Precedence.values();
   for (Precedence precedence : values) {
     operations.addAll(Arrays.asList(precedence.getOperations().getTypes()));
   }
   ALL_OPERATIONS = TokenSet.create(operations.toArray(new IElementType[operations.size()]));
 }
예제 #23
0
  /**
   * "(" (modifiers SimpleName (":" type)?){","} ")"
   *
   * @return true if at least one comma was found
   */
  private boolean parseFunctionLiteralParameterList() {
    PsiBuilder.Marker list = mark();
    expect(LPAR, "Expecting a parameter list in parentheses (...)", TokenSet.create(ARROW, COLON));

    boolean hasComma = false;

    myBuilder.disableNewlines();

    if (!at(RPAR)) {
      while (true) {
        if (at(COMMA)) errorAndAdvance("Expecting a parameter declaration");

        PsiBuilder.Marker parameter = mark();
        int parameterNamePos =
            matchTokenStreamPredicate(
                new LastBefore(
                    new At(IDENTIFIER), new AtSet(COMMA, RPAR, COLON, ARROW, RBRACE, LBRACE)));
        createTruncatedBuilder(parameterNamePos)
            .parseModifierList(MODIFIER_LIST, REGULAR_ANNOTATIONS_ONLY_WITH_BRACKETS);

        expect(IDENTIFIER, "Expecting parameter declaration");

        if (at(COLON)) {
          advance(); // COLON
          myJetParsing.parseTypeRef();
        }
        parameter.done(VALUE_PARAMETER);
        if (!at(COMMA)) break;
        advance(); // COMMA

        hasComma = true;

        if (at(RPAR)) {
          error("Expecting a parameter declaration");
          break;
        }
      }
    }

    myBuilder.restoreNewlinesState();

    expect(RPAR, "Expecting ')'", TokenSet.create(ARROW, COLON));
    list.done(VALUE_PARAMETER_LIST);

    return hasComma;
  }
public final class XPath2ElementTypes {
  public static final IFileElementType FILE =
      new IFileElementType("XPATH2_FILE", XPathFileType.XPATH2.getLanguage());

  public static final IElementType SEQUENCE = new XPath2ElementType("SEQUENCE");
  public static final IElementType RANGE_EXPRESSION = new XPath2ElementType("RANGE_EXPRESSION");
  public static final IElementType IF = new XPath2ElementType("IF");
  public static final IElementType FOR = new XPath2ElementType("FOR");
  public static final IElementType BODY = new XPath2ElementType("RETURN");
  public static final IElementType QUANTIFIED = new XPath2ElementType("QUANTIFIED");

  public static final IElementType INSTANCE_OF = new XPath2ElementType("INSTANCE_OF");
  public static final IElementType TREAT_AS = new XPath2ElementType("TREAT_AS");
  public static final IElementType CASTABLE_AS = new XPath2ElementType("CASTABLE_AS");
  public static final IElementType CAST_AS = new XPath2ElementType("CAST_AS");

  public static final IElementType BINDING_SEQ = new XPath2ElementType("BINDING_SEQ");

  public static final IElementType VARIABLE_DECL = new XPath2ElementType("VARIABLE_DECL");
  public static final IElementType CONTEXT_ITEM = new XPath2ElementType("CONTEXT_ITEM");

  public static final IElementType SEQUENCE_TYPE = new XPath2ElementType("SEQUENCE_TYPE");
  public static final IElementType SINGLE_TYPE = new XPath2ElementType("SINGLE_TYPE");
  public static final IElementType ITEM_OR_EMPTY_SEQUENCE =
      new XPath2ElementType("ITEM_OR_EMPTY_SEQUENCE");
  public static final TokenSet TYPE_ELEMENTS = TokenSet.create(SEQUENCE_TYPE, SINGLE_TYPE);

  public static final TokenSet EXPRESSIONS =
      TokenSet.orSet(
          XPathElementTypes.EXPRESSIONS,
          TokenSet.create(
              XPathElementTypes.NODE_TYPE,
              SEQUENCE,
              CONTEXT_ITEM,
              IF,
              FOR,
              RANGE_EXPRESSION,
              QUANTIFIED,
              INSTANCE_OF,
              TREAT_AS,
              CASTABLE_AS,
              CAST_AS));

  private XPath2ElementTypes() {}
}
@Singleton
public class PureXbaseTokenTypeProvider implements TokenTypeProvider {

  private static final String[] TOKEN_NAMES = new PsiInternalPureXbaseParser(null).getTokenNames();

  private static final IElementType[] tokenTypes = new IElementType[TOKEN_NAMES.length];

  static {
    for (int i = 0; i < TOKEN_NAMES.length; i++) {
      tokenTypes[i] = new IndexedElementType(TOKEN_NAMES[i], i, PureXbaseLanguage.INSTANCE);
    }
  }

  private static final TokenSet WHITESPACE_TOKENS = TokenSet.create(tokenTypes[RULE_WS]);
  private static final TokenSet COMMENT_TOKENS =
      TokenSet.create(tokenTypes[RULE_SL_COMMENT], tokenTypes[RULE_ML_COMMENT]);
  private static final TokenSet STRING_TOKENS = TokenSet.create(tokenTypes[RULE_STRING]);

  @Override
  public int getAntlrType(IElementType iElementType) {
    return (iElementType instanceof IndexedElementType)
        ? ((IndexedElementType) iElementType).getLocalIndex()
        : org.antlr.runtime.Token.INVALID_TOKEN_TYPE;
  }

  @Override
  public IElementType getIElementType(int antlrType) {
    return tokenTypes[antlrType];
  }

  @Override
  public TokenSet getWhitespaceTokens() {
    return WHITESPACE_TOKENS;
  }

  @Override
  public TokenSet getCommentTokens() {
    return COMMENT_TOKENS;
  }

  @Override
  public TokenSet getStringLiteralTokens() {
    return STRING_TOKENS;
  }
}
예제 #26
0
  private boolean parseValueParameter(boolean rollbackOnFailure) {
    PsiBuilder.Marker parameter = mark();

    parseModifierListWithShortAnnotations(
        MODIFIER_LIST, TokenSet.create(IDENTIFIER), TokenSet.create(COMMA, RPAR, COLON));

    if (at(VAR_KEYWORD) || at(VAL_KEYWORD)) {
      advance(); // VAR_KEYWORD | VAL_KEYWORD
    }

    if (!parseFunctionParameterRest() && rollbackOnFailure) {
      parameter.rollbackTo();
      return false;
    }

    parameter.done(VALUE_PARAMETER);
    return true;
  }
예제 #27
0
 @Override
 public void setUp() throws Exception {
   super.setUp();
   lexer =
       new LayeredLexer(
           new LatteTopLexer(),
           dummyLexer = new MyDummyLexer(),
           TokenSet.create(LatteTokenTypes.PARAMS, LatteTokenTypes.N_ATTR_VALUE));
 }
예제 #28
0
/** @author fernandohur */
public class EamlParserDefinition implements ParserDefinition {

  public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE);
  public static final IFileElementType FILE =
      new IFileElementType(Language.<EamlLanguage>findInstance(EamlLanguage.class));

  @NotNull
  @Override
  public Lexer createLexer(final Project project) {
    return new EamlLexerAdapter();
  }

  @NotNull
  @Override
  public TokenSet getWhitespaceTokens() {
    return WHITE_SPACES;
  }

  @NotNull
  @Override
  public TokenSet getCommentTokens() {
    return TokenSet.EMPTY;
  }

  @NotNull
  @Override
  public TokenSet getStringLiteralElements() {
    return TokenSet.EMPTY;
  }

  @Override
  public PsiParser createParser(final Project project) {
    return new EamlParser();
  }

  @Override
  public IFileElementType getFileNodeType() {
    return FILE;
  }

  @Override
  public PsiFile createFile(final FileViewProvider fileViewProvider) {
    return new EamlFile(fileViewProvider);
  }

  @Override
  public SpaceRequirements spaceExistanceTypeBetweenTokens(
      final ASTNode astNode, final ASTNode astNode1) {
    return SpaceRequirements.MAY;
  }

  @NotNull
  @Override
  public PsiElement createElement(final ASTNode astNode) {
    return EamlTypes.Factory.createElement(astNode);
  }
}
/** Created by Anastasia Izmaylova on 12/10/15. */
public class IGGYFindUsesProvider implements FindUsagesProvider {

  WordsScanner scanner =
      new DefaultWordsScanner(
          new IGGYLexer(),
          TokenSet.create(IGGYTokenTypes.TERMINAL),
          TokenSet.create(IGGYTokenTypes.COMMENT),
          TokenSet.EMPTY);

  @Nullable
  @Override
  public WordsScanner getWordsScanner() {
    return scanner;
  }

  @Override
  public boolean canFindUsagesFor(PsiElement psiElement) {
    return psiElement instanceof NontName$DeclarationImpl;
  }

  @Nullable
  @Override
  public String getHelpId(PsiElement psiElement) {
    return null;
  }

  @NotNull
  @Override
  public String getType(PsiElement element) {
    return "Nonterminal name";
  }

  @NotNull
  @Override
  public String getDescriptiveName(@NotNull PsiElement element) {
    return element.getText();
  }

  @NotNull
  @Override
  public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
    return element.getText();
  }
}
예제 #30
0
  /*
   * try
   *   : "try" block catchBlock* finallyBlock?
   *   ;
   * catchBlock
   *   : "catch" "(" annotations SimpleName ":" userType ")" block
   *   ;
   *
   * finallyBlock
   *   : "finally" block
   *   ;
   */
  private void parseTry() {
    assert _at(TRY_KEYWORD);

    PsiBuilder.Marker tryExpression = mark();

    advance(); // TRY_KEYWORD

    myJetParsing.parseBlock();

    boolean catchOrFinally = false;
    while (at(CATCH_KEYWORD)) {
      catchOrFinally = true;
      PsiBuilder.Marker catchBlock = mark();
      advance(); // CATCH_KEYWORD

      TokenSet recoverySet = TokenSet.create(LBRACE, FINALLY_KEYWORD, CATCH_KEYWORD);
      if (atSet(recoverySet)) {
        error("Expecting exception variable declaration");
      } else {
        PsiBuilder.Marker parameters = mark();
        expect(LPAR, "Expecting '('", recoverySet);
        if (!atSet(recoverySet)) {
          myJetParsing.parseValueParameter(/*typeRequired = */ true);
          expect(RPAR, "Expecting ')'", recoverySet);
        } else {
          error("Expecting exception variable declaration");
        }
        parameters.done(VALUE_PARAMETER_LIST);
      }

      if (at(LBRACE)) {
        myJetParsing.parseBlock();
      } else {
        error("Expecting a block: { ... }");
      }
      catchBlock.done(CATCH);
    }

    if (at(FINALLY_KEYWORD)) {
      catchOrFinally = true;
      PsiBuilder.Marker finallyBlock = mark();

      advance(); // FINALLY_KEYWORD

      myJetParsing.parseBlock();

      finallyBlock.done(FINALLY);
    }

    if (!catchOrFinally) {
      error("Expecting 'catch' or 'finally'");
    }

    tryExpression.done(TRY);
  }