diff --git a/common/reflection.ys b/common/reflection.ys index 0edd948da..0d7efa614 100644 --- a/common/reflection.ys +++ b/common/reflection.ys @@ -23,6 +23,7 @@ classes: - java.lang.String - java.lang.System - java.lang.Thread +- java.math.BigInteger --- !YS-v0: diff --git a/core/src/yamlscript/ast.clj b/core/src/yamlscript/ast.clj index bd5bbad24..5b4218856 100644 --- a/core/src/yamlscript/ast.clj +++ b/core/src/yamlscript/ast.clj @@ -43,14 +43,7 @@ (defn Chr [s] {:Chr (symbol s)}) -(defn Int [s] - {:Int (cond - (re-find #"^0x" s) - (Long/parseLong (subs s 2) 16) - (re-find #"^0o" s) - (Long/parseLong (subs s 2) 8) - :else - (parse-long s))}) +(defn Int [s] {:Int (bigint s)}) (defn Flt [s] {:Flt (parse-double s)}) diff --git a/core/src/yamlscript/re.clj b/core/src/yamlscript/re.clj index 2c6986f53..583717421 100644 --- a/core/src/yamlscript/re.clj +++ b/core/src/yamlscript/re.clj @@ -68,15 +68,8 @@ (def fnum (re #"(?:$inum\.\d+(?:e$inum)?)")) ; Floating point literal token (def xnum (re #"(?:$fnum|$inum)")) ; Numeric literal token ; Maybe Number token -(def mnum (re #"(?x) - (?: $xnum - (?:[-+/*%_] \d* | - \.\d+ | - \.\w+ [\?\!]? (?=[^\(\w\?\!] | $) - )* - ) - ")) - +(def mnum (re #"(?:$xnum[/0-9A-Za-z\.]*)")); *anything* that starts with a number, could be a number + ; We check later with `yamlscript.ysreader/is-bad-number?` (def xsym #"(?:[=!]~~?)") ; Special operator token ;; Operator symbol token diff --git a/core/src/yamlscript/runtime.clj b/core/src/yamlscript/runtime.clj index ec497b0b1..cc4e1cf97 100644 --- a/core/src/yamlscript/runtime.clj +++ b/core/src/yamlscript/runtime.clj @@ -260,7 +260,7 @@ [sci/file file ARGS (vec (map #(cond - (re-matches re/inum %1) (parse-long %1) + (re-matches re/inum %1) (bigint %1) (re-matches re/fnum %1) (parse-double %1) (re-matches re/keyw %1) (keyword (subs %1 1)) :else %1) diff --git a/core/src/yamlscript/ysreader.clj b/core/src/yamlscript/ysreader.clj index a631978c4..58a4bc15c 100644 --- a/core/src/yamlscript/ysreader.clj +++ b/core/src/yamlscript/ysreader.clj @@ -302,7 +302,7 @@ (let [[[key val]] (seq %1) val (str val)] (if (and (= :Sym key) (re-matches #"_\d+" val)) - (let [n (parse-long (subs val 1))] + (let [n (bigint (subs val 1))] (swap! args assoc n true) (swap! maxn max n)) %1)) @@ -398,7 +398,7 @@ (= "true" token) [(Bln token) tokens] (= "false" token) [(Bln token) tokens] (is-narg? token) (let [n (subs token 1) - n (parse-long n) + n (bigint n) _ (when (or (<= n 0) (> n 20)) (die "Invalid numbered argument: " token)) n (str "_" n)] diff --git a/core/src/ys/std.clj b/core/src/ys/std.clj index 6db508a88..e1fdf1e9c 100644 --- a/core/src/ys/std.clj +++ b/core/src/ys/std.clj @@ -619,7 +619,7 @@ number? x string? (if (re-find #"\." x) (parse-double x) - (parse-long x)) + (bigint x)) nil? (util/die "Can't convert a nil value to a number") seqable? (count x) char? (int x) diff --git a/core/test/compiler-stack.yaml b/core/test/compiler-stack.yaml index efe64bde6..7a0c7924c 100644 --- a/core/test/compiler-stack.yaml +++ b/core/test/compiler-stack.yaml @@ -1553,10 +1553,16 @@ clojure: | -- name: Octal and hex literals not loading correctly +- name: Octal literals aren't supported yamlscript: | !YS-v0: - 0o12 + error: | + Invalid number: 0x12 + +- name: Hex literals aren't supported + yamlscript: | + !YS-v0: - 0x12 - build: | - {:Vec [{:Int 10} {:Int 18}]} + error: | + Invalid number: 0x12 diff --git a/core/test/resolver.yaml b/core/test/resolver.yaml index 23725dbda..faf2b2456 100644 --- a/core/test/resolver.yaml +++ b/core/test/resolver.yaml @@ -12,7 +12,7 @@ - > folded block scalar - - [41, -42, +43, +0, -0, 0o1337, 0xcafebabe] + - [41, -42, +43, +0, -0] - [.1, -.2, +.3, 4.00, -5.99] - [.1e-00, -.2e+3, +.3e11, 4.00E-4, -5.99E99] - [true, True, TRUE] @@ -35,9 +35,7 @@ {:int "-42"} {:int "+43"} {:int "+0"} - {:int "-0"} - {:int "0o1337"} - {:int "0xcafebabe"}]} + {:int "-0"}]} {:seq [{:flt ".1"} {:flt "-.2"} diff --git a/yamltest/src/yamltest/core.clj b/yamltest/src/yamltest/core.clj index d19e777bf..340b2fcd2 100644 --- a/yamltest/src/yamltest/core.clj +++ b/yamltest/src/yamltest/core.clj @@ -46,7 +46,7 @@ (let [kw (keyword (subs kw 1))] (when (contains? short-keys kw) kw)) (when (re-matches #"\d+" opt) - (parse-long opt)))) + (bigint opt)))) opts)) (repeat true))))) diff --git a/ys/share/ys-0.bash b/ys/share/ys-0.bash index ffe2fe525..2ce0bcb5b 100755 --- a/ys/share/ys-0.bash +++ b/ys/share/ys-0.bash @@ -156,7 +156,7 @@ $program (let [argv (vec (map #(if (re-matches #"\d+" %) - (parse-long %) %) + (bigint %) %) args))] (apply main argv))) EOF