Skip to content

Conversation

eokoneyo
Copy link
Contributor

@eokoneyo eokoneyo commented Feb 19, 2024

Summary

This PR migrates kibana away from using the antlr4ts to the official antlr package, so the grammar used in Kibana (for example with ES|QL) is on par with ES.

@eokoneyo eokoneyo self-assigned this Feb 19, 2024
@eokoneyo eokoneyo changed the title [PoC] Migrating to official antlr package [PoC] Migrate to official antlr4 package Feb 19, 2024
@eokoneyo eokoneyo force-pushed the chore/poc-exploring-antlr branch from 23a5405 to 79258d0 Compare February 19, 2024 17:20
@@ -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
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.

@eokoneyo eokoneyo added the Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// label Feb 19, 2024
@eokoneyo eokoneyo force-pushed the chore/poc-exploring-antlr branch 5 times, most recently from 26da451 to 16a6499 Compare February 22, 2024 13:22
@eokoneyo
Copy link
Contributor Author

eokoneyo commented Mar 4, 2024

/ci

@eokoneyo eokoneyo marked this pull request as ready for review March 4, 2024 17:11
@eokoneyo eokoneyo requested review from a team as code owners March 4, 2024 17:11
@elasticmachine
Copy link
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

@eokoneyo eokoneyo added the release_note:skip Skip the PR/issue when compiling release notes label Mar 4, 2024
@eokoneyo
Copy link
Contributor Author

eokoneyo commented Mar 4, 2024

@elasticmachine merge upstream

@eokoneyo eokoneyo linked an issue Mar 4, 2024 that may be closed by this pull request
@eokoneyo eokoneyo changed the title [PoC] Migrate to official antlr4 package Migrate to official antlr4 package Mar 4, 2024
Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Tested with ES|QL and works ok 👍

@@ -28,10 +27,6 @@ export const ESQLLang: CustomLangModuleType<ESQLCallbacks> = {
workerProxyService.setup(ESQL_LANG_ID);

monaco.languages.setTokensProvider(ESQL_LANG_ID, new ESQLTokensProvider());

// handle syntax errors via the diagnostic adapter
Copy link
Contributor

Choose a reason for hiding this comment

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

This is handled now together with the rest of the validation task.

@eokoneyo eokoneyo force-pushed the chore/poc-exploring-antlr branch from d9b5c5c to aa65424 Compare March 5, 2024 09:26
@eokoneyo eokoneyo requested review from a team as code owners March 5, 2024 09:26
@eokoneyo eokoneyo force-pushed the chore/poc-exploring-antlr branch from aa65424 to 7aababd Compare March 5, 2024 09:28
@eokoneyo eokoneyo removed request for a team March 5, 2024 09:29
@eokoneyo eokoneyo removed the Feature:Drilldowns Embeddable panel Drilldowns label Mar 5, 2024
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 2.9MB 2.9MB -5.1KB
Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/monaco 4 6 +2

Total ESLint disabled count

id before after diff
@kbn/monaco 11 13 +2

History

  • 💚 Build #195752 succeeded d9b5c5c301b5ba6c8b8b69be0b7c052cb8cd2dea
  • 💚 Build #195707 succeeded 44a80d503cadf62b237e591009c721b384c36699

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @eokoneyo

Copy link
Contributor

@vadimkibana vadimkibana left a comment

Choose a reason for hiding this comment

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

Code changes LGTM, didn't run locally.

Comment on lines +30 to 32
// @ts-expect-error the addParseListener API does exist and is documented here
// https://github.com/antlr/antlr4/blob/dev/doc/listeners.md
parser.addParseListener(parseListener);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to cast to any instead of @ts-expect-error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using @ts-expect-error is actually a better choice for this scenario, in the event that this method becomes present in the type declaration we'd get an error to remove this, unlike with any.

@eokoneyo eokoneyo merged commit cbcbb93 into elastic:main Mar 5, 2024
@eokoneyo eokoneyo deleted the chore/poc-exploring-antlr branch March 5, 2024 14:27
@kibanamachine kibanamachine added v8.14.0 backport:skip This commit does not require backporting labels Mar 5, 2024
drewdaemon added a commit that referenced this pull request Mar 8, 2024
## Summary

Up till now, we had to define our own lexer rules for our client-side
ES|QL validation. This was because we were using an unofficial ANTLR
package (before the official ANTLR had typescript support).

Now that we are using the official ANTLR library (as of
#177211), we no longer have to
encode case insensitivity into the lexer rules themselves because the
[`caseInsensitive` option](antlr/antlr4#3399) is
now available to us.

This means we can adopt the very [same
definitions](https://github.com/elastic/elasticsearch/blob/343b1ae1ba74fbf2e75c29adddb2790312dd680b/x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.g4)
that Elasticsearch uses as long as we set `caseInsensitive`
(Elasticsearch handles case insensitivity at runtime).

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SharedUX] Replace antlr4ts dependency with official antlr package
6 participants