]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/io/encodings/iso2022/iso2022.factor
use radix literals
[factor.git] / basis / io / encodings / iso2022 / iso2022.factor
index 3dabb894e41602cb29ee75b157862bbf8e2d1b32..1a8b66c3c01d53ad0cc477e2123c9ae2b9a1b8b5 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io.encodings kernel sequences io simple-flat-file sets math
 combinators.short-circuit io.binary values arrays assocs
-locals accessors combinators literals biassocs byte-arrays ;
+locals accessors combinators biassocs byte-arrays parser ;
 IN: io.encodings.iso2022
 
 SINGLETON: iso2022
@@ -13,12 +13,12 @@ VALUE: jis201
 VALUE: jis208
 VALUE: jis212
 
-"vocab:io/encodings/iso2022/201.txt" flat-file>biassoc to: jis201
-"vocab:io/encodings/iso2022/208.txt" flat-file>biassoc to: jis208
-"vocab:io/encodings/iso2022/212.txt" flat-file>biassoc to: jis212
+"vocab:io/encodings/iso2022/201.txt" flat-file>biassoc \ jis201 set-value
+"vocab:io/encodings/iso2022/208.txt" flat-file>biassoc \ jis208 set-value
+"vocab:io/encodings/iso2022/212.txt" flat-file>biassoc \ jis212 set-value
 
 VALUE: ascii
-128 unique >biassoc to: ascii
+128 iota unique >biassoc \ ascii set-value
 
 TUPLE: iso2022-state type ;
 
@@ -31,12 +31,12 @@ M: iso2022 <encoder>
 M: iso2022 <decoder>
     make-iso-coder <decoder> ;
 
-CONSTANT: ESC HEX: 16
+<< SYNTAX: ESC 0x16 suffix! ; >>
 
-CONSTANT: switch-ascii B{ ESC CHAR: ( CHAR: B }
-CONSTANT: switch-jis201 B{ ESC CHAR: ( CHAR: J }
-CONSTANT: switch-jis208 B{ ESC CHAR: $ CHAR: B }
-CONSTANT: switch-jis212 B{ ESC CHAR: $ CHAR: ( CHAR: D }
+CONSTANT: switch-ascii B{ ESC CHAR: ( CHAR: B }
+CONSTANT: switch-jis201 B{ ESC CHAR: ( CHAR: J }
+CONSTANT: switch-jis208 B{ ESC CHAR: $ CHAR: B }
+CONSTANT: switch-jis212 B{ ESC CHAR: $ CHAR: ( CHAR: D }
 
 : find-type ( char -- code type )
     {
@@ -56,7 +56,7 @@ M:: iso2022-state encode-char ( char stream encoding -- )
     char encoding type>> value? [
         char find-type
         [ stream stream-write ]
-        [ encoding (>>type) ] bi*
+        [ encoding type<< ] bi*
     ] unless
     char encoding type>> value-at stream stream-write-num ;
 
@@ -92,7 +92,7 @@ M:: iso2022-state decode-char ( stream encoding -- char )
     stream stream-read1 {
         { ESC [
             stream read-escape [
-                encoding (>>type)
+                encoding type<<
                 stream encoding decode-char
             ] [ replacement-char ] if*
         ] }