How to use the chevrotain.isRecognitionException 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 / classes.js View on Github external
}

    try {
      // The {classModifier} is a super grammar of the "interfaceModifier"
      // So we must parse all the "{classModifier}" before we can distinguish
      // between the alternatives.
      $.MANY({
        GATE: () =>
          (tokenMatcher($.LA(1).tokenType, t.At) &&
            tokenMatcher($.LA(2).tokenType, t.Interface)) === false,
        DEF: () => {
          $.SUBRULE($.classModifier);
        }
      });
    } catch (e) {
      if (isRecognitionException(e)) {
        // TODO: add original syntax error?
        throw "Cannot Identify if the  is a  or an ";
      } else {
        throw e;
      }
    }

    if (isEmptyTypeDeclaration) {
      return false;
    }

    const nextTokenType = this.LA(1).tokenType;
    return (
      tokenMatcher(nextTokenType, t.Class) ||
      tokenMatcher(nextTokenType, t.Enum)
    );
github jhipster / prettier-java / packages / java-parser / src / productions / packages-and-modules.js View on Github external
$.SUBRULE2($.importDeclaration);
      });

      $.MANY2({
        // To avoid ambiguity with @interface ("AnnotationTypeDeclaration" vs "Annotaion")
        GATE: () =>
          (tokenMatcher($.LA(1).tokenType, t.At) &&
            tokenMatcher($.LA(2).tokenType, t.Interface)) === false,
        DEF: () => {
          $.SUBRULE($.annotation);
        }
      });
    } 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 felipemanga / FemtoIDE / node_modules / java-parser / src / productions / classes.js View on Github external
}

    try {
      // The {classModifier} is a super grammar of the "interfaceModifier"
      // So we must parse all the "{classModifier}" before we can distinguish
      // between the alternatives.
      $.MANY({
        GATE: () =>
          ($.LA(1).tokenType === t.At && $.LA(2).tokenType === t.Interface) ===
          false,
        DEF: () => {
          $.SUBRULE($.classModifier);
        }
      });
    } catch (e) {
      if (isRecognitionException(e)) {
        // TODO: add original syntax error?
        throw "Cannot Identify if the  is a  or an ";
      } else {
        throw e;
      }
    }

    const nextTokenType = this.LA(1).tokenType;
    return nextTokenType === t.Class || nextTokenType === t.Enum;
  });
github jhipster / prettier-java / packages / java-parser / src / parser.js View on Github external
return this.ACTION(() => {
      this.isBackTrackingStack.push(1);
      // TODO: "saveRecogState" does not handle the occurrence stack
      const orgState = this.saveRecogState();
      try {
        // hack to enable outputting none CST values from grammar rules.
        this.outputCst = false;
        return production.call(this);
      } catch (e) {
        if (isRecognitionException(e)) {
          return errValue;
        }
        throw e;
      } finally {
        this.outputCst = true;
        this.reloadRecogState(orgState);
        this.isBackTrackingStack.pop();
      }
    });
  }