Skip to content

Commit

Permalink
Fix parsing of floating point constants w/ exponents
Browse files Browse the repository at this point in the history
  • Loading branch information
hugheaves committed Dec 19, 2023
1 parent 93ade7e commit d15d8e0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
16 changes: 16 additions & 0 deletions internal/formatter/testdata/scientific_notation.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Test formatting of floating point numbers
*/
a=8.014786;
b=.014786;
c=8.014786e+00;
d=8.014786E+00;
e=8.014786E-00;
f=8.014786e-00;
g=8.014786E00;
h=8.014786e00;
i=9.9e-126;
j=9.e-126;
k=9e-126;
l=9e-126;
m=-9e-126;
16 changes: 16 additions & 0 deletions internal/formatter/testdata/scientific_notation.scad.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Test formatting of floating point numbers
*/
a = 8.014786;
b = .014786;
c = 8.014786e+00;
d = 8.014786E+00;
e = 8.014786E-00;
f = 8.014786e-00;
g = 8.014786E00;
h = 8.014786e00;
i = 9.9e-126;
j = 9.e-126;
k = 9e-126;
l = 9e-126;
m = -9e-126;
20 changes: 11 additions & 9 deletions internal/parser/OpenSCAD.g4
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,10 @@ NUMBER
)
;

FLOAT
:
DIGIT* '.' DIGIT+
;
FLOAT:
DIGIT+ FLOAT_EXPONENT?
| DIGIT* '.' DIGIT+ FLOAT_EXPONENT?
| DIGIT+ '.' DIGIT* FLOAT_EXPONENT?;

INTEGER
:
Expand Down Expand Up @@ -622,8 +622,13 @@ fragment EOL
| '\n'
;

fragment
STRING_CHAR

fragment FLOAT_EXPONENT
:
[eE] [+-]? DIGIT+
;

fragment STRING_CHAR
:
~["\\]
| ESCAPE_SEQUENCE
Expand Down Expand Up @@ -690,6 +695,3 @@ HEX_DIGIT
:
[0-9a-fA-F]
;



0 comments on commit d15d8e0

Please sign in to comment.