]> Repositorios git - scryer-prolog.git/commitdiff
Now preserving distinction between ints and floats
authorpanasenco <[email protected]>
Wed, 21 Apr 2021 02:59:01 +0000 (19:59 -0700)
committerpanasenco <[email protected]>
Wed, 21 Apr 2021 02:59:01 +0000 (19:59 -0700)
src/lib/json.pl
src/tests/json/pass_everything.min.json
src/tests/json/test_json.pl

index 218152e2c915193d5e03776df05310762876fa15..7b8338177b11ffbaeb625357d6d92ba15c79f681 100644 (file)
@@ -226,7 +226,11 @@ json_number(Number) -->
     json_integer(Integer),
     json_fraction(Fraction),
     json_exponent(Exponent),
-    { Number is Sign * (Integer + Fraction) * 10.0 ^ Exponent }.
+    { (   Exponent >= 0 ->
+          Base = 10
+      ;   Base = 10.0
+      ),
+      Number is Sign * (Integer + Fraction) * Base ^ Exponent }.
 
 json_integer(Digit)      --> json_digit(Digit).
 json_integer(TotalValue) -->
index 85cf7acb5150b48a2a5d0031d8170841a75dffd6..35137af4a7de41cadd70c9523868a76075340573 100644 (file)
@@ -1 +1 @@
-["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42.0,true,false,null,{"":23456789011999997000000000000000000000000000000000000000000000000000000000000.0," s p a c e d ":[1.0,2.0,3.0,4.0,5.0,6.0,7.0],"# -- --> *\/":" ","\/\\\"쫾몾ꮘﳞ볚\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","E":12345678900000000000000000000000000.0,"address":"50 St. James Street","alpha":"abcdefghijklmnopqrstuvwyz","array":[],"backslash":"\\","comment":"\/\/ \/* <!-- --","compact":[1.0,2.0,3.0,4.0,5.0,6.0,7.0],"controls":"\b\f\n\r\t","digit":"0123456789","e":0.000000000000123456789,"false":false,"hex":"ģ䕧覫\u0001췯ꯍ\u001a","integer":1234567890.0,"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","null":null,"object":{},"one":1.0,"quote":"\"","quotes":"&#34; \" %22 0x22 034 &#x22;","real":-9876.54321,"slash":"\/ & \/","space":" ","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","true":true,"url":"http:\/\/www.JSON.org\/","zero":0.0},0.5,98.6,99.44,1066.0,"rosebud"]
\ No newline at end of file
+["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"":23456789012000000000000000000000000000000000000000000000000000000000000000000," s p a c e d ":[1,2,3,4,5,6,7],"# -- --> *\/":" ","\/\\\"쫾몾ꮘﳞ볚\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","E":12345678900000000000000000000000000.0,"address":"50 St. James Street","alpha":"abcdefghijklmnopqrstuvwyz","array":[],"backslash":"\\","comment":"\/\/ \/* <!-- --","compact":[1,2,3,4,5,6,7],"controls":"\b\f\n\r\t","digit":"0123456789","e":0.000000000000123456789,"false":false,"hex":"ģ䕧覫\u0001췯ꯍ\u001a","integer":1234567890,"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","null":null,"object":{},"one":1,"quote":"\"","quotes":"&#34; \" %22 0x22 034 &#x22;","real":-9876.54321,"slash":"\/ & \/","space":" ","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","true":true,"url":"http:\/\/www.JSON.org\/","zero":0},0.5,98.6,99.44,1066,"rosebud"]
\ No newline at end of file
index c0c931f9a327950b8272753a3a3d62ce7d8deb3a..85bf4774b81c0532b7bfde411ade0b94324efa35 100644 (file)
@@ -1,4 +1,4 @@
-:- module(test_json, [test_json_read/0, test_json_minify/0]).
+:- module(test_json, [test_json/0]).
 
 :- use_module(library(charsio)).
 :- use_module(library(dcgs)).
@@ -36,3 +36,20 @@ test_json_minify :-
     name_parse("pass_everything.json", Json),
     time(once(phrase(json_chars(Json), MinChars))),
     RefChars = MinChars.
+
+test_json_int_float :-
+    once(phrase(json_chars(number(ZeroInt)), "0")),
+    integer(ZeroInt),
+    once(phrase(json_chars(number(ZeroFloat)), "0.0")),
+    \+ integer(ZeroFloat),
+    once(phrase(json_chars(number(BigInt)), "32E5")),
+    integer(BigInt),
+    once(phrase(json_chars(number(BigFloat)), "32.2E5")),
+    \+ integer(BigFloat),
+    once(phrase(json_chars(number(SmallFloat)), "32E-5")),
+    \+ integer(SmallFloat).
+
+test_json :-
+    test_json_read,
+    test_json_minify,
+    test_json_int_float.