Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No highlighting for radix numbers #21

Open
MrEbbinghaus opened this issue Nov 10, 2021 · 1 comment
Open

No highlighting for radix numbers #21

MrEbbinghaus opened this issue Nov 10, 2021 · 1 comment

Comments

@MrEbbinghaus
Copy link

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
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant