How to use the chevrotain.MismatchedTokenException 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 / visitor.js View on Github external
"Only identifier is allowed with colon",
            undefined
          );
        }
        if (ctx.typeArguments || ctx.Dot) {
          throw new MismatchedTokenException(
            "Only identifier is allowed with type arguments or dot",
            undefined
          );
        }
      }

      // identifier statement
      if (expression.type === "IDENTIFIER" && ctx.Colon) {
        if (ctx.classOrInterfaceModifier) {
          throw new MismatchedTokenException(
            "Identifier statement is not allowed to have annotations or modifiers.",
            undefined
          );
        }
        if (ctx.LSquare || ctx.variableDeclarators) {
          throw new MismatchedTokenException(
            "Identifier statement is not allowed to have squares or variable declarators",
            undefined
          );
        }
        const statement = this.visit(ctx.statement);

        return {
          type: "IDENTIFIER_STATEMENT",
          identifier: expression,
          statement: statement
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
// parExpression

    // if parExpression
    // -> no
    //       - annotations
    //       - typeArguments
    //       - LSquare/RSquare
    // -> only one expression

    if (
      // ctx.annotation ||
      // ctx.typeArguments ||
      // ctx.LSquare ||
      ctx.expression.length !== 1
    ) {
      throw new MismatchedTokenException(
        "Found parenthesis expression with annotations, typeArguments or Squares",
        undefined
      );
    }

    const expression = this.visit(ctx.expression);

    const parExpression = {
      type: "PAR_EXPRESSION",
      expression: expression
    };

    if (ctx.qualifiedExpressionRest) {
      const rest = this.visit(ctx.qualifiedExpressionRest);

      const qualifiedExpression = {
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
return this.visit(ctx.commentStandalone);
    }

    if (ctx.expression) {
      let expression = this.visit(ctx.expression);

      if (expression.type === "PRIMITIVE_TYPE") {
        // if expression is only a primitiveType nothing else is allowed with it
        if (ctx.Colon) {
          throw new MismatchedTokenException(
            "Primitive type with colon found",
            undefined
          );
        }
        if (ctx.typeArguments || ctx.Dot) {
          throw new MismatchedTokenException(
            "Primitive type with type arguments or dot found",
            undefined
          );
        }
      }

      if (expression.type !== "IDENTIFIER") {
        // if expression is only a primitiveType nothing else is allowed with it
        if (ctx.Colon) {
          throw new MismatchedTokenException(
            "Only identifier is allowed with colon",
            undefined
          );
        }
        if (ctx.typeArguments || ctx.Dot) {
          throw new MismatchedTokenException(
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
"Only identifier is allowed with type arguments or dot",
            undefined
          );
        }
      }

      // identifier statement
      if (expression.type === "IDENTIFIER" && ctx.Colon) {
        if (ctx.classOrInterfaceModifier) {
          throw new MismatchedTokenException(
            "Identifier statement is not allowed to have annotations or modifiers.",
            undefined
          );
        }
        if (ctx.LSquare || ctx.variableDeclarators) {
          throw new MismatchedTokenException(
            "Identifier statement is not allowed to have squares or variable declarators",
            undefined
          );
        }
        const statement = this.visit(ctx.statement);

        return {
          type: "IDENTIFIER_STATEMENT",
          identifier: expression,
          statement: statement
        };
      }

      const followedEmptyLine = this.visit(ctx.semiColon).followedEmptyLine;
      if (
        expression.type === "IDENTIFIER" ||
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
"Primitive type with colon found",
            undefined
          );
        }
        if (ctx.typeArguments || ctx.Dot) {
          throw new MismatchedTokenException(
            "Primitive type with type arguments or dot found",
            undefined
          );
        }
      }

      if (expression.type !== "IDENTIFIER") {
        // if expression is only a primitiveType nothing else is allowed with it
        if (ctx.Colon) {
          throw new MismatchedTokenException(
            "Only identifier is allowed with colon",
            undefined
          );
        }
        if (ctx.typeArguments || ctx.Dot) {
          throw new MismatchedTokenException(
            "Only identifier is allowed with type arguments or dot",
            undefined
          );
        }
      }

      // identifier statement
      if (expression.type === "IDENTIFIER" && ctx.Colon) {
        if (ctx.classOrInterfaceModifier) {
          throw new MismatchedTokenException(
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
left: value,
          operator: operator,
          right: expression
        };
      }
      // We have a cast expression

      // if identifier is not an identifier throw error
      if (
        value.type !== "IDENTIFIER" &&
        value.type !== "CLASS_OR_INTERFACE_TYPE_ELEMENT" &&
        value.type !== "TYPE_TYPE" &&
        value.type !== "PRIMITIVE_TYPE" &&
        value.type !== "QUALIFIED_EXPRESSION"
      ) {
        throw new MismatchedTokenException(
          "Found cast expression but cast expression is not an Identifier",
          undefined
        );
      }

      return {
        type: "CAST_EXPRESSION",
        castType: value,
        expression: expression
      };
    }

    // parExpression

    // if parExpression
    // -> no
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
"Primitive type with type arguments or dot found",
            undefined
          );
        }
      }

      if (expression.type !== "IDENTIFIER") {
        // if expression is only a primitiveType nothing else is allowed with it
        if (ctx.Colon) {
          throw new MismatchedTokenException(
            "Only identifier is allowed with colon",
            undefined
          );
        }
        if (ctx.typeArguments || ctx.Dot) {
          throw new MismatchedTokenException(
            "Only identifier is allowed with type arguments or dot",
            undefined
          );
        }
      }

      // identifier statement
      if (expression.type === "IDENTIFIER" && ctx.Colon) {
        if (ctx.classOrInterfaceModifier) {
          throw new MismatchedTokenException(
            "Identifier statement is not allowed to have annotations or modifiers.",
            undefined
          );
        }
        if (ctx.LSquare || ctx.variableDeclarators) {
          throw new MismatchedTokenException(
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
ctx.expression.map(expression => {
              const identifier = this.visit(expression);
              if (identifier.type !== "IDENTIFIER") {
                throw new MismatchedTokenException(
                  "Found lambda expression but left side is not an identifier",
                  undefined
                );
              }

              parameters.identifiers.list.push(identifier);
            });
          }
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
const ifElseExpressionRest = this.visit(ctx.ifElseExpressionRest);

          return {
            type: "IF_ELSE_EXPRESSION",
            condition: operatorExpression,
            if: ifElseExpressionRest.if,
            else: ifElseExpressionRest.else
          };
        }

        return operatorExpression;
      }

      if (ctx.Pointer) {
        if (atomic.type !== "IDENTIFIER") {
          throw new MismatchedTokenException(
            "Found lambda expression but left side is not an identifier",
            undefined
          );
        }

        const body = this.visit(ctx.lambdaBody);

        return {
          type: "LAMBDA_EXPRESSION",
          parameters: {
            type: "IDENTIFIERS",
            identifiers: {
              type: "IDENTIFIER_LIST",
              list: [atomic]
            }
          },
github jhipster / prettier-java / packages / java-parser / src / visitor.js View on Github external
formalParameterList(ctx) {
    const formalParameters = [];
    if (ctx.formalParameter) {
      ctx.formalParameter.map(formalParameter =>
        formalParameters.push(this.visit(formalParameter))
      );
    }

    for (let i = 0; i < formalParameters.length; i++) {
      if (formalParameters[i].dotDotDot && i + 1 < formalParameters.length) {
        throw new MismatchedTokenException(
          'Only last parameter is allowed with "..."',
          undefined
        );
      }
    }

    return formalParameters;
  }