-
-
Save jtbandes/14045fcd6152e8160cd5dd7612025ada to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Valid decimal | |
10 | |
-1000 | |
-1_000 | |
42_42_42 | |
0755 | |
0123456789 | |
0.0 | |
-42.0123456789 | |
1_000.234_567_89 | |
1e2 | |
4.567e5 | |
-2E-4 | |
1e+0 | |
// Valid hex | |
0x10 | |
0x7FFFFFFF | |
0xBadFace | |
0x0123_4567_89ab_cdef | |
0x1p0 | |
0x1p-2 | |
0xFEEDp+3 | |
0x1234.5P4 | |
0x123.45P8 | |
0x12.345P12 | |
0x1.2345P16 | |
0x0.12345P20 | |
// Valid octal | |
0o10 | |
0o755 | |
-0o0123_4567 | |
// Valid binary | |
-0b101010 | |
0b111_101_101 | |
0b1011_1010_1101 | |
// Invalid number-like strings | |
.1 | |
2. | |
1.2. | |
1.2.3 | |
0.1a | |
5e | |
0x1p | |
0x1p_2 | |
0x1.2f | |
0x1.5pa | |
0x1.5w | |
0x1.1p+1f | |
0x1pz | |
-.5 | |
.2f | |
12f | |
42z | |
0b | |
0b_0_1 | |
0b23 | |
0b1.2010 | |
0b12.5 | |
0b101.012 | |
0b101.4 | |
0x_1p+3q | |
0x0.1p | |
0x | |
0xG | |
0x_ | |
0o | |
0o1.2 | |
0a | |
0o8 | |
// Invalid expressions involving numbers | |
1 .2 | |
1*.2 | |
tuple.0x1 | |
// Weird-looking but potentially valid expressions involving numbers | |
_012 | |
1._2 | |
tuple.1 | |
tuple.42 | |
1.property | |
1.5.property | |
0x1.f | |
1+2 | |
0x1p2+0x1p3 | |
29.-.42 | |
29.-.0x42 | |
29.&.0b1 | |
29.^.0o7 | |
0x1...0x10 | |
1..<5 | |
1..5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ name = 'constant.numeric.float.decimal.swift'; | |
comment = '0.1, -4_2.5, 6.022e23, 10E-5'; | |
match = '(\B\-|\b)(?<![^.]\.)[0-9][0-9_]*(?:\.[0-9][0-9_]*)?(?:[eE][+\-]?[0-9][0-9_]*)?\b(?!\.[0-9])'; | |
}, | |
{ name = 'constant.numeric.float.hexadecimal.swift'; | |
comment = '-0x1.ap2_3, 0x31p-4'; | |
match = '(\B\-|\b)(?<![^.]\.)(0x\h[\h_]*)(?:\.\h[\h_]*)?[pP][+\-]?[0-9][0-9_]*\b(?!\.[0-9])'; | |
}, | |
{ name = 'invalid.illegal.numeric.float.invalid-exponent.swift'; | |
comment = '0x1p, 0x1p_2, 0x1.5pa, 0x1.1p+1f, 0x1pz'; | |
match = '(\B\-|\b)(?<![^.]\.)(0x\h[\h_]*)(?:\.\h[\h_]*)?(?:[pP][+\-]?\w*)\b(?!\.[0-9])'; | |
}, | |
{ name = 'invalid.illegal.numeric.float.missing-exponent.swift'; | |
comment = '0x1.5w (note that 0x1.f may be a valid expression)'; | |
match = '(\B\-|\b)(?<![^.]\.)(0x\h[\h_]*)\.[0-9][\w.]*'; | |
}, | |
{ name = 'invalid.illegal.numeric.float.missing-leading-zero.swift'; | |
comment = '-.5, .2f (note that 1.-.5 may be a valid expression)'; | |
match = '(?<=\s|^)\-?\.[0-9][\w.]*'; | |
}, | |
{ name = 'invalid.illegal.numeric.leading-underscore.swift'; | |
comment = '0b_0_1, 0x_1p+3q'; | |
match = '(\B\-|\b)0[box]_[\h_]*(?:[pPeE][+-]?\w+)?[\w.]+'; | |
}, | |
{ comment = 'tuple positional member: not really a numeric literal, but not invalid'; | |
match = '(?<=[^.]\.)[0-9][0-9_]*\b'; | |
}, | |
{ name = 'constant.numeric.integer.binary.swift'; | |
comment = '0b010, 0b1_0'; | |
match = '(\B\-|\b)(?<![^.]\.)0b[01][01_]*\b(?!\.[0-9])'; | |
}, | |
{ name = 'constant.numeric.integer.octal.swift'; | |
comment = '0o1, 0o7_3'; | |
match = '(\B\-|\b)(?<![^.]\.)0o[0-7][0-7_]*\b(?!\.[0-9])'; | |
}, | |
{ name = 'constant.numeric.integer.decimal.swift'; | |
comment = '02, 3_456'; | |
match = '(\B\-|\b)(?<![^.]\.)[0-9][0-9_]*\b(?!\.[0-9])'; | |
}, | |
{ name = 'constant.numeric.integer.hexadecimal.swift'; | |
comment = '0x4, 0xF_7'; | |
match = '(\B\-|\b)(?<![^.]\.)0x\h[\h_]*\b(?!\.[0-9])'; | |
}, | |
{ name = 'invalid.illegal.numeric.other.swift'; | |
match = '(\B\-|\b)[0-9][\w.]*'; | |
}, |
Author
jtbandes
commented
Aug 29, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment