pnathan / pp-toml

Paul's Parser for Tom's Own Minimal Language
https://github.com/mojombo/toml
Other
19 stars 3 forks source link

Add scientific notation for floats & allow optional + prefix on integers. #13

Open pnathan opened 9 years ago

pnathan commented 9 years ago
+A float consists of an integer part (which may be prefixed with a plus or minus
+sign) followed by a fractional part and/or an exponent part. If both a
+fractional part and exponent part are present, the fractional part must precede
+the exponent part.

+A fractional part is a decimal point followed by one or more digits.
+
+An exponent part is an E (upper or lower case) followed by an integer part
+(which may be prefixed with a plus or minus sign).
+
+64-bit (double) precision expected.

---
+# fractional
++1.0
 3.1415
 -0.01
+
+# exponent
+5e+22
+1e6
+-2E-2
+
+# both
6.626e-34
pnathan commented 3 years ago

Floats should be implemented as IEEE 754 binary64 values.

A float consists of an integer part (which follows the same rules as decimal integer values) followed by a fractional part and/or an exponent part. If both a fractional part and exponent part are present, the fractional part must precede the exponent part.

fractional

flt1 = +1.0 flt2 = 3.1415 flt3 = -0.01

exponent

flt4 = 5e+22 flt5 = 1e06 flt6 = -2E-2

both

flt7 = 6.626e-34 A fractional part is a decimal point followed by one or more digits.

An exponent part is an E (upper or lower case) followed by an integer part (which follows the same rules as decimal integer values but may include leading zeros).

The decimal point, if used, must be surrounded by at least one digit on each side.

INVALID FLOATS

invalid_float_1 = .7 invalid_float_2 = 7. invalid_float_3 = 3.e+20 Similar to integers, you may use underscores to enhance readability. Each underscore must be surrounded by at least one digit.

flt8 = 224_617.445_991_228 Float values -0.0 and +0.0 are valid and should map according to IEEE 754.

Special float values can also be expressed. They are always lowercase.

infinity

sf1 = inf # positive infinity sf2 = +inf # positive infinity sf3 = -inf # negative infinity

not a number

sf4 = nan # actual sNaN/qNaN encoding is implementation-specific sf5 = +nan # same as nan sf6 = -nan # valid, actual encoding is implementation-specific