diff --git a/internal/formatter/testdata/scientific_notation.scad b/internal/formatter/testdata/scientific_notation.scad new file mode 100644 index 0000000..b2c151f --- /dev/null +++ b/internal/formatter/testdata/scientific_notation.scad @@ -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; diff --git a/internal/formatter/testdata/scientific_notation.scad.expected b/internal/formatter/testdata/scientific_notation.scad.expected new file mode 100644 index 0000000..2146f6f --- /dev/null +++ b/internal/formatter/testdata/scientific_notation.scad.expected @@ -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; diff --git a/internal/parser/OpenSCAD.g4 b/internal/parser/OpenSCAD.g4 index e74cf2f..8e9aacd 100644 --- a/internal/parser/OpenSCAD.g4 +++ b/internal/parser/OpenSCAD.g4 @@ -543,10 +543,10 @@ NUMBER ) ; -FLOAT -: - DIGIT* '.' DIGIT+ -; +FLOAT: + DIGIT+ FLOAT_EXPONENT? + | DIGIT* '.' DIGIT+ FLOAT_EXPONENT? + | DIGIT+ '.' DIGIT* FLOAT_EXPONENT?; INTEGER : @@ -622,8 +622,13 @@ fragment EOL | '\n' ; -fragment -STRING_CHAR + +fragment FLOAT_EXPONENT +: + [eE] [+-]? DIGIT+ +; + +fragment STRING_CHAR : ~["\\] | ESCAPE_SEQUENCE @@ -690,6 +695,3 @@ HEX_DIGIT : [0-9a-fA-F] ; - - -