]> Repositorios git - scryer-prolog.git/commitdiff
Oops, we want to keep digits as characters in library(abnf), but as numbers in librar...
authorpanasenco <[email protected]>
Thu, 29 Apr 2021 05:58:04 +0000 (22:58 -0700)
committerpanasenco <[email protected]>
Thu, 29 Apr 2021 06:05:02 +0000 (23:05 -0700)
src/lib/serialization/abnf.pl
src/lib/serialization/json.pl
src/tests/json/pass_everything.min.json

index 40e5d9f67c16846194fe87c3f5294db20858af60..bf71ab9c424751cec4c9b9e3efe3d9ba6428ae9d 100644 (file)
@@ -116,37 +116,37 @@ abnf_alpha('X') --> "X".
 abnf_alpha('Y') --> "Y".
 abnf_alpha('Z') --> "Z".
 
-abnf_bit(0) --> "0".
-abnf_bit(1) --> "1".
+abnf_bit('0') --> "0".
+abnf_bit('1') --> "1".
 
-abnf_char(C) --> [C], { dif(C, '\x0000\'), char_type(C, ascii) }. %'
+abnf_char(Char) --> [Char], { dif(Char, '\x0000\'), char_type(Char, ascii) }. %'
 
 abnf_cr --> "\r".
 
 abnf_crlf --> "\r\n".
 
-abnf_ctl(C) --> [C], { char_type(C, ascii), char_type(C, control) }.
+abnf_ctl(Char) --> [Char], { char_type(Char, ascii), char_type(Char, control) }.
 
-abnf_digit(0) --> "0".
-abnf_digit(1) --> "1".
-abnf_digit(2) --> "2".
-abnf_digit(3) --> "3".
-abnf_digit(4) --> "4".
-abnf_digit(5) --> "5".
-abnf_digit(6) --> "6".
-abnf_digit(7) --> "7".
-abnf_digit(8) --> "8".
-abnf_digit(9) --> "9".
+abnf_digit('0') --> "0".
+abnf_digit('1') --> "1".
+abnf_digit('2') --> "2".
+abnf_digit('3') --> "3".
+abnf_digit('4') --> "4".
+abnf_digit('5') --> "5".
+abnf_digit('6') --> "6".
+abnf_digit('7') --> "7".
+abnf_digit('8') --> "8".
+abnf_digit('9') --> "9".
 
 abnf_dquote --> "\"".
 
-abnf_hexdig(Digit) --> abnf_digit(Digit).
-abnf_hexdig(10) --> "A".
-abnf_hexdig(11) --> "B".
-abnf_hexdig(12) --> "C".
-abnf_hexdig(13) --> "D".
-abnf_hexdig(14) --> "E".
-abnf_hexdig(15) --> "F".
+abnf_hexdig(Char) --> abnf_digit(Char).
+abnf_hexdig('A') --> "A".
+abnf_hexdig('B') --> "B".
+abnf_hexdig('C') --> "C".
+abnf_hexdig('D') --> "D".
+abnf_hexdig('E') --> "E".
+abnf_hexdig('F') --> "F".
 
 abnf_htab --> "\t".
 
@@ -156,11 +156,11 @@ abnf_lwsp --> "".
 abnf_lwsp --> abnf_wsp, abnf_lwsp.
 abnf_lwsp --> abnf_clrf, abnf_wsp, abnf_lwsp.
 
-abnf_octet(C) --> [C], char_type(C, octet).
+abnf_octet(Char) --> [Char], char_type(Char, octet).
 
 abnf_sp --> " ".
 
-abnf_vchar(C) --> [C], char_type(C, ascii_graphic).
+abnf_vchar(Char) --> [Char], char_type(Char, ascii_graphic).
 
 abnf_wsp --> abnf_sp.
 abnf_wsp --> abnf_htab.
index 50672e1f200e35a1ff1cb1cb99bc41589f19bea7..e1bebe114780c6042e45284276d07e0089b114f6 100644 (file)
@@ -1,7 +1,7 @@
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Written Apr 2021 by Aram Panasenco ([email protected])
    Part of Scryer Prolog.
-
+   
    `json_chars//1` can be used with [`phrase_from_file/2`](src/lib/pio.pl)
    or [`phrase/2`](src/lib/dcgs.pl) to parse and generate [JSON](https://www.json.org/json-en.html).
    
@@ -43,7 +43,6 @@
 :- use_module(library(dcgs)).
 :- use_module(library(dif)).
 :- use_module(library(lists)).
-:- use_module(library(serialization/abnf)).
 
 /*  The DCGs are written to match the McKeeman form presented on the right side of https://www.json.org/json-en.html 
     as closely as possible. Note that the names in the McKeeman form conflict with the pictures on the site. */
@@ -165,13 +164,19 @@ json_character(EscapeChar) -->
               H4 is (EscapeCharCode // 16^0) mod 16
           ) }.
 
-json_hex(Hex) --> abnf_hexdig(Hex).
+json_hex(Digit) --> json_digit(Digit).
 json_hex(10)    --> "a".
 json_hex(11)    --> "b".
 json_hex(12)    --> "c".
 json_hex(13)    --> "d".
 json_hex(14)    --> "e".
 json_hex(15)    --> "f".
+json_hex(10)    --> "A".
+json_hex(11)    --> "B".
+json_hex(12)    --> "C".
+json_hex(13)    --> "D".
+json_hex(14)    --> "E".
+json_hex(15)    --> "F".
 
 /*  I can't think of any alternatives to using `number_chars/2` when generating, though this leads
     to under-reporting of correct solutions. At least matching solutions unify when both are instantiated...
@@ -203,20 +208,31 @@ json_number(Number) -->
             NumberChars
         ).
 
-json_integer(Digit)      --> abnf_digit(Digit).
+json_integer(Digit)      --> json_digit(Digit).
 json_integer(TotalValue) -->
         json_onenine(FirstDigit),
         json_digits(RemainingValue, Power),
         { TotalValue is FirstDigit * 10 ^ (Power + 1) + RemainingValue }.
 
-json_digits(Digit, 0)     --> abnf_digit(Digit).
+json_digits(Digit, 0)     --> json_digit(Digit).
 json_digits(Value, Power) -->
-        abnf_digit(FirstDigit),
+        json_digit(FirstDigit),
         json_digits(RemainingValue, NextPower),
         { Power is NextPower + 1,
           Value is FirstDigit * 10^Power + RemainingValue }.
 
-json_onenine(Digit) --> abnf_digit(Digit), { dif(Digit, 0) }.
+json_digit(0)     --> "0".
+json_digit(Digit) --> json_onenine(Digit).
+
+json_onenine(1) --> "1".
+json_onenine(2) --> "2".
+json_onenine(3) --> "3".
+json_onenine(4) --> "4".
+json_onenine(5) --> "5".
+json_onenine(6) --> "6".
+json_onenine(7) --> "7".
+json_onenine(8) --> "8".
+json_onenine(9) --> "9".
 
 json_fraction(0)        --> "".
 json_fraction(Fraction) -->
index 5d5659ea5746fb7556fa78d17d5d73a08aa32067..27f37e6264befcc9dd7b7ca2511d918f19610500 100644 (file)
@@ -1 +1 @@
-["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":0.000000000000123456789,"E":12345678900000000000000000000000000.0,"":23456789012000000000000000000000000000000000000000000000000000000000000000000,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"ģ䕧覫\u0001췯ꯍ\u001A","true":true,"false":false,"null":null,"array":[],"object":{},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* <!-- --","# -- --> *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"&#34; \" %22 0x22 034 &#x22;","\/\\\"쫾몾ꮘﳞ볚\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"]
+["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":0.000000000000123456789,"E":12345678900000000000000000000000000.0,"":23456789012000000000000000000000000000000000000000000000000000000000000000000,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"ģ䕧覫\u0001췯ꯍ\u001a","true":true,"false":false,"null":null,"array":[],"object":{},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* <!-- --","# -- --> *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"&#34; \" %22 0x22 034 &#x22;","\/\\\"쫾몾ꮘﳞ볚\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"]