What is underscore in terms of real or floating point fragments #4649
Replies: 4 comments 10 replies
-
To clarify a bit, basically, I want to support the following kinds of use cases:
Maybe that's asking too much. i.e. just define an |
Beta Was this translation helpful? Give feedback.
-
Having a devil of a time making this work correctly. Trying to get this "simple" DSL working, but it cannot seem to parse beyond the first fragment DIGIT: [0-9];
fragment DOT: '.';
fragment MINUS: '-';
DECIMAL_LITERAL: DIGIT+ ( DOT DIGIT+ )?;
NUMERIC_LITERAL: MINUS? DECIMAL_LITERAL;
SP: ' ';
WS: ( SP | HT | VT )+ -> skip;
location: coordinate ( SP+ coordinate )*;
coordinate: NUMERIC_LITERAL; I've tried different iterations of this, none of them seem to be quite working. For now focused there. Goal is to support the decimal forms above. But like I said, I am willing to consider an Eventually in its slightly more complex axis based form: // Importing the baseline grammar
fragment X: [xX];
fragment Y: [yY];
fragment Z: [zZ];
AXIS: X | Y | Z;
OP_EQ: '=';
coordinate: AXIS SP* OP_EQ SP* DECIMAL_LITERAL; |
Beta Was this translation helpful? Give feedback.
-
By comparison, or perhaps contrast at this point, the same problem approached from a regular expression perspective has been proven far more reliable. decimal val;
var re = new Regex(@$"\s*(?<{nameof(val)}>\-?(\d+(\.\d*)?|\d*\.\d+))");
// And subsequent logic parsing through the matches etc. |
Beta Was this translation helpful? Give feedback.
-
Not sure what you are doing wrong. Here's a zip with driver, grammar, etc., for C#.
|
Beta Was this translation helpful? Give feedback.
-
Referencing in particular the CSharp
REAL_LITERAL
lexicon, perhaps others have modeled similarly:Mainly am interested in a subset portion of the definition:
However, what is the significance of the
'_'
in the definition, I am unfamiliar with that syntax.As if to say, could be something like this?
0___0
, really? After a bit more digging, yes, truly, I guess so; if I am keeping with that definition.No harm if my particular use cases do not need it? Otherwise, the lexicon seems pretty solid. Better than what I was tinkering with, fewer alternatives that can trip up and foul things up:
Thoughts, suggestions? Other than of course to pare back the CSharp description a bit and just run with it.
Beta Was this translation helpful? Give feedback.
All reactions