Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 45bdb88

Browse files
committed
Fix up expressions for numbers
1 parent a2d53e8 commit 45bdb88

2 files changed

Lines changed: 18 additions & 21 deletions

File tree

grammars/clojure.cson

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,36 +104,34 @@
104104
'match': '(true|false)'
105105
'name': 'constant.language.boolean.clojure'
106106
}
107+
{
108+
'match': '(##(?:Inf|-Inf|NaN))'
109+
'name': 'constant.numeric.symbol.clojure'
110+
}
107111
{
108112
'match': '([-+]?\\d+/\\d+)'
109113
'name': 'constant.numeric.ratio.clojure'
110114
}
111115
{
112-
'match': '([-+]?\\d+[rR]\\w+)'
116+
# Only Radixes between 2 and 36 are allowed
117+
'match': '([-+]?(?:(?:3[0-6])|(?:[12]\\d)|[2-9])[rR][0-9A-Za-z]+N?)'
113118
'name': 'constant.numeric.arbitrary-radix.clojure'
114119
}
115120
{
116-
'match': '([-+]?0[xX][0-9a-fA-F]+)'
121+
'match': '([-+]?0[xX][0-9a-fA-F]+N?)'
117122
'name': 'constant.numeric.hexadecimal.clojure'
118123
}
119124
{
120-
'match': '([-+]?0\\d+)'
125+
'match': '([-+]?0[0-7]+N?)'
121126
'name': 'constant.numeric.octal.clojure'
122127
}
123128
{
124-
'match': '([-+]?\\d+\\.\\d+([eE][+-]?\\d+)?M)'
125-
'name': 'constant.numeric.bigdecimal.clojure'
126-
}
127-
{
128-
'match': '([-+]?\\d+\\.\\d+([eE][+-]?\\d+)?)'
129+
# The decimal separator is optional only when followed by e, E or M!
130+
'match': '([-+]?[0-9]+(?:(\\.|(?=[eEM]))[0-9]*([eE][-+]?[0-9]+)?)M?)'
129131
'name': 'constant.numeric.double.clojure'
130132
}
131133
{
132-
'match': '([-+]?\\d+N)'
133-
'name': 'constant.numeric.bigint.clojure'
134-
}
135-
{
136-
'match': '([-+]?\\d+)'
134+
'match': '([-+]?\\d+N?)'
137135
'name': 'constant.numeric.long.clojure'
138136
}
139137
{ # separating the pattern for reuse

spec/clojure-spec.coffee

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ describe "Clojure grammar", ->
6262
6363
it "tokenizes numerics", ->
6464
numbers =
65-
"constant.numeric.ratio.clojure": ["1/2", "123/456"]
66-
"constant.numeric.arbitrary-radix.clojure": ["2R1011", "16rDEADBEEF", "56råäöÅÄÖπ"]
67-
"constant.numeric.hexadecimal.clojure": ["0xDEADBEEF", "0XDEADBEEF"]
68-
"constant.numeric.octal.clojure": ["0123"]
69-
"constant.numeric.bigdecimal.clojure": ["123.456M"]
70-
"constant.numeric.double.clojure": ["123.45", "123.45e6", "123.45E6"]
71-
"constant.numeric.bigint.clojure": ["123N"]
72-
"constant.numeric.long.clojure": ["123", "12321"]
65+
"constant.numeric.ratio.clojure": ["1/2", "123/456", "+0/2", "-23/1"]
66+
"constant.numeric.arbitrary-radix.clojure": ["2R1011", "16rDEADBEEF", "16rDEADBEEFN", "36rZebra"]
67+
"constant.numeric.hexadecimal.clojure": ["0xDEADBEEF", "0XDEADBEEF", "0xDEADBEEFN", "0x0"]
68+
"constant.numeric.octal.clojure": ["0123", "0123N", "00"]
69+
"constant.numeric.double.clojure": ["123.45", "123.45e6", "123.45E6", "123.456M", "42.", "42.M", "42E+9M", "42E-0", "0M", "+0M", "42.E-23M"]
70+
"constant.numeric.long.clojure": ["123", "12321", "123N", "+123N", "-123", "0"]
71+
"constant.numeric.symbol.clojure": ["##Inf", "##-Inf", "##NaN"]
7372
7473
for scope, nums of numbers
7574
for num in nums

0 commit comments

Comments
 (0)