From ebd0e9250f2891b5ccbae60fad103b75be9f018a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 15 Feb 2009 20:45:06 -0600 Subject: [PATCH] Clean up some usages to use file-lines, file>csv, and file>xml instead --- basis/html/templates/chloe/chloe.factor | 2 +- basis/io/encodings/8-bit/8-bit.factor | 6 +++--- basis/io/encodings/iana/iana.factor | 8 ++++---- basis/unicode/collation/collation.factor | 7 +++---- basis/unicode/data/data.factor | 6 +++--- basis/xmode/catalog/catalog.factor | 3 +-- basis/xmode/loader/loader.factor | 4 ++-- core/io/encodings/encodings-tests.factor | 12 ++++++------ core/io/files/files-tests.factor | 12 ++++++------ extra/benchmark/xml/xml.factor | 2 +- extra/usa-cities/usa-cities.factor | 4 ++-- 11 files changed, 32 insertions(+), 34 deletions(-) diff --git a/basis/html/templates/chloe/chloe.factor b/basis/html/templates/chloe/chloe.factor index 439b207063..da0d45a9d4 100644 --- a/basis/html/templates/chloe/chloe.factor +++ b/basis/html/templates/chloe/chloe.factor @@ -107,7 +107,7 @@ TUPLE: cached-template path last-modified quot ; path>> ".xml" append [ ] [ file-info modified>> ] - [ utf8 read-xml compile-template ] tri + [ file>xml compile-template ] tri \ cached-template boa ; \ load-template DEBUG add-input-logging diff --git a/basis/io/encodings/8-bit/8-bit.factor b/basis/io/encodings/8-bit/8-bit.factor index b3519a7990..bad2d9fd82 100644 --- a/basis/io/encodings/8-bit/8-bit.factor +++ b/basis/io/encodings/8-bit/8-bit.factor @@ -34,7 +34,7 @@ IN: io.encodings.8-bit : encoding-file ( file-name -- stream ) "vocab:io/encodings/8-bit/" swap ".TXT" - 3append ascii ; + 3append ; : process-contents ( lines -- assoc ) [ "#" split1 drop ] map harvest @@ -47,8 +47,8 @@ IN: io.encodings.8-bit : ch>byte ( assoc -- newassoc ) [ swap ] assoc-map >hashtable ; -: parse-file ( stream -- byte>ch ch>byte ) - lines process-contents +: parse-file ( path -- byte>ch ch>byte ) + ascii file-lines process-contents [ byte>ch ] [ ch>byte ] bi ; SYMBOL: 8-bit-encodings diff --git a/basis/io/encodings/iana/iana.factor b/basis/io/encodings/iana/iana.factor index 07b0429696..a8555ac339 100644 --- a/basis/io/encodings/iana/iana.factor +++ b/basis/io/encodings/iana/iana.factor @@ -21,14 +21,14 @@ ERROR: missing-name encoding ; dup e>n-table get-global at [ ] [ missing-name ] ?if ; e ) +: make-aliases ( file -- n>e ) parse-iana [ [ first ] [ ] bi ] H{ } map>assoc ; : initial-n>e ( -- assoc ) @@ -45,7 +45,7 @@ ERROR: missing-name encoding ; PRIVATE> "vocab:io/encodings/iana/character-sets" -utf8 make-aliases aliases set-global +make-aliases aliases set-global n>e-table [ initial-n>e ] initialize e>n-table [ initial-e>n ] initialize diff --git a/basis/unicode/collation/collation.factor b/basis/unicode/collation/collation.factor index 78727b16e2..2a94d501bd 100755 --- a/basis/unicode/collation/collation.factor +++ b/basis/unicode/collation/collation.factor @@ -24,12 +24,11 @@ TUPLE: weight primary secondary tertiary ignorable? ; ";" split1 [ [ blank? ] trim ] bi@ [ " " split [ hex> ] "" map-as ] [ parse-weight ] bi* ; -: parse-ducet ( stream -- ducet ) - lines filter-comments +: parse-ducet ( file -- ducet ) + ascii file-lines filter-comments [ parse-line ] H{ } map>assoc ; -"vocab:unicode/collation/allkeys.txt" -ascii parse-ducet to: ducet +"vocab:unicode/collation/allkeys.txt" parse-ducet to: ducet ! Fix up table for long contractions : help-one ( assoc key -- ) diff --git a/basis/unicode/data/data.factor b/basis/unicode/data/data.factor index d40024eb1e..de8d28ad2e 100644 --- a/basis/unicode/data/data.factor +++ b/basis/unicode/data/data.factor @@ -196,9 +196,9 @@ load-properties to: properties SYMBOL: interned -: parse-script ( stream -- assoc ) +: parse-script ( filename -- assoc ) ! assoc is code point/range => name - lines filter-comments [ split-; ] map ; + ascii file-lines filter-comments [ split-; ] map ; : range, ( value key -- ) swap interned get @@ -218,7 +218,7 @@ SYMBOL: interned [ expand-ranges ] with-variable ; : load-script ( filename -- table ) - ascii parse-script process-script ; + parse-script process-script ; [ name>char [ "Invalid character" throw ] unless* ] name>char-hook set-global diff --git a/basis/xmode/catalog/catalog.factor b/basis/xmode/catalog/catalog.factor index 47186d2090..7a935d31a4 100644 --- a/basis/xmode/catalog/catalog.factor +++ b/basis/xmode/catalog/catalog.factor @@ -37,8 +37,7 @@ MEMO: mode-names ( -- modes ) MEMO: (load-mode) ( name -- rule-sets ) modes at [ file>> - "vocab:xmode/modes/" prepend - utf8 parse-mode + "vocab:xmode/modes/" prepend parse-mode ] [ "text" (load-mode) ] if* ; diff --git a/basis/xmode/loader/loader.factor b/basis/xmode/loader/loader.factor index 70466913a0..ef1defc4da 100644 --- a/basis/xmode/loader/loader.factor +++ b/basis/xmode/loader/loader.factor @@ -84,5 +84,5 @@ TAGS> [ merge-rule-set-props ] with each ] when* ; -: parse-mode ( stream -- rule-sets ) - read-xml parse-mode-tag ; +: parse-mode ( filename -- rule-sets ) + file>xml parse-mode-tag ; diff --git a/core/io/encodings/encodings-tests.factor b/core/io/encodings/encodings-tests.factor index cb066dd3a5..fa8832deab 100644 --- a/core/io/encodings/encodings-tests.factor +++ b/core/io/encodings/encodings-tests.factor @@ -4,18 +4,18 @@ namespaces accessors io.encodings ; IN: io.streams.encodings.tests [ { } ] -[ "vocab:io/test/empty-file.txt" ascii lines ] +[ "vocab:io/test/empty-file.txt" ascii file-lines ] unit-test -: lines-test ( stream -- line1 line2 ) - [ readln readln ] with-input-stream ; +: lines-test ( file encoding -- line1 line2 ) + [ readln readln ] with-file-reader ; [ "This is a line." "This is another line." ] [ "vocab:io/test/windows-eol.txt" - ascii lines-test + ascii lines-test ] unit-test [ @@ -23,7 +23,7 @@ unit-test "This is another line." ] [ "vocab:io/test/mac-os-eol.txt" - ascii lines-test + ascii lines-test ] unit-test [ @@ -31,7 +31,7 @@ unit-test "This is another line." ] [ "vocab:io/test/unix-eol.txt" - ascii lines-test + ascii lines-test ] unit-test [ diff --git a/core/io/files/files-tests.factor b/core/io/files/files-tests.factor index c49fcb7aea..ce15a69773 100644 --- a/core/io/files/files-tests.factor +++ b/core/io/files/files-tests.factor @@ -14,15 +14,15 @@ IN: io.files.tests [ "This is a line.\rThis is another line.\r" ] [ - "vocab:io/test/mac-os-eol.txt" latin1 - [ 500 read ] with-input-stream + "vocab:io/test/mac-os-eol.txt" latin1 + [ 500 read ] with-file-reader ] unit-test [ 255 ] [ - "vocab:io/test/binary.txt" latin1 - [ read1 ] with-input-stream >fixnum + "vocab:io/test/binary.txt" latin1 + [ read1 ] with-file-reader >fixnum ] unit-test [ ] [ @@ -39,11 +39,11 @@ IN: io.files.tests ] [ [ "separator-test.txt" temp-file - latin1 [ + latin1 [ "J" read-until 2array , "i" read-until 2array , "X" read-until 2array , - ] with-input-stream + ] with-file-reader ] { } make ] unit-test diff --git a/extra/benchmark/xml/xml.factor b/extra/benchmark/xml/xml.factor index 5f8955b97c..0450331ddf 100644 --- a/extra/benchmark/xml/xml.factor +++ b/extra/benchmark/xml/xml.factor @@ -6,7 +6,7 @@ IN: benchmark.xml : xml-benchmark ( -- ) "vocab:xmode/modes/" [ - [ utf8 read-xml drop ] each + [ file>xml drop ] each ] with-directory-files ; MAIN: xml-benchmark diff --git a/extra/usa-cities/usa-cities.factor b/extra/usa-cities/usa-cities.factor index 25ec30ac78..0ee2a114dd 100644 --- a/extra/usa-cities/usa-cities.factor +++ b/extra/usa-cities/usa-cities.factor @@ -28,8 +28,8 @@ TUPLE: city first-zip name state latitude longitude gmt-offset dst-offset ; MEMO: cities ( -- seq ) - "resource:extra/usa-cities/zipcode.csv" ascii - csv rest-slice [ + "resource:extra/usa-cities/zipcode.csv" ascii file>csv + rest-slice [ [ { [ string>number ]