Skip to content

Commit

Permalink
chore: upgrade to Chevrotain 11
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkiesel committed Dec 30, 2023
1 parent 4eabddd commit 83eb25d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/java-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "Apache-2.0",
"types": "./api.d.ts",
"dependencies": {
"chevrotain": "6.5.0",
"chevrotain": "11.0.3",
"lodash": "4.17.21"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/java-parser/scripts/gen-diagrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
import path from "path";
import fs from "fs";
import chevrotain from "chevrotain";
import * as chevrotain from "chevrotain";
import url from "url";
import JavaParser from "../src/parser.js";

Expand Down
38 changes: 24 additions & 14 deletions packages/java-parser/src/parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Parser, isRecognitionException } from "chevrotain";
import { CstParser, isRecognitionException } from "chevrotain";
import { allTokens, tokens as t } from "./tokens.js";
import * as lexicalStructure from "./productions/lexical-structure.js";
import * as typesValuesVariables from "./productions/types-values-and-variables.js";
Expand Down Expand Up @@ -35,7 +35,7 @@ import { shouldNotFormat } from "./comments.js";
* TODO: document guide lines for using back tracking
*
*/
export default class JavaParser extends Parser {
export default class JavaParser extends CstParser {
constructor() {
super(allTokens, {
maxLookahead: 1,
Expand Down Expand Up @@ -76,16 +76,16 @@ export default class JavaParser extends Parser {
}

cstPostNonTerminal(ruleCstResult, ruleName) {
if (this.isBackTracking()) {
return;
}
super.cstPostNonTerminal(ruleCstResult, ruleName);
if (this.isBackTracking() === false) {
this.mostEnclosiveCstNodeByStartOffset[
ruleCstResult.location.startOffset
] = ruleCstResult;
this.mostEnclosiveCstNodeByEndOffset[ruleCstResult.location.endOffset] =
ruleCstResult;
this.mostEnclosiveCstNodeByStartOffset[ruleCstResult.location.startOffset] =
ruleCstResult;
this.mostEnclosiveCstNodeByEndOffset[ruleCstResult.location.endOffset] =
ruleCstResult;

shouldNotFormat(ruleCstResult, this.onOffCommentPairs);
}
shouldNotFormat(ruleCstResult, this.onOffCommentPairs);
}

BACKTRACK_LOOKAHEAD(production, errValue = false) {
Expand All @@ -94,16 +94,26 @@ export default class JavaParser extends Parser {
// 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);
// hack to enable outputting non-CST values from grammar rules.
const { ruleName, originalGrammarAction } = production;
try {
this.ruleInvocationStateUpdate(
this.fullRuleNameToShort[ruleName],
ruleName,
this.subruleIdx
);
return originalGrammarAction.call(this);
} catch (e) {
return this.invokeRuleCatch(e, true, () => undefined);
} finally {
this.ruleFinallyStateUpdate();
}
} catch (e) {
if (isRecognitionException(e)) {
return errValue;
}
throw e;
} finally {
this.outputCst = true;
this.reloadRecogState(orgState);
this.isBackTrackingStack.pop();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/prettier-plugin-java/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build:watch": "tsc --inlineSourceMap -w"
},
"devDependencies": {
"@chevrotain/types": "9.0.2",
"@chevrotain/types": "11.0.3",
"@types/chai": "4.3.4",
"@types/fs-extra": "9.0.13",
"@types/jest": "29.2.3",
Expand Down
52 changes: 48 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,37 @@
"@babel/helper-validator-identifier" "^7.22.20"
to-fast-properties "^2.0.0"

"@chevrotain/types@9.0.2":
version "9.0.2"
resolved "https://registry.yarnpkg.com/@chevrotain/types/-/types-9.0.2.tgz#477bb3b973b91ff47377399d1e9f4410be6c0141"
integrity sha512-lo1dQPX7DQffJb26eaYLEy4/jUTFmsGKa43mDvMNAHwItEgUQHUkTZR0iAkHG0aJv8ejM/KqYpRVSNetrOK8qw==
"@chevrotain/cst-dts-gen@11.0.3":
version "11.0.3"
resolved "https://registry.yarnpkg.com/@chevrotain/cst-dts-gen/-/cst-dts-gen-11.0.3.tgz#5e0863cc57dc45e204ccfee6303225d15d9d4783"
integrity sha512-BvIKpRLeS/8UbfxXxgC33xOumsacaeCKAjAeLyOn7Pcp95HiRbrpl14S+9vaZLolnbssPIUuiUd8IvgkRyt6NQ==
dependencies:
"@chevrotain/gast" "11.0.3"
"@chevrotain/types" "11.0.3"
lodash-es "4.17.21"

"@chevrotain/gast@11.0.3":
version "11.0.3"
resolved "https://registry.yarnpkg.com/@chevrotain/gast/-/gast-11.0.3.tgz#e84d8880323fe8cbe792ef69ce3ffd43a936e818"
integrity sha512-+qNfcoNk70PyS/uxmj3li5NiECO+2YKZZQMbmjTqRI3Qchu8Hig/Q9vgkHpI3alNjr7M+a2St5pw5w5F6NL5/Q==
dependencies:
"@chevrotain/types" "11.0.3"
lodash-es "4.17.21"

"@chevrotain/regexp-to-ast@11.0.3":
version "11.0.3"
resolved "https://registry.yarnpkg.com/@chevrotain/regexp-to-ast/-/regexp-to-ast-11.0.3.tgz#11429a81c74a8e6a829271ce02fc66166d56dcdb"
integrity sha512-1fMHaBZxLFvWI067AVbGJav1eRY7N8DDvYCTwGBiE/ytKBgP8azTdgyrKyWZ9Mfh09eHWb5PgTSO8wi7U824RA==

"@chevrotain/types@11.0.3":
version "11.0.3"
resolved "https://registry.yarnpkg.com/@chevrotain/types/-/types-11.0.3.tgz#f8a03914f7b937f594f56eb89312b3b8f1c91848"
integrity sha512-gsiM3G8b58kZC2HaWR50gu6Y1440cHiJ+i3JUvcp/35JchYejb2+5MVeJK0iKThYpAa/P2PYFV4hoi44HD+aHQ==

"@chevrotain/utils@11.0.3":
version "11.0.3"
resolved "https://registry.yarnpkg.com/@chevrotain/utils/-/utils-11.0.3.tgz#e39999307b102cff3645ec4f5b3665f5297a2224"
integrity sha512-YslZMgtJUyuMbZ+aKvfF3x1f5liK4mWNxghFRv7jqRR9C3R3fAOGTTKvxXDa2Y1s9zSbcpuO0cAxDYsc9SrXoQ==

"@cspotcode/source-map-support@^0.8.0":
version "0.8.1"
Expand Down Expand Up @@ -2017,6 +2044,18 @@ check-error@^1.0.3:
dependencies:
get-func-name "^2.0.2"

chevrotain@11.0.3:
version "11.0.3"
resolved "https://registry.yarnpkg.com/chevrotain/-/chevrotain-11.0.3.tgz#88ffc1fb4b5739c715807eaeedbbf200e202fc1b"
integrity sha512-ci2iJH6LeIkvP9eJW6gpueU8cnZhv85ELY8w8WiFtNjMHA5ad6pQLaJo9mEly/9qUyCpvqX8/POVUTf18/HFdw==
dependencies:
"@chevrotain/cst-dts-gen" "11.0.3"
"@chevrotain/gast" "11.0.3"
"@chevrotain/regexp-to-ast" "11.0.3"
"@chevrotain/types" "11.0.3"
"@chevrotain/utils" "11.0.3"
lodash-es "4.17.21"

chevrotain@6.5.0:
version "6.5.0"
resolved "https://registry.yarnpkg.com/chevrotain/-/chevrotain-6.5.0.tgz#dcbef415516b0af80fd423cc0d96b28d3f11374e"
Expand Down Expand Up @@ -4023,6 +4062,11 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"

lodash-es@4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash.flattendeep@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
Expand Down

0 comments on commit 83eb25d

Please sign in to comment.