Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
"adm-zip": "^0.5.9",
"ajv": "^8.12.0",
"ansi-regex": "^6.0.1",
"antlr4ts": "^0.5.0-alpha.3",
"antlr4": "^4.13.1-patch-1",
Copy link
Copy Markdown
Contributor Author

@eokoneyo eokoneyo Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the antlr4 javascript runtime and should not be confused with the cli that's a java binary used to generate the lexer and parser for defined languages.

"archiver": "^5.3.1",
"async": "^3.2.3",
"aws4": "^1.12.0",
Expand Down Expand Up @@ -1512,7 +1512,6 @@
"@yarnpkg/lockfile": "^1.1.0",
"abab": "^2.0.4",
"aggregate-error": "^3.1.0",
"antlr4ts-cli": "^0.5.0-alpha.3",
"apidoc-markdown": "^7.3.0",
"argsplit": "^1.0.5",
"autoprefixer": "^10.4.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-monaco/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SRCS = glob(
SHARED_DEPS = [
"//packages/kbn-i18n",
"//packages/kbn-ui-theme",
"@npm//antlr4ts",
"@npm//antlr4",
"@npm//monaco-editor",
"@npm//monaco-yaml",
"@npm//js-levenshtein",
Expand Down
7 changes: 4 additions & 3 deletions packages/kbn-monaco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"private": true,
"license": "SSPL-1.0 OR Elastic License 2.0",
"scripts": {
"build:antlr4ts:painless": "../../node_modules/antlr4ts-cli/antlr4ts ./src/painless/antlr/painless_lexer.g4 ./src/painless/antlr/painless_parser.g4 && node ./scripts/fix_generated_antlr.js painless",
"build:antlr4ts:esql": "../../node_modules/antlr4ts-cli/antlr4ts src/esql/antlr/esql_lexer.g4 src/esql/antlr/esql_parser.g4 && node ./scripts/fix_generated_antlr.js esql && node ./scripts/esql_update_ast_script.js",
"build:antlr4ts": "npm run build:antlr4ts:painless && npm run build:antlr4ts:esql"
"build:antlr4:painless": "antlr -Dlanguage=TypeScript ./src/painless/antlr/painless_lexer.g4 ./src/painless/antlr/painless_parser.g4 && node ./scripts/fix_generated_antlr.js painless",
"build:antlr4:esql": "antlr -Dlanguage=TypeScript src/esql/antlr/esql_lexer.g4 src/esql/antlr/esql_parser.g4 && node ./scripts/fix_generated_antlr.js esql && node ./scripts/esql_update_ast_script.js",
"prebuild:antlr4": "brew bundle --file=./scripts/antlr4_tools/brewfile",
"build:antlr4": "yarn run build:antlr4:painless && npm run build:antlr4:esql"
}
}
1 change: 1 addition & 0 deletions packages/kbn-monaco/scripts/antlr4_tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brewfile.lock.json
3 changes: 3 additions & 0 deletions packages/kbn-monaco/scripts/antlr4_tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## antlr4-tools

defines a fairly quick way to get [antlr](https://github.com/antlr/antlr4) setup on any machine with brew support, simply run `brew bundle` within this directory. On running the aforementioned command, `antlr` should be become available in your path as a valid executable.
2 changes: 2 additions & 0 deletions packages/kbn-monaco/scripts/antlr4_tools/brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
brew "openjdk"
brew "antlr"
8 changes: 4 additions & 4 deletions packages/kbn-monaco/scripts/esql_update_ast_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const { readdirSync, readFileSync, writeFileSync } = require('fs');
const ora = require('ora');
const log = ora('Updating ES|QL AST walker from antlr grammar').start();
/*
* This script will read from the parser file generated by the "build:antlr4ts:esql" task
* This script will read from the parser file generated by the "build:antlr4:esql" task
* and extract all quoted/unquoted tokens to update their ids
* into the "ast_helper" file.
* This prevents the bundle size to increase by ~500 kb ("esql_parser" size).
* This script is run at the end of "build:antlr4ts:esql" task, so no need to call it manually.
* This script is run at the end of "build:antlr4:esql" task, so no need to call it manually.
*/
async function execute(folder) {
const generatedAntlrFolder = join(__dirname, '..', 'src', folder, 'antlr');
Expand Down Expand Up @@ -60,7 +60,7 @@ function getQuotedText(ctx: ParserRuleContext) {
return [
${quotedList.map(({ name, value }) => `${value} /* esql_parser.${name} */`).join(', ')}
]
.map((keyCode) => ctx.tryGetToken(keyCode, 0))
.map((keyCode) => ctx.getToken(keyCode, 0))
.filter(nonNullable)[0];
}

Expand All @@ -69,7 +69,7 @@ function getUnquotedText(ctx: ParserRuleContext) {
${unquotedList.map(({ name, value }) => `${value} /* esql_parser.${name} */`).join(', ')}

]
.map((keyCode) => ctx.tryGetToken(keyCode, 0))
.map((keyCode) => ctx.getToken(keyCode, 0))
.filter(nonNullable)[0];
}
/* SCRIPT_MARKER_END */
Expand Down
6 changes: 4 additions & 2 deletions packages/kbn-monaco/scripts/fix_generated_antlr.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function execute(folder) {
.toString()
.split('\n');

fileContentRows.unshift('// @ts-nocheck');
if (!/\@ts-nocheck/.test(fileContentRows[0])) {
fileContentRows.unshift('// @ts-nocheck');
}

const filePath = join(generatedAntlrFolder, file);
const fileContent = fileContentRows.join('\n');
Expand All @@ -44,7 +46,7 @@ function execute(folder) {
});

// Rename generated parserListener file to snakecase to satisfy file casing check
// There doesn't appear to be a way to fix this OOTB with antlr4ts-cli
// There doesn't appear to be a way to fix this OOTB with antlr4
try {
renameSync(
join(generatedAntlrFolder, `${folder}_parserListener.ts`),
Expand Down
12 changes: 7 additions & 5 deletions packages/kbn-monaco/src/common/error_listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
* Side Public License, v 1.
*/

import { ANTLRErrorListener, Recognizer } from 'antlr4ts';
import type { Recognizer, RecognitionException } from 'antlr4';
import { ErrorListener } from 'antlr4';
import type { EditorError } from '../types';

export class ANTLREErrorListener implements ANTLRErrorListener<any> {
private errors: EditorError[] = [];
export class ANTLRErrorListener extends ErrorListener<any> {
protected errors: EditorError[] = [];

syntaxError(
recognizer: Recognizer<any, any>,
recognizer: Recognizer<any>,
offendingSymbol: any,
line: number,
column: number,
message: string
message: string,
error: RecognitionException | undefined
): void {
let endColumn = column + 1;

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-monaco/src/esql/antlr/esql_lexer.interp

Large diffs are not rendered by default.

Loading