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

Fix matching of numbers #90

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions grammars/clojure.cson
Original file line number Diff line number Diff line change
Expand Up @@ -105,35 +105,33 @@
'name': 'constant.language.boolean.clojure'
}
{
'match': '(-?\\d+/\\d+)'
'match': '(##(?:Inf|-Inf|NaN))'
'name': 'constant.numeric.symbol.clojure'
}
{
'match': '([-+]?\\d+/\\d+)'
'name': 'constant.numeric.ratio.clojure'
}
{
'match': '(-?\\d+[rR]\\w+)'
# Only Radixes between 2 and 36 are allowed
'match': '([-+]?(?:(?:3[0-6])|(?:[12]\\d)|[2-9])[rR][0-9A-Za-z]+N?)'
'name': 'constant.numeric.arbitrary-radix.clojure'
}
{
'match': '(-?0[xX][0-9a-fA-F]+)'
'match': '([-+]?0[xX][0-9a-fA-F]+N?)'
'name': 'constant.numeric.hexadecimal.clojure'
}
{
'match': '(-?0\\d+)'
'match': '([-+]?0[0-7]+N?)'
'name': 'constant.numeric.octal.clojure'
}
{
'match': '(-?\\d+\\.\\d+([eE][+-]?\\d+)?M)'
'name': 'constant.numeric.bigdecimal.clojure'
}
{
'match': '(-?\\d+\\.\\d+([eE][+-]?\\d+)?)'
# The decimal separator is optional only when followed by e, E or M!
'match': '([-+]?[0-9]+(?:(\\.|(?=[eEM]))[0-9]*([eE][-+]?[0-9]+)?)M?)'
'name': 'constant.numeric.double.clojure'
}
{
'match': '(-?\\d+N)'
'name': 'constant.numeric.bigint.clojure'
}
{
'match': '(-?\\d+)'
'match': '([-+]?\\d+N?)'
'name': 'constant.numeric.long.clojure'
}
{ # separating the pattern for reuse
Expand Down
15 changes: 7 additions & 8 deletions spec/clojure-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ describe "Clojure grammar", ->

it "tokenizes numerics", ->
numbers =
"constant.numeric.ratio.clojure": ["1/2", "123/456"]
"constant.numeric.arbitrary-radix.clojure": ["2R1011", "16rDEADBEEF", "56råäöÅÄÖπ"]
"constant.numeric.hexadecimal.clojure": ["0xDEADBEEF", "0XDEADBEEF"]
"constant.numeric.octal.clojure": ["0123"]
"constant.numeric.bigdecimal.clojure": ["123.456M"]
"constant.numeric.double.clojure": ["123.45", "123.45e6", "123.45E6"]
"constant.numeric.bigint.clojure": ["123N"]
"constant.numeric.long.clojure": ["123", "12321"]
"constant.numeric.ratio.clojure": ["1/2", "123/456", "+0/2", "-23/1"]
"constant.numeric.arbitrary-radix.clojure": ["2R1011", "16rDEADBEEF", "16rDEADBEEFN", "36rZebra"]
"constant.numeric.hexadecimal.clojure": ["0xDEADBEEF", "0XDEADBEEF", "0xDEADBEEFN", "0x0"]
"constant.numeric.octal.clojure": ["0123", "0123N", "00"]
"constant.numeric.double.clojure": ["123.45", "123.45e6", "123.45E6", "123.456M", "42.", "42.M", "42E+9M", "42E-0", "0M", "+0M", "42.E-23M"]
"constant.numeric.long.clojure": ["123", "12321", "123N", "+123N", "-123", "0"]
"constant.numeric.symbol.clojure": ["##Inf", "##-Inf", "##NaN"]

for scope, nums of numbers
for num in nums
Expand Down