boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

053-string-escapes.scm (1887B)


      1 ; All five named string escapes plus inline-hex escapes \xNN;.
      2 ;
      3 ; Named escapes (\n \t \r \\ \") each yield one byte:
      4 ;     "x\ny\tz\r\\\""  -> 'x', LF, 'y', TAB, 'z', CR, '\\', '"'  (8 bytes)
      5 (define s "x\ny\tz\r\\\"")
      6 (if (= (bytevector-length s)  8) 0 (sys-exit 1))
      7 (if (= (bytevector-u8-ref s 0) 120) 0 (sys-exit 2))   ; 'x'
      8 (if (= (bytevector-u8-ref s 1)  10) 0 (sys-exit 3))   ; \n
      9 (if (= (bytevector-u8-ref s 2) 121) 0 (sys-exit 4))   ; 'y'
     10 (if (= (bytevector-u8-ref s 3)   9) 0 (sys-exit 5))   ; \t
     11 (if (= (bytevector-u8-ref s 4) 122) 0 (sys-exit 6))   ; 'z'
     12 (if (= (bytevector-u8-ref s 5)  13) 0 (sys-exit 7))   ; \r
     13 (if (= (bytevector-u8-ref s 6)  92) 0 (sys-exit 8))   ; \\
     14 (if (= (bytevector-u8-ref s 7)  34) 0 (sys-exit 9))   ; \"
     15 
     16 ; Inline-hex escape \xHEX;: 1+ hex digits, terminated by ';', value 0..255.
     17 ; "\x41;" -> "A"  (one byte, 0x41).
     18 (define h1 "\x41;")
     19 (if (= (bytevector-length h1) 1) 0 (sys-exit 10))
     20 (if (= (bytevector-u8-ref h1 0) 65) 0 (sys-exit 11))
     21 
     22 ; Mixed: ordinary bytes interleaved with hex escapes; lower/upper-case
     23 ; hex digits; leading-zero short form; max byte 0xFF.
     24 ;     "a\x42;c\xff;\x0;" -> 'a', 'B', 'c', 0xff, 0x00  (5 bytes)
     25 (define h2 "a\x42;c\xff;\x0;")
     26 (if (= (bytevector-length h2) 5) 0 (sys-exit 12))
     27 (if (= (bytevector-u8-ref h2 0)  97) 0 (sys-exit 13))  ; 'a'
     28 (if (= (bytevector-u8-ref h2 1)  66) 0 (sys-exit 14))  ; 'B'
     29 (if (= (bytevector-u8-ref h2 2)  99) 0 (sys-exit 15))  ; 'c'
     30 (if (= (bytevector-u8-ref h2 3) 255) 0 (sys-exit 16))  ; 0xff
     31 (if (= (bytevector-u8-ref h2 4)   0) 0 (sys-exit 17))  ; 0x00
     32 
     33 ; Multi-digit form (still byte-sized) and uppercase X is NOT accepted —
     34 ; only lowercase \x; this matches R7RS-Small literal syntax.
     35 (define h3 "\x0041;")                                  ; leading zeros ok
     36 (if (= (bytevector-length h3) 1) 0 (sys-exit 18))
     37 (if (= (bytevector-u8-ref h3 0) 65) 0 (sys-exit 19))
     38 
     39 (sys-exit 0)