nextjournal / clojure-mode

Clojure/Script mode for CodeMirror 6
https://nextjournal.github.io/clojure-mode/
Eclipse Public License 2.0
158 stars 19 forks source link

No highlighting for radix numbers #21

Open MrEbbinghaus opened 2 years ago

MrEbbinghaus commented 2 years ago

Clojure allows for numbers with a radix between 2 and 36. Also, the BigInt N suffix is allowed after a hexadecimal number.

From https://clojure.org/reference/reader#_literals:

When possible, they can be specified in any base with radix from 2 to 36 (see Long.parseLong()); for example 2r101010, 052, 8r52, 0x2a, 36r16, and 42 are all the same Long.

image

Here are some regex from [clojure.tools.reader] describing all numbers. (https://github.com/clojure/tools.reader/blob/master/src/main/clojure/clojure/tools/reader/impl/commons.clj#L46-L48)

(def ^Pattern int-pattern #"([-+]?)(?:(0)|([1-9][0-9]*)|0[xX]([0-9A-Fa-f]+)|0([0-7]+)|([1-9][0-9]?)[rR]([0-9A-Za-z]+)|0[0-9]+)(N)?")
(def ^Pattern ratio-pattern #"([-+]?[0-9]+)/([0-9]+)")
(def ^Pattern float-pattern #"([-+]?[0-9]+(\.[0-9]*)?([eE][-+]?[0-9]+)?)(M)?")
MrEbbinghaus commented 2 years ago

I looked at the regex. There are more issues:

 Number {
    ("+" | "-")? (std.digit+ ("." std.digit* "M"?)? | "." std.digit+) (("e" | "E") ("+" | "-")? std.digit+ "M"?)? |
    ("+" | "-")? std.digit+ ("M" | "N") |
    ("+" | "-")? std.digit+ "/" std.digit+ |
    ("+" | "-")? "0x" (std.digit | $[a-fA-F])+ |
    "0b" $[01]+ |
    "0o" $[0-7]+
  }