diff --git a/src/platform/packages/shared/kbn-esql-ast/src/parser/parser.ts b/src/platform/packages/shared/kbn-esql-ast/src/parser/parser.ts index c6eeb8b7214c7..334c2fdbf6b36 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/parser/parser.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/parser/parser.ts @@ -13,33 +13,10 @@ import { ESQLErrorListener } from './esql_error_listener'; import { ESQLAstBuilderListener } from './esql_ast_builder_listener'; import { GRAMMAR_ROOT_RULE } from './constants'; import { attachDecorations, collectDecorations } from './formatting'; -import type { ESQLAst, ESQLAstQueryExpression, EditorError } from '../types'; import { Builder } from '../builder'; import { default as ESQLLexer } from '../antlr/esql_lexer'; import { default as ESQLParser } from '../antlr/esql_parser'; - -/** - * Some changes to the grammar deleted the literal names for some tokens. - * This is a workaround to restore the literals that were lost. - * - * See https://github.com/elastic/elasticsearch/pull/124177 for context. - */ -const replaceSymbolsWithLiterals = ( - symbolicNames: Array, - literalNames: Array -) => { - const symbolReplacements: Map = new Map([ - ['LP', '('], - ['OPENING_BRACKET', '['], - ]); - - for (let i = 0; i < symbolicNames.length; i++) { - const name = symbolicNames[i]; - if (name && symbolReplacements.has(name)) { - literalNames[i] = `'${symbolReplacements.get(name)!}'`; - } - } -}; +import type { ESQLAst, ESQLAstQueryExpression, EditorError } from '../types'; export interface ParseOptions { /** @@ -100,9 +77,6 @@ export class Parser { const tokens = (this.tokens = new CommonTokenStream(lexer)); const parser = (this.parser = new ESQLParser(tokens)); - replaceSymbolsWithLiterals(lexer.symbolicNames, lexer.literalNames); - replaceSymbolsWithLiterals(parser.symbolicNames, parser.literalNames); - lexer.removeErrorListeners(); lexer.addErrorListener(this.errors); diff --git a/src/platform/packages/shared/kbn-esql-validation-autocomplete/src/validation/validation.ts b/src/platform/packages/shared/kbn-esql-validation-autocomplete/src/validation/validation.ts index 2280ca3d531c6..1095430cb5576 100644 --- a/src/platform/packages/shared/kbn-esql-validation-autocomplete/src/validation/validation.ts +++ b/src/platform/packages/shared/kbn-esql-validation-autocomplete/src/validation/validation.ts @@ -194,8 +194,15 @@ async function validateAst( messages.push(...commandMessages); } + const parserErrors = parsingResult.errors; + + for (const error of parserErrors) { + error.message = error.message.replace(/\bLP\b/, "'('"); + error.message = error.message.replace(/\bOPENING_BRACKET\b/, "'['"); + } + return { - errors: [...parsingResult.errors, ...messages.filter(({ type }) => type === 'error')], + errors: [...parserErrors, ...messages.filter(({ type }) => type === 'error')], warnings: messages.filter(({ type }) => type === 'warning'), }; }