antlr / antlr/antlr4

Dart to JS Integer Literal not Represented Exactly

Open
#3,928 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

Hello, this isn't a bug in antlr4, but I was hoping for some guidance with using it.

I've used it extensively for parsing FHIRPath, the repo can be found here: https://github.com/MayJuun/fhir/tree/main/fhir_path.

I've setup an app to test with, that works fine for Linux and Android: https://github.com/MayJuun/fhir/tree/dev/fhir_path/test/fhir_path_test

However, when I try to run it in web, I get the following error:
```
Launching lib/main.dart on Chrome in debug mode...
lib/main.dart:1
: Error: The integer literal 4575657493346130736 can't be represented exactly in JavaScript.
../…/antlr4/fhirPathParser.dart:802
Try changing the literal to something that can be represented in Javascript. In Javascript 4575657493346130944 is the nearest value that can be represented exactly.
if (((_la) & ~0x3f) == 0 && ((1 << _la) & 4575657493346130736) != 0) {
```

Referencing this line: https://github.com/MayJuun/fhir/blob/dev/fhir_path/lib/antlr4/fhirPathParser.dart#L802

As I said, I know this isn't an error with Antlr4, but I was wondering if anyone else found a way around this issue?

Contributor guide

Open the contributing guide

Research direction

Inspect the generated fhirPathParser.dart at line 802 and compare it with the Dart web build error. Start by examining how the ANTLR Dart target emits integer literals for parser lookahead masks; done means the generated parser can compile for JavaScript without losing the intended mask value.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, javascript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.