Skip to content

Commit 982a4c4

Browse files
jtkieselclementdessoude
authored andcommitted
chore: upgrade to Chevrotain 11
closes #423
1 parent b7b46fa commit 982a4c4

File tree

5 files changed

+75
-21
lines changed

5 files changed

+75
-21
lines changed

packages/java-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "Apache-2.0",
99
"types": "./api.d.ts",
1010
"dependencies": {
11-
"chevrotain": "6.5.0",
11+
"chevrotain": "11.0.3",
1212
"lodash": "4.17.21"
1313
},
1414
"scripts": {

packages/java-parser/scripts/gen-diagrams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
import path from "path";
1212
import fs from "fs";
13-
import chevrotain from "chevrotain";
13+
import * as chevrotain from "chevrotain";
1414
import url from "url";
1515
import JavaParser from "../src/parser.js";
1616

packages/java-parser/src/parser.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Parser, isRecognitionException } from "chevrotain";
1+
import { CstParser, isRecognitionException } from "chevrotain";
22
import { allTokens, tokens as t } from "./tokens.js";
33
import * as lexicalStructure from "./productions/lexical-structure.js";
44
import * as typesValuesVariables from "./productions/types-values-and-variables.js";
@@ -35,7 +35,7 @@ import { shouldNotFormat } from "./comments.js";
3535
* TODO: document guide lines for using back tracking
3636
*
3737
*/
38-
export default class JavaParser extends Parser {
38+
export default class JavaParser extends CstParser {
3939
constructor() {
4040
super(allTokens, {
4141
maxLookahead: 1,
@@ -76,16 +76,16 @@ export default class JavaParser extends Parser {
7676
}
7777

7878
cstPostNonTerminal(ruleCstResult, ruleName) {
79+
if (this.isBackTracking()) {
80+
return;
81+
}
7982
super.cstPostNonTerminal(ruleCstResult, ruleName);
80-
if (this.isBackTracking() === false) {
81-
this.mostEnclosiveCstNodeByStartOffset[
82-
ruleCstResult.location.startOffset
83-
] = ruleCstResult;
84-
this.mostEnclosiveCstNodeByEndOffset[ruleCstResult.location.endOffset] =
85-
ruleCstResult;
83+
this.mostEnclosiveCstNodeByStartOffset[ruleCstResult.location.startOffset] =
84+
ruleCstResult;
85+
this.mostEnclosiveCstNodeByEndOffset[ruleCstResult.location.endOffset] =
86+
ruleCstResult;
8687

87-
shouldNotFormat(ruleCstResult, this.onOffCommentPairs);
88-
}
88+
shouldNotFormat(ruleCstResult, this.onOffCommentPairs);
8989
}
9090

9191
BACKTRACK_LOOKAHEAD(production, errValue = false) {
@@ -94,16 +94,26 @@ export default class JavaParser extends Parser {
9494
// TODO: "saveRecogState" does not handle the occurrence stack
9595
const orgState = this.saveRecogState();
9696
try {
97-
// hack to enable outputting none CST values from grammar rules.
98-
this.outputCst = false;
99-
return production.call(this);
97+
// hack to enable outputting non-CST values from grammar rules.
98+
const { ruleName, originalGrammarAction } = production;
99+
try {
100+
this.ruleInvocationStateUpdate(
101+
this.fullRuleNameToShort[ruleName],
102+
ruleName,
103+
this.subruleIdx
104+
);
105+
return originalGrammarAction.call(this);
106+
} catch (e) {
107+
return this.invokeRuleCatch(e, true, () => undefined);
108+
} finally {
109+
this.ruleFinallyStateUpdate();
110+
}
100111
} catch (e) {
101112
if (isRecognitionException(e)) {
102113
return errValue;
103114
}
104115
throw e;
105116
} finally {
106-
this.outputCst = true;
107117
this.reloadRecogState(orgState);
108118
this.isBackTrackingStack.pop();
109119
}

packages/prettier-plugin-java/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"build:watch": "tsc --inlineSourceMap -w"
2727
},
2828
"devDependencies": {
29-
"@chevrotain/types": "9.0.2",
29+
"@chevrotain/types": "11.0.3",
3030
"@types/chai": "4.3.4",
3131
"@types/fs-extra": "9.0.13",
3232
"@types/jest": "29.2.3",

yarn.lock

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,37 @@
194194
"@babel/helper-validator-identifier" "^7.22.20"
195195
to-fast-properties "^2.0.0"
196196

197-
"@chevrotain/types@9.0.2":
198-
version "9.0.2"
199-
resolved "https://registry.yarnpkg.com/@chevrotain/types/-/types-9.0.2.tgz#477bb3b973b91ff47377399d1e9f4410be6c0141"
200-
integrity sha512-lo1dQPX7DQffJb26eaYLEy4/jUTFmsGKa43mDvMNAHwItEgUQHUkTZR0iAkHG0aJv8ejM/KqYpRVSNetrOK8qw==
197+
"@chevrotain/cst-dts-gen@11.0.3":
198+
version "11.0.3"
199+
resolved "https://registry.yarnpkg.com/@chevrotain/cst-dts-gen/-/cst-dts-gen-11.0.3.tgz#5e0863cc57dc45e204ccfee6303225d15d9d4783"
200+
integrity sha512-BvIKpRLeS/8UbfxXxgC33xOumsacaeCKAjAeLyOn7Pcp95HiRbrpl14S+9vaZLolnbssPIUuiUd8IvgkRyt6NQ==
201+
dependencies:
202+
"@chevrotain/gast" "11.0.3"
203+
"@chevrotain/types" "11.0.3"
204+
lodash-es "4.17.21"
205+
206+
"@chevrotain/gast@11.0.3":
207+
version "11.0.3"
208+
resolved "https://registry.yarnpkg.com/@chevrotain/gast/-/gast-11.0.3.tgz#e84d8880323fe8cbe792ef69ce3ffd43a936e818"
209+
integrity sha512-+qNfcoNk70PyS/uxmj3li5NiECO+2YKZZQMbmjTqRI3Qchu8Hig/Q9vgkHpI3alNjr7M+a2St5pw5w5F6NL5/Q==
210+
dependencies:
211+
"@chevrotain/types" "11.0.3"
212+
lodash-es "4.17.21"
213+
214+
"@chevrotain/regexp-to-ast@11.0.3":
215+
version "11.0.3"
216+
resolved "https://registry.yarnpkg.com/@chevrotain/regexp-to-ast/-/regexp-to-ast-11.0.3.tgz#11429a81c74a8e6a829271ce02fc66166d56dcdb"
217+
integrity sha512-1fMHaBZxLFvWI067AVbGJav1eRY7N8DDvYCTwGBiE/ytKBgP8azTdgyrKyWZ9Mfh09eHWb5PgTSO8wi7U824RA==
218+
219+
"@chevrotain/types@11.0.3":
220+
version "11.0.3"
221+
resolved "https://registry.yarnpkg.com/@chevrotain/types/-/types-11.0.3.tgz#f8a03914f7b937f594f56eb89312b3b8f1c91848"
222+
integrity sha512-gsiM3G8b58kZC2HaWR50gu6Y1440cHiJ+i3JUvcp/35JchYejb2+5MVeJK0iKThYpAa/P2PYFV4hoi44HD+aHQ==
223+
224+
"@chevrotain/utils@11.0.3":
225+
version "11.0.3"
226+
resolved "https://registry.yarnpkg.com/@chevrotain/utils/-/utils-11.0.3.tgz#e39999307b102cff3645ec4f5b3665f5297a2224"
227+
integrity sha512-YslZMgtJUyuMbZ+aKvfF3x1f5liK4mWNxghFRv7jqRR9C3R3fAOGTTKvxXDa2Y1s9zSbcpuO0cAxDYsc9SrXoQ==
201228

202229
"@cspotcode/source-map-support@^0.8.0":
203230
version "0.8.1"
@@ -2017,6 +2044,18 @@ check-error@^1.0.3:
20172044
dependencies:
20182045
get-func-name "^2.0.2"
20192046

2047+
chevrotain@11.0.3:
2048+
version "11.0.3"
2049+
resolved "https://registry.yarnpkg.com/chevrotain/-/chevrotain-11.0.3.tgz#88ffc1fb4b5739c715807eaeedbbf200e202fc1b"
2050+
integrity sha512-ci2iJH6LeIkvP9eJW6gpueU8cnZhv85ELY8w8WiFtNjMHA5ad6pQLaJo9mEly/9qUyCpvqX8/POVUTf18/HFdw==
2051+
dependencies:
2052+
"@chevrotain/cst-dts-gen" "11.0.3"
2053+
"@chevrotain/gast" "11.0.3"
2054+
"@chevrotain/regexp-to-ast" "11.0.3"
2055+
"@chevrotain/types" "11.0.3"
2056+
"@chevrotain/utils" "11.0.3"
2057+
lodash-es "4.17.21"
2058+
20202059
chevrotain@6.5.0:
20212060
version "6.5.0"
20222061
resolved "https://registry.yarnpkg.com/chevrotain/-/chevrotain-6.5.0.tgz#dcbef415516b0af80fd423cc0d96b28d3f11374e"
@@ -4023,6 +4062,11 @@ locate-path@^6.0.0:
40234062
dependencies:
40244063
p-locate "^5.0.0"
40254064

4065+
lodash-es@4.17.21:
4066+
version "4.17.21"
4067+
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
4068+
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==
4069+
40264070
lodash.flattendeep@^4.4.0:
40274071
version "4.4.0"
40284072
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"

0 commit comments

Comments
 (0)