Skip to content

Commit

Permalink
optimization by extracting logic to compute firstForUnaryExpressionNo…
Browse files Browse the repository at this point in the history
…tPlusMinus
  • Loading branch information
clementdessoude committed Sep 27, 2019
1 parent 5a620d9 commit 4a70840
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions packages/java-parser/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class JavaParser extends Parser {
blocksStatements.defineRules.call(this, $, t);
expressions.defineRules.call(this, $, t);

this.firstForUnaryExpressionNotPlusMinus = [];
this.performSelfAnalysis();
this.firstForUnaryExpressionNotPlusMinus = expressions.computeFirstForUnaryExpressionNotPlusMinus.call(
this
);
}

// hack to turn off CST building side effects during backtracking
Expand Down
29 changes: 15 additions & 14 deletions packages/java-parser/src/productions/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,18 +612,6 @@ function defineRules($, t) {
});

$.RULE("isReferenceTypeCastExpression", () => {
const firstUnaryExpressionNotPlusMinus = this.computeContentAssist(
"unaryExpressionNotPlusMinus",
[]
);
const nextTokTypes = firstUnaryExpressionNotPlusMinus.map(
x => x.nextTokenType
);
// uniq
const firstForUnaryExpressionNotPlusMinus = nextTokTypes.filter(
(v, i, a) => a.indexOf(v) === i
);

$.CONSUME(t.LBrace);
$.SUBRULE($.referenceType);
$.MANY(() => {
Expand All @@ -633,7 +621,7 @@ function defineRules($, t) {
const firstTokTypeAfterRBrace = this.LA(1).tokenType;

return (
firstForUnaryExpressionNotPlusMinus.find(tokType =>
this.firstForUnaryExpressionNotPlusMinus.find(tokType =>
tokenMatcher(firstTokTypeAfterRBrace, tokType)
) !== undefined
);
Expand Down Expand Up @@ -673,6 +661,19 @@ function defineRules($, t) {
});
}

function computeFirstForUnaryExpressionNotPlusMinus() {
const firstUnaryExpressionNotPlusMinus = this.computeContentAssist(
"unaryExpressionNotPlusMinus",
[]
);
const nextTokTypes = firstUnaryExpressionNotPlusMinus.map(
x => x.nextTokenType
);
// uniq
return nextTokTypes.filter((v, i, a) => a.indexOf(v) === i);
}

module.exports = {
defineRules
defineRules,
computeFirstForUnaryExpressionNotPlusMinus
};

0 comments on commit 4a70840

Please sign in to comment.