Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
// 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;
});
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: () => {
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
}
});
} 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)
);
});
}
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: () => {
GATE: () =>
tokenMatcher($.LA(1).tokenType, t.At) ||
tokenMatcher($.LA(2).tokenType, t.RSquare),
DEF: () => {
GATE: () =>
(tokenMatcher($.LA(1).tokenType, t.At) &&
tokenMatcher($.LA(2).tokenType, t.Interface)) === false,
DEF: () => {
GATE: () => tokenMatcher($.LA(2).tokenType, t.RBrace) === false,
DEF: () => {
GATE: () => tokenMatcher($.LA(2).tokenType, t.RCurly) === false,
DEF: () => {