Skip to content

No highlighting for radix numbers #21

Open

Description

@MrEbbinghaus

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)?")

Activity

  1. MrEbbinghaus commented on Nov 10, 2021

    @MrEbbinghaus
    Author

    I looked at the regex.
    There are more issues:

    • 0b101010 is not a valid Clojure number. You would write: 2r101010.
    • Similar, octals are not written with 0o prefix.
      • It should be just a 0 or, more explicit, 8r (052 8r52)
      • And they can begin with + or -
    • The x and the r for hexadecimal numbers and radix numbers are case-insensitive.
     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]+
      }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions