Fix float parsing precision in SimpleQueryParser#4913
Merged
kgrgreer merged 6 commits intodevelopmentfrom Mar 14, 2026
Merged
Conversation
VesnaSUG
requested changes
Mar 14, 2026
src/foam/parse/SimpleQueryParser.js
Outdated
| @@ -191,8 +191,11 @@ foam.CLASS({ | |||
|
|
|||
| digits: str(repeat(range('0', '9'), null, 1)), | |||
Collaborator
There was a problem hiding this comment.
@abdelaziz-mahdy why are we duplicating the grammar here. Shouldn't we have digits just call sym(rawDigits)?
Collaborator
Author
There was a problem hiding this comment.
noted: fixed
Owner
|
The Java version has the same issue: |
digits now delegates to sym('rawDigits') instead of duplicating the
grammar rule. rawDigits holds the base grammar, digits adds parseInt.
Collaborator
Author
fixed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SimpleQueryParser corrupted small float values (e.g.,
0.001,0.0001) during parsing. Thedigitsgrammar action appliedparseInt()to the fractional part of floats, stripping leading zeros —0.001became0.1,0.0001became0.1. This broke all float-based queries (IN RANGE, equality, comparison) for values with leading zeros after the decimal point.Separately,
Constant.toMQL()usedtoFixed(20)which added floating-point noise to the output (e.g.,0.1became0.10000000000000000555).Solution
Add a
rawDigitsgrammar symbol (identical grammar todigitsbut without theparseIntaction) and use it in thefloatrule. This preserves the raw digit string"001"during float parsing instead of converting it to1. Fix applied to both JS and Java parsers.Fix
Constant.toMQL()to useString()(shortest exact decimal representation) withtoFixed(20)fallback only for scientific notation.Changes
rawDigitsgrammar symbol in both JS and Java SimpleQueryParser to preserve leading zeros in float fractional partsConstant.toMQL()float formatting:String()instead oftoFixed(20)to avoid floating-point noiseSimpleQueryParserTest,SimpleQueryParserJavaTest, andSimpleQueryParserMQLTest