How to use the chevrotain.tokenMatcher function in chevrotain

To help you get started, we’ve selected a few chevrotain examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jhipster / prettier-java / packages / java-parser / src / productions / interfaces.js View on Github external
nextTokenType = this.LA(1).tokenType;
    if (
      tokenMatcher(nextTokenType, t.Class) ||
      tokenMatcher(nextTokenType, t.Enum)
    ) {
      return InterfaceBodyTypes.classDeclaration;
    }
    if (
      tokenMatcher(nextTokenType, t.Interface) ||
      tokenMatcher(nextTokenType, t.At)
    ) {
      return InterfaceBodyTypes.interfaceDeclaration;
    }
    if (
      tokenMatcher(nextTokenType, t.Void) ||
      tokenMatcher(nextTokenType, t.Less)
    ) {
      // method with result type "void"
      return InterfaceBodyTypes.interfaceMethodDeclaration;
    }

    // Only constant or interfaceMethod declarations may be valid at this point.
    // All other alternatives should have been attempted.
    // **both** start with "unannType"
    this.SUBRULE($.unannType);

    const nextToken = this.LA(1);
    const nextNextTokenType = this.LA(2).tokenType;
    // "foo(..." --> look like method start
    if (
      tokenMatcher(nextToken, t.Identifier) &&
      tokenMatcher(nextNextTokenType, t.LBrace)
github jhipster / prettier-java / packages / java-parser / src / productions / interfaces.js View on Github external
// Only constant or interfaceMethod declarations may be valid at this point.
    // All other alternatives should have been attempted.
    // **both** start with "unannType"
    this.SUBRULE($.unannType);

    const nextToken = this.LA(1);
    const nextNextTokenType = this.LA(2).tokenType;
    // "foo(..." --> look like method start
    if (
      tokenMatcher(nextToken, t.Identifier) &&
      tokenMatcher(nextNextTokenType, t.LBrace)
    ) {
      return InterfaceBodyTypes.interfaceMethodDeclaration;
    }
    // a valid constant
    if (tokenMatcher(nextToken, t.Identifier)) {
      return InterfaceBodyTypes.constantDeclaration;
    }
    return InterfaceBodyTypes.unknown;
  });
github jhipster / prettier-java / packages / java-parser / src / productions / expressions.js View on Github external
GATE: () =>
        // avoids ambiguity with ".this" and ".new" which are parsed as a primary suffix.
        tokenMatcher(this.LA(2).tokenType, t.Class) === false &&
        tokenMatcher(this.LA(2).tokenType, t.This) === false &&
        tokenMatcher(this.LA(2).tokenType, t.New) === false,
      DEF: () => {
github SAP / chevrotain / examples / grammars / ecma5 / ecma5_parser.js View on Github external
canAndShouldDoSemiColonInsertion() {
    const nextToken = this.LA(1)
    const isNextTokenSemiColon = tokenMatcher(nextToken, t.Semicolon)
    return (
      isNextTokenSemiColon === false &&
      (this.lineTerminatorHere() || // basic rule 1a and 3
      tokenMatcher(nextToken, t.RCurly) || // basic rule 1b
        tokenMatcher(nextToken, EOF))
    ) // basic rule 2
  }
github jhipster / prettier-java / packages / java-parser / src / productions / packages-and-modules.js View on Github external
});
    } catch (e) {
      // This means we had a syntax error in the imports or annotations
      // So we can't keep parsing deep enough to make the decision
      if (isRecognitionException(e)) {
        // TODO: add original syntax error?
        throw "Cannot Identify if the source code is an OrdinaryCompilationUnit or  ModularCompilationUnit";
      } else {
        throw e;
      }
    }

    const nextTokenType = this.LA(1).tokenType;
    return (
      tokenMatcher(nextTokenType, t.Open) ||
      tokenMatcher(nextTokenType, t.Module)
    );
  });
}
github jhipster / prettier-java / packages / java-parser / src / productions / expressions.js View on Github external
GATE: () =>
        // avoids ambiguity with ".this" and ".new" which are parsed as a primary suffix.
        tokenMatcher(this.LA(2).tokenType, t.Class) === false &&
        tokenMatcher(this.LA(2).tokenType, t.This) === false &&
        tokenMatcher(this.LA(2).tokenType, t.New) === false,
      DEF: () => {
github jhipster / prettier-java / packages / java-parser / src / productions / expressions.js View on Github external
GATE: () =>
        tokenMatcher($.LA(1).tokenType, t.At) ||
        tokenMatcher($.LA(2).tokenType, t.RSquare),
      DEF: () => {
github jhipster / prettier-java / packages / java-parser / src / productions / classes.js View on Github external
GATE: () =>
          (tokenMatcher($.LA(1).tokenType, t.At) &&
            tokenMatcher($.LA(2).tokenType, t.Interface)) === false,
        DEF: () => {
github jhipster / prettier-java / packages / java-parser / src / productions / blocks-and-statements.js View on Github external
      GATE: () => tokenMatcher($.LA(2).tokenType, t.RBrace) === false,
      DEF: () => {
github jhipster / prettier-java / packages / java-parser / src / productions / interfaces.js View on Github external
      GATE: () => tokenMatcher($.LA(2).tokenType, t.RCurly) === false,
      DEF: () => {