Skip to content

Commit

Permalink
fix: leading zeros are accepted on a big decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
carocad committed Nov 3, 2020
1 parent 718de49 commit 347e897
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Clojure.g4
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@ LONG: SIGN? DECIMAL BIG_INT?;

fragment BIG_INT: 'N';

DOUBLE: SIGN? DECIMAL ('.' DIGIT*)? ([eE]SIGN?DIGIT+)? 'M'?;
// forbids numbers like: 0002341349 (invalid octal) from matching double
DOUBLE: SIGN? DECIMAL+ ('M' | (FRACTION | EXPONENT | (FRACTION EXPONENT)) 'M'?);

fragment DECIMAL: (ZERO | ([1-9] DIGIT*));
fragment FRACTION: ('.' DIGIT*);
fragment EXPONENT: [eE] SIGN? DIGIT+;
fragment DECIMAL: ZERO | ([1-9] DIGIT*);

fragment ZERO: '0';

Expand Down
8 changes: 7 additions & 1 deletion test/parcera/test_cases.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,18 @@
(doseq [input inputs]
(valid? input)
(roundtrip input)))
(let [inputs ["08" "0x1G"]]
(let [inputs ["08" ;; invalid octal
"0x1G" ;; invalid hexadecimal
"0002341349" #_(invalid octal)]]
(doseq [input inputs]
(is (parcera/failure? (parcera/ast input)))))
(let [input "0007000321110000334004002007N"]
(is (= (parcera/ast input) [:code [:number input]])))
(let [input "0x07000321110000334004002007N"]
(is (= (parcera/ast input) [:code [:number input]])))
(let [input "0002341349M"] ;; valid big decimal
(is (= (parcera/ast input) [:code [:number input]])))
(let [input "0002341349.2432"] ;; valid double
(is (= (parcera/ast input) [:code [:number input]]))))


Expand Down

0 comments on commit 347e897

Please sign in to comment.