Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"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
// 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 = {
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(
"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" ||
"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(
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
"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(
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);
});
}
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]
}
},
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;
}