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

number parser returns 13 for "015" #1

Open
kjw opened this issue May 4, 2012 · 4 comments
Open

number parser returns 13 for "015" #1

kjw opened this issue May 4, 2012 · 4 comments

Comments

@kjw
Copy link

kjw commented May 4, 2012

Due to the use of clojure's reader in zetta.parser.seq/number.

Clojure's reader interprets a sequence of digits with leading 0s as base 8, e.g. (parse-number "010") => 8 , (parse-number "08") => nil and (parse-number "07") => 7.

@ujihisa
Copy link
Member

ujihisa commented May 10, 2012

src/zetta/parser/seq.clj

307 (let [m (.getDeclaredMethod clojure.lang.LispReader
308                             "matchNumber"
309                             (into-array [String]))]
310   (.setAccessible m true)
311   (defn- read-number [s]
312     (.invoke m clojure.lang.LispReader (into-array [s]))))

Roman: instead of using LispReader as kjw pointed out, how about using Java's BigInteger constructor, and convert it to appropriate Clojure data type?

(defn- read-number [x]
  (let [big-int (BigInteger. x)]
    (if (< big-int Long/MAX_VALUE)
      (long big-int)
      (bigint big-int))))

@ujihisa
Copy link
Member

ujihisa commented May 10, 2012

and also we should provide the previous zetta.parser.seq/number as another name, like zetta.parser.seq/number-clojure

@ujihisa
Copy link
Member

ujihisa commented May 10, 2012

note that Roman, the author of zetta-parser, is busy in May so let's just wait until the end of month :)

@kjw
Copy link
Author

kjw commented May 10, 2012

Problem with using BigInteger. is it doesn't read rationals. Would be nice to keep that functionality (though there's probably a case for having separate integer and number parsers).

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

2 participants