Clean up some <file-reader> usages to use file-lines, file>csv, and file>xml instead
parent
2fe934ba9d
commit
ebd0e9250f
|
@ -107,7 +107,7 @@ TUPLE: cached-template path last-modified quot ;
|
|||
path>> ".xml" append
|
||||
[ ]
|
||||
[ file-info modified>> ]
|
||||
[ utf8 <file-reader> read-xml compile-template ] tri
|
||||
[ file>xml compile-template ] tri
|
||||
\ cached-template boa ;
|
||||
|
||||
\ load-template DEBUG add-input-logging
|
||||
|
|
|
@ -34,7 +34,7 @@ IN: io.encodings.8-bit
|
|||
|
||||
: encoding-file ( file-name -- stream )
|
||||
"vocab:io/encodings/8-bit/" swap ".TXT"
|
||||
3append ascii <file-reader> ;
|
||||
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
|
||||
|
|
|
@ -21,14 +21,14 @@ ERROR: missing-name encoding ;
|
|||
dup e>n-table get-global at [ ] [ missing-name ] ?if ;
|
||||
|
||||
<PRIVATE
|
||||
: parse-iana ( stream -- synonym-set )
|
||||
lines { "" } split [
|
||||
: parse-iana ( file -- synonym-set )
|
||||
utf8 file-lines { "" } split [
|
||||
[ " " split ] map
|
||||
[ first { "Name:" "Alias:" } member? ] filter
|
||||
[ second ] map { "None" } diff
|
||||
] map harvest ;
|
||||
|
||||
: make-aliases ( stream -- n>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 <file-reader> make-aliases aliases set-global
|
||||
make-aliases aliases set-global
|
||||
|
||||
n>e-table [ initial-n>e ] initialize
|
||||
e>n-table [ initial-e>n ] initialize
|
||||
|
|
|
@ -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 <file-reader> parse-ducet to: ducet
|
||||
"vocab:unicode/collation/allkeys.txt" parse-ducet to: ducet
|
||||
|
||||
! Fix up table for long contractions
|
||||
: help-one ( assoc key -- )
|
||||
|
|
|
@ -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 <file-reader> parse-script process-script ;
|
||||
parse-script process-script ;
|
||||
|
||||
[ name>char [ "Invalid character" throw ] unless* ]
|
||||
name>char-hook set-global
|
||||
|
|
|
@ -37,8 +37,7 @@ MEMO: mode-names ( -- modes )
|
|||
MEMO: (load-mode) ( name -- rule-sets )
|
||||
modes at [
|
||||
file>>
|
||||
"vocab:xmode/modes/" prepend
|
||||
utf8 <file-reader> parse-mode
|
||||
"vocab:xmode/modes/" prepend parse-mode
|
||||
] [
|
||||
"text" (load-mode)
|
||||
] if* ;
|
||||
|
|
|
@ -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 ;
|
||||
|
|
|
@ -4,18 +4,18 @@ namespaces accessors io.encodings ;
|
|||
IN: io.streams.encodings.tests
|
||||
|
||||
[ { } ]
|
||||
[ "vocab:io/test/empty-file.txt" ascii <file-reader> 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 <file-reader> 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 <file-reader> lines-test
|
||||
ascii lines-test
|
||||
] unit-test
|
||||
|
||||
[
|
||||
|
@ -31,7 +31,7 @@ unit-test
|
|||
"This is another line."
|
||||
] [
|
||||
"vocab:io/test/unix-eol.txt"
|
||||
ascii <file-reader> lines-test
|
||||
ascii lines-test
|
||||
] unit-test
|
||||
|
||||
[
|
||||
|
|
|
@ -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 <file-reader>
|
||||
[ 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 <file-reader>
|
||||
[ 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 <file-reader> [
|
||||
latin1 [
|
||||
"J" read-until 2array ,
|
||||
"i" read-until 2array ,
|
||||
"X" read-until 2array ,
|
||||
] with-input-stream
|
||||
] with-file-reader
|
||||
] { } make
|
||||
] unit-test
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ IN: benchmark.xml
|
|||
|
||||
: xml-benchmark ( -- )
|
||||
"vocab:xmode/modes/" [
|
||||
[ utf8 <file-reader> read-xml drop ] each
|
||||
[ file>xml drop ] each
|
||||
] with-directory-files ;
|
||||
|
||||
MAIN: xml-benchmark
|
||||
|
|
|
@ -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 <file-reader>
|
||||
csv rest-slice [
|
||||
"resource:extra/usa-cities/zipcode.csv" ascii file>csv
|
||||
rest-slice [
|
||||
[
|
||||
{
|
||||
[ string>number ]
|
||||
|
|
Loading…
Reference in New Issue