Skip to content

Commit 7508416

Browse files
committed
Octal numerals
1 parent 5f4fbb1 commit 7508416

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

docs/New Features/Numeral Parsing.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ Pluto makes two small changes to numeral parsing.
66
## Cosmetic Underscores
77

88
You can add underscores to your numeric literals to make them more readable.
9-
```pluto showLineNumbers title="Example Code"
9+
```pluto
1010
local n = 10_000_000
11-
assert(n == 10000000)
11+
print(n) --> 10000000
1212
```
1313
These underscores are ignored by the compiler, so they are purely cosmetic.
1414

15-
## Binary Integers
15+
## Binary & Octal Numerals
1616

1717
Similar to how Lua allows you to input numbers in hexadecimal:
18-
```pluto showLineNumbers title="Example Code"
19-
local n = 0x420
20-
assert(n == 1056)
18+
```pluto
19+
local n = 0x2A
20+
print(n) --> 42
2121
```
22-
Pluto allows you to input numbers in binary as well:
23-
```pluto showLineNumbers title="Example Code"
24-
local n = 0b1000101
25-
assert(n == 69)
22+
Pluto allows you to input numbers in binary and octal as well:
23+
```pluto
24+
local n = 0b101010
25+
print(n) --> 42
26+
```
27+
```pluto
28+
local n = 0o52
29+
print(n) --> 42
2630
```

src/theme/Pluto.tmLanguage.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@
580580
"match": "0[bB][01][01_]*",
581581
"name": "constant.numeric.integer.binary.pluto"
582582
},
583+
{
584+
"match": "0[oO][0-7][0-7_]*",
585+
"name": "constant.numeric.integer.octal.pluto"
586+
},
583587
{
584588
"match": "(?<![\\w\\d])\\d[0-9_]*(?![pPeE.0-9])",
585589
"name": "constant.numeric.integer.pluto"

0 commit comments

Comments
 (0)