Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #35 from abusalimov/num-literals
Browse files Browse the repository at this point in the history
numbers: Fix decimal floats
  • Loading branch information
abusalimov committed Feb 2, 2016
2 parents 67a50e0 + 513399f commit cc1172c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
12 changes: 3 additions & 9 deletions C Improved.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1400,10 +1400,10 @@
(?!0x)
# significand
(?: (?: [0-9]++ ([0-9a-z&&[^e]]*?) [0-9]+* )?
\. [0-9]++ ([0-9a-z.&&[^e]]*?) [0-9]+*
(?: (?: [0-9]++ ([0-9a-z&&[^e]]*?) [0-9]*+ )?
\. [0-9]++ ([0-9a-z.&&[^e]]*?) [0-9]*+
| [0-9]++ ([0-9a-z&&[^e]]*?) [0-9]+* (?: \. | (?=e)) )
| [0-9]++ ([0-9a-z&&[^e]]*?) [0-9]*+ (?: \. | (?=e)) )
# exponent (optional)
(?: (e) (?: [+\-] [0-9]++ ([0-9a-z]*?)
Expand Down Expand Up @@ -1454,12 +1454,6 @@
\b (?!\.)
</string>
<key>name</key> <string>invalid.illegal.invalid-number-literal.c</string>
<key>captures</key>
<dict>
<key>1</key> <dict> <key>name</key> <string>storage.type.number.prefix.hexadecimal.c</string> </dict>
<key>2</key> <dict> <key>name</key> <string>storage.type.number.prefix.binary.c</string> </dict>
<key>3</key> <dict> <key>name</key> <string>storage.type.number.suffix.c</string> </dict>
</dict>
</dict>
<dict>
<key>match</key> <string>(?ix)
Expand Down
57 changes: 40 additions & 17 deletions tests/test_numbers.c
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
/**
* Test numeric literals: both integers and floats.
*/

int main(int argc, char const *argv[])
{
GOOD = {
/* zeroes */
0,
0.0l,
.0,
0.f,
0UL,
0x0ull,
7e5,

/* decimal integers */
42,
-123,

/* GNU C binary literals */
0b100110,
0b100110ul,

/* hexadecimal integers */
0xFF,
0xcf400000ul,
0xFull,
0xC0FFEE,
0xdeadbeef,

/* octal integers */
0777,
0123l, // long

089e3l, // but: decimal float

/* decimal floats */
3.1415926,
.015625,
7e5, // 7.0 * 10^5
7.3,
7.3E+5,
7.E+5,
.3E+5f,
7.3+5,
7.3+E,
0x73e5f,
0x7.3p5f,
0x7.3p-5f,
0x7p5f,
029e3l,
7.3e5l, // long double

2,
256,
0.015625,
0.857421875,
0x1p-1074,
3.1415926,
0.1,
0x3.334p-5,
0xcc.cdp-11,
7.3+E, // a sum, i.e. 7.3 + E
7.3+5, // also a sum

/* hexadecimal floats */
0x7.0p5, // 7.0 * 2^5
0xcf7p5,
0xcc.dp-11,
0x13p-10,
};

BAD = {
Expand Down

0 comments on commit cc1172c

Please sign in to comment.