diff --git a/basis/db/db-docs.factor b/basis/db/db-docs.factor index ae7451cb48..08544b3367 100644 --- a/basis/db/db-docs.factor +++ b/basis/db/db-docs.factor @@ -244,13 +244,13 @@ ARTICLE: "db-protocol" "Low-level database protocol" ! { $subsection bind-tuple } ARTICLE: "db-lowlevel-tutorial" "Low-level database tutorial" -"Although Factor makes integrating a database with its object system easy (see " { $vocab-link "db.tuples" } "), sometimes you may want to write SQL directly and get the results back as arrays of strings, for instance, when interfacing with a legacy database that doesn't easily map to " { $snippet "tuples" } "." +"Although Factor makes integrating a database with its object system easy (see " { $vocab-link "db.tuples" } "), sometimes you may want to write SQL directly and get the results back as arrays of strings, for instance, when interfacing with a legacy database that doesn't easily map to " { $snippet "tuples" } "." $nl "Executing a SQL command:" { $subsection sql-command } "Executing a query directly:" { $subsection sql-query } "Here's an example usage where we'll make a book table, insert some objects, and query them." $nl -"First, let's set up a custom combinator for using our database. See " { $link "db-custom-database-combinators" } " for more details." +"First, let's set up a custom combinator for using our database. See " { $link "db-custom-database-combinators" } " for more details." { $code <" USING: db.sqlite db io.files ; : with-book-db ( quot -- ) diff --git a/basis/db/tuples/tuples-docs.factor b/basis/db/tuples/tuples-docs.factor index 51830ee610..e853c55ede 100644 --- a/basis/db/tuples/tuples-docs.factor +++ b/basis/db/tuples/tuples-docs.factor @@ -199,7 +199,7 @@ ARTICLE: "db-tuples-protocol" "Tuple database protocol" { $subsection } ; ARTICLE: "db-tuples-tutorial" "Tuple database tutorial" -"Let's make a tuple and store it in a database. To follow along, click on each code example and run it in the listener. If you forget to run an example, just start at the top and run them all again in order." $nl +"Let's make a tuple and store it in a database. To follow along, click on each code example and run it in the listener. If you forget to run an example, just start at the top and run them all again in order." $nl "We're going to store books in this tutorial." { $code "TUPLE: book id title author date-published edition cover-price condition ;" } "The title, author, and publisher should be strings; the date-published a timestamp; the edition an integer; the cover-price a float. These are the Factor types for which we will need to look up the corresponding " { $link "db.types" } ". " $nl @@ -246,7 +246,7 @@ T{ book { $code <" [ book get update-tuple ] with-book-tutorial "> } -"And select it again. You can query the database by any field -- just set it in the exemplar tuple you pass to " { $link select-tuples } "." +"And select it again. You can query the database by any field -- just set it in the exemplar tuple you pass to " { $link select-tuples } "." { $code <" [ T{ book { title "Factor for Sheeple" } } select-tuples ] with-book-tutorial "> } diff --git a/basis/farkup/farkup.factor b/basis/farkup/farkup.factor index ccd12b83f2..b9e62717eb 100644 --- a/basis/farkup/farkup.factor +++ b/basis/farkup/farkup.factor @@ -236,7 +236,7 @@ M: f (write-farkup) ; parse-farkup (write-farkup) ; : write-farkup ( string -- ) - farkup>xml write-xml-chunk ; + farkup>xml write-xml ; : convert-farkup ( string -- string' ) [ write-farkup ] with-string-writer ; diff --git a/basis/html/components/components.factor b/basis/html/components/components.factor index e63447ec55..462c9b3c78 100644 --- a/basis/html/components/components.factor +++ b/basis/html/components/components.factor @@ -19,7 +19,7 @@ GENERIC: render* ( value name renderer -- xml ) [ f swap ] if ] 2dip - render* write-xml-chunk + render* write-xml [ render-error ] when* ; xml-chunk ; +M: html render* 2drop ; diff --git a/basis/html/elements/elements.factor b/basis/html/elements/elements.factor index 7bca545df5..a6e1928f83 100644 --- a/basis/html/elements/elements.factor +++ b/basis/html/elements/elements.factor @@ -1,11 +1,9 @@ -! cont-html v0.6 -! -! Copyright (C) 2004 Chris Double. +! Copyright (C) 2004, 2009 Chris Double, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. - USING: io io.styles kernel namespaces prettyprint quotations sequences strings words xml.entities compiler.units effects -urls math math.parser combinators present fry ; +xml.data xml.interpolate urls math math.parser combinators +present fry io.streams.string xml.writer ; IN: html.elements @@ -135,17 +133,18 @@ SYMBOL: html "" write-html ; : simple-page ( title head-quot body-quot -- ) - #! Call the quotation, with all output going to the - #! body of an html page with the given title. - spin - xhtml-preamble - - - write - call - - call - ; inline + [ with-string-writer ] bi@ + + + + + <-> + <-> + + <-> + + XML> write-xml ; inline : render-error ( message -- ) - escape-string write ; + [XML <-> XML] write-xml ; diff --git a/basis/html/templates/chloe/compiler/compiler.factor b/basis/html/templates/chloe/compiler/compiler.factor index 4410cd7599..4034b67d45 100644 --- a/basis/html/templates/chloe/compiler/compiler.factor +++ b/basis/html/templates/chloe/compiler/compiler.factor @@ -49,7 +49,7 @@ DEFER: compile-element reset-buffer "@" ?head [ , [ value present ] % ] [ , ] if ; : compile-attrs ( assoc -- ) - attrs>> [ + [ " " [write] swap name>string [write] "=\"" [write] @@ -59,7 +59,7 @@ DEFER: compile-element : compile-start-tag ( tag -- ) "<" [write] - [ name>string [write] ] [ compile-attrs ] bi + [ name>string [write] ] [ attrs>> compile-attrs ] bi ">" [write] ; : compile-end-tag ( tag -- ) @@ -90,7 +90,7 @@ ERROR: unknown-chloe-tag tag ; { [ dup [ tag? ] [ xml? ] bi or ] [ compile-tag ] } { [ dup string? ] [ escape-string [write] ] } { [ dup comment? ] [ drop ] } - [ [ write-xml-chunk ] [code-with] ] + [ [ write-xml ] [code-with] ] } cond ; : with-compiler ( quot -- quot' ) @@ -126,7 +126,7 @@ ERROR: unknown-chloe-tag tag ; : compile-prologue ( xml -- ) [ - [ prolog>> [ write-prolog ] [code-with] ] + [ prolog>> [ write-xml ] [code-with] ] [ before>> compile-chunk ] bi ] compile-quot diff --git a/basis/http/http-tests.factor b/basis/http/http-tests.factor index 6b0bdbe2c0..6103fb622f 100644 --- a/basis/http/http-tests.factor +++ b/basis/http/http-tests.factor @@ -2,7 +2,7 @@ USING: http http.server http.client http.client.private tools.test multiline io.streams.string io.encodings.utf8 io.encodings.8-bit io.encodings.binary io.encodings.string kernel arrays splitting sequences assocs io.sockets db db.sqlite continuations urls -hashtables accessors namespaces ; +hashtables accessors namespaces xml.data ; IN: http.tests [ "text/plain" latin1 ] [ "text/plain" parse-content-type ] unit-test @@ -322,7 +322,7 @@ SYMBOL: a 3 a set-global -: test-a string>xml "input" tag-named "value" swap at ; +: test-a string>xml "input" tag-named "value" attr ; [ "3" ] [ "http://localhost/" add-port http-get diff --git a/basis/http/server/server.factor b/basis/http/server/server.factor index b4af727caa..a886d7bae7 100755 --- a/basis/http/server/server.factor +++ b/basis/http/server/server.factor @@ -12,6 +12,7 @@ io.encodings.utf8 io.encodings.ascii io.encodings.binary io.streams.limited +io.streams.string io.servers.connection io.timeouts io.crlf diff --git a/basis/lcs/diff2html/diff2html-tests.factor b/basis/lcs/diff2html/diff2html-tests.factor index d261a4659a..0c2ed34f45 100644 --- a/basis/lcs/diff2html/diff2html-tests.factor +++ b/basis/lcs/diff2html/diff2html-tests.factor @@ -3,4 +3,4 @@ USING: lcs.diff2html lcs kernel tools.test strings sequences xml.writer ; IN: lcs.diff2html.tests -[ ] [ "hello" "heyo" [ 1string ] { } map-as diff htmlize-diff xml-chunk>string drop ] unit-test +[ ] [ "hello" "heyo" [ 1string ] { } map-as diff htmlize-diff xml>string drop ] unit-test diff --git a/basis/syndication/syndication.factor b/basis/syndication/syndication.factor index 58b2279cb1..b23910e200 100644 --- a/basis/syndication/syndication.factor +++ b/basis/syndication/syndication.factor @@ -81,7 +81,7 @@ TUPLE: entry title url description date ; [ { "content" "summary" } any-tag-named dup children>> [ string? not ] contains? - [ children>> [ write-xml-chunk ] with-string-writer ] + [ children>> xml>string ] [ children>string ] if >>description ] [ diff --git a/basis/xml/autoencoding/autoencoding.factor b/basis/xml/autoencoding/autoencoding.factor index 5dc32958d4..20a661cfa7 100644 --- a/basis/xml/autoencoding/autoencoding.factor +++ b/basis/xml/autoencoding/autoencoding.factor @@ -2,14 +2,15 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel namespaces xml.name io.encodings.utf8 xml.elements io.encodings.utf16 xml.tokenize xml.state math ascii sequences -io.encodings.string io.encodings combinators ; +io.encodings.string io.encodings combinators accessors +xml.data io.encodings.iana ; IN: xml.autoencoding : continue-make-tag ( str -- tag ) parse-name-starting middle-tag end-tag ; : start-utf16le ( -- tag ) - utf16le decode-input-if + utf16le decode-input "?\0" expect check instruct ; @@ -17,20 +18,36 @@ IN: xml.autoencoding -6 shift 3 bitand 2 = ; : start> dup "UTF-16" = + [ drop ] [ name>encoding [ decode-input ] when* ] if ; + +: instruct-encoding ( instruct/prolog -- ) + dup prolog? + [ prolog-encoding ] + [ drop utf8 decode-input ] if ; + +: go-utf8 ( -- ) + check utf8 decode-input next next ; + : start< ( -- tag ) + ! What if first letter of processing instruction is non-ASCII? get-next { { 0 [ next next start-utf16le ] } - { CHAR: ? [ check next next instruct ] } ! XML prolog parsing sets the encoding - { CHAR: ! [ check utf8 decode-input next next direct ] } + { CHAR: ? [ go-utf8 instruct dup instruct-encoding ] } + { CHAR: ! [ go-utf8 direct ] } [ check start, in the case of XML chunks? - } case check ; + [ drop utf8 decode-input check f ] + } case ; diff --git a/basis/xml/char-classes/char-classes.factor b/basis/xml/char-classes/char-classes.factor index 03e85e3ea3..b47d4c66df 100644 --- a/basis/xml/char-classes/char-classes.factor +++ b/basis/xml/char-classes/char-classes.factor @@ -26,7 +26,7 @@ CATEGORY: 1.1name-char Ll Lu Lo Lm Ln Nl Mc Mn Nd Pc Cf _-.\u0000b7: ; ! 1.1: ! [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] { - { [ dup HEX: 20 < ] [ "\t\r\n" member? and ] } + { [ dup HEX: 20 < ] [ swap [ "\t\r\n" member? ] [ zero? not ] if ] } { [ nip dup HEX: D800 < ] [ drop t ] } { [ dup HEX: E000 < ] [ drop f ] } [ { HEX: FFFE HEX: FFFF } member? not ] diff --git a/basis/xml/data/data-docs.factor b/basis/xml/data/data-docs.factor index 52394ccc5c..639ef5591c 100644 --- a/basis/xml/data/data-docs.factor +++ b/basis/xml/data/data-docs.factor @@ -13,15 +13,17 @@ ARTICLE: "xml.data" "XML data types" "For high-level tools for manipulating XML, see " { $vocab-link "xml.utilities" } ; ARTICLE: { "xml.data" "classes" } "XML data classes" - "Data types that XML documents are made of:" - { $subsection name } + "XML documents and chunks are made of the following classes:" + { $subsection xml } + { $subsection xml-chunk } { $subsection tag } + { $subsection name } { $subsection contained-tag } { $subsection open-tag } - { $subsection xml } { $subsection prolog } { $subsection comment } { $subsection instruction } + { $subsection unescaped } { $subsection element-decl } { $subsection attlist-decl } { $subsection entity-decl } @@ -32,13 +34,15 @@ ARTICLE: { "xml.data" "classes" } "XML data classes" ARTICLE: { "xml.data" "constructors" } "XML data constructors" "These data types are constructed with:" - { $subsection } - { $subsection } - { $subsection } { $subsection } + { $subsection } + { $subsection } + { $subsection } + { $subsection } { $subsection } { $subsection } { $subsection } + { $subsection } { $subsection } { $subsection } { $subsection } @@ -89,7 +93,7 @@ HELP: xml HELP: { $values { "prolog" "an XML prolog" } { "before" "a sequence of XML elements" } { "body" tag } { "after" "a sequence of XML elements" } { "xml" "an XML document" } } -{ $description "creates an XML document, delegating to the main tag, with the specified prolog, before, and after" } +{ $description "Creates an XML document. The " { $snippet "before" } " and " { $snippet "after" } " slots store what comes before and after the main tag, and " { $snippet "body" } "contains the main tag itself." } { $see-also xml } ; HELP: prolog @@ -99,47 +103,46 @@ HELP: prolog HELP: { $values { "version" "a string, 1.0 or 1.1" } { "encoding" "a string" } { "standalone" "a boolean" } { "prolog" "an XML prolog" } } -{ $description "creates an XML prolog tuple" } +{ $description "Creates an XML prolog tuple." } { $see-also prolog } ; HELP: comment -{ $class-description "represents a comment in XML. Has one slot, text, which contains the string of the comment" } +{ $class-description "Represents a comment in XML. This tuple has one slot, " { $snippet "text" } ", which contains the string of the comment." } { $see-also } ; HELP: -{ $values { "text" "a string" } { "comment" "a comment" } } -{ $description "creates an XML comment tuple" } +{ $values { "text" string } { "comment" comment } } +{ $description "Creates an XML " { $link comment } " tuple." } { $see-also comment } ; HELP: instruction -{ $class-description "represents an XML instruction, such as . Contains one slot, text, which contains the string between the question marks." } +{ $class-description "Represents an XML instruction, such as " { $snippet "" } ". Contains one slot, " { $snippet "text" } ", which contains the string between the question marks." } { $see-also } ; HELP: { $values { "text" "a string" } { "instruction" "an XML instruction" } } -{ $description "creates an XML parsing instruction, such as ." } +{ $description "Creates an XML parsing instruction, like " { $snippet "" } "." } { $see-also instruction } ; HELP: opener -{ $class-description "describes an opening tag, like . Contains two slots, name and attrs containing, respectively, the name of the tag and its attributes. Usually, the name-url will be f." } -{ $see-also closer contained } ; +{ $class-description "Describes an opening tag, like " { $snippet "" } ". Contains two slots, " { $snippet "name" } " and " { $snippet "attrs" } " containing, respectively, the name of the tag and its attributes." } ; HELP: closer -{ $class-description "describes a closing tag, like . Contains one slot, name, containing the tag's name. Usually, the name-url will be f." } -{ $see-also opener contained } ; +{ $class-description "Describes a closing tag, like " { $snippet "" } ". Contains one slot, " { $snippet "name" } ", containing the closer's name." } ; HELP: contained -{ $class-description "represents a self-closing tag, like . Contains two slots, name and attrs containing, respectively, the name of the tag and its attributes. Usually, the name-url will be f." } -{ $see-also opener closer } ; +{ $class-description "Represents a self-closing tag, like " { $snippet "" } ". Contains two slots," { $snippet "name" } " and " { $snippet "attrs" } " containing, respectively, the name of the tag and its attributes." } ; + +{ opener closer contained } related-words HELP: open-tag -{ $class-description "represents a tag that does have children, ie is not a contained tag" } -{ $notes "the constructor used for this class is simply " { $link } "." } +{ $class-description "Represents a tag that does have children, ie. is not a contained tag" } +{ $notes "The constructor used for this class is simply " { $link } "." } { $see-also tag contained-tag } ; HELP: names-match? { $values { "name1" "a name" } { "name2" "a name" } { "?" "t or f" } } -{ $description "checks to see if the two names match, that is, if all fields are equal, ignoring fields whose value is f in either name." } +{ $description "Checks to see if the two names match, that is, if all fields are equal, ignoring fields whose value is f in either name." } { $example "USING: prettyprint xml.data ;" "T{ name f \"rpc\" \"methodCall\" f } T{ name f f \"methodCall\" \"http://www.xmlrpc.org/\" } names-match? ." "t" } { $see-also name } ; @@ -173,7 +176,7 @@ HELP: { $description "Creates an entity declaration object, of the class " { $link entity-decl } ". The pe? slot should be t if the object is a DTD-internal entity, like " { $snippet "" } " and f if the object is like " { $snippet "" } ", that is, it can be used outside of the DTD." } ; HELP: system-id -{ $class-description "Describes the class of system identifiers within an XML DTD directive, such as " { $snippet "" } } ; +{ $class-description "Describes the class of system identifiers within an XML DTD directive, such as " { $snippet "" } "." } ; HELP: { $values { "system-literal" string } { "system-id" system-id } } @@ -199,3 +202,17 @@ HELP: doctype-decl HELP: { $values { "name" name } { "external-id" id } { "internal-subset" sequence } { "doctype-decl" doctype-decl } } { $description "Creates a new doctype declaration object, of the class " { $link doctype-decl } ". Only one of external-id or internal-subset will be non-null." } ; + +HELP: unescaped +{ $class-description "When constructing XML documents to write to output, it can be useful to splice in a string which is already written. This tuple type allows for that. Printing an " { $snippet "unescaped" } " is the same is printing its " { $snippet "string" } " slot." } ; + +HELP: +{ $values { "string" string } { "unescaped" unescaped } } +{ $description "Constructs an " { $link unescaped } " tuple, given a string." } ; + +HELP: xml-chunk +{ $class-description "Encapsulates a balanced fragment of an XML document. This is a sequence (following the sequence protocol) of XML data types, eg " { $link string } "s and " { $link tag } "s." } ; + +HELP: +{ $values { "seq" sequence } { "xml-chunk" xml-chunk } } +{ $description "Constructs an " { $link xml-chunk } " tuple, given a sequence to be its contents." } ; diff --git a/basis/xml/elements/elements.factor b/basis/xml/elements/elements.factor index 116acb076b..b927947329 100644 --- a/basis/xml/elements/elements.factor +++ b/basis/xml/elements/elements.factor @@ -29,7 +29,7 @@ IN: xml.elements parse-name swap ; : (middle-tag) ( -- ) - pass-blank version=1.0? get-char name-start? + pass-blank version-1.0? get-char name-start? [ parse-attr (middle-tag) ] when ; : assure-no-duplicates ( attrs-alist -- attrs-alist ) @@ -66,7 +66,8 @@ IN: xml.elements : prolog-version ( alist -- version ) T{ name { space "" } { main "version" } } swap at - [ good-version ] [ versionless-prolog ] if* ; + [ good-version ] [ versionless-prolog ] if* + dup set-version ; : prolog-encoding ( alist -- encoding ) T{ name { space "" } { main "encoding" } } swap at @@ -89,16 +90,9 @@ IN: xml.elements [ prolog-standalone ] tri ; -SYMBOL: string-input? -: decode-input-if ( encoding -- ) - string-input? get [ drop ] [ decode-input ] if ; - : parse-prolog ( -- prolog ) pass-blank middle-tag "?>" expect - dup assure-no-extra prolog-attrs - dup encoding>> dup "UTF-16" = - [ drop ] [ name>encoding [ decode-input-if ] when* ] if - dup prolog-data set ; + dup assure-no-extra prolog-attrs ; : instruct ( -- instruction ) take-name { diff --git a/basis/xml/entities/entities-docs.factor b/basis/xml/entities/entities-docs.factor index ab105300e1..2fccb500a4 100644 --- a/basis/xml/entities/entities-docs.factor +++ b/basis/xml/entities/entities-docs.factor @@ -12,11 +12,10 @@ ARTICLE: "xml.entities" "XML entities" "For entities used in HTML/XHTML, see " { $vocab-link "xml.entities.html" } ; HELP: entities -{ $description "a hash table from default XML entity names (like & and <) to the characters they represent. This is automatically included when parsing any XML document." } +{ $description "A hash table from default XML entity names (like " { $snippet "&" } " and " { $snippet "<" } ") to the characters they represent. This is automatically included when parsing any XML document." } { $see-also with-entities } ; HELP: with-entities -{ $values { "entities" "a hash table of strings to chars" } - { "quot" "a quotation ( -- )" } } -{ $description "calls the quotation using the given table of entity values (symbolizing, eg, that &foo; represents CHAR: a) on top of the default XML entities" } ; +{ $values { "entities" "a hash table of strings to strings" } { "quot" "a quotation ( -- )" } } +{ $description "Calls the quotation using the given table of entity values (symbolizing, eg, that " { $snippet "&foo;" } " represents " { $snippet "\"a\"" } ") on top of the default XML entities" } ; diff --git a/basis/xml/entities/html/html-docs.factor b/basis/xml/entities/html/html-docs.factor index 2e1b67a100..f436944954 100644 --- a/basis/xml/entities/html/html-docs.factor +++ b/basis/xml/entities/html/html-docs.factor @@ -5,14 +5,14 @@ IN: xml.entities.html ARTICLE: "xml.entities.html" "HTML entities" { $vocab-link "xml.entities.html" } " defines words for using entities defined in HTML/XHTML." - { $subsection html-entities } - { $subsection with-html-entities } ; +{ $subsection html-entities } +{ $subsection with-html-entities } ; HELP: html-entities -{ $description "a hash table from HTML entity names to their character values" } +{ $description "A hash table from HTML entity names to their character values." } { $see-also entities with-html-entities } ; HELP: with-html-entities { $values { "quot" "a quotation ( -- )" } } -{ $description "calls the given quotation using HTML entity values" } +{ $description "Calls the given quotation using HTML entity values." } { $see-also html-entities with-entities } ; diff --git a/basis/xml/errors/errors-docs.factor b/basis/xml/errors/errors-docs.factor index 46c4fbe466..01a943eab7 100644 --- a/basis/xml/errors/errors-docs.factor +++ b/basis/xml/errors/errors-docs.factor @@ -3,45 +3,60 @@ USING: help.markup help.syntax ; IN: xml.errors + + HELP: multitags -{ $class-description "XML parsing error describing the case where there is more than one main tag in a document. Contains no slots" } ; +{ $class-description "XML parsing error describing the case where there is more than one main tag in a document." } +{ $xml-error "\n" } ; HELP: notags -{ $class-description "XML parsing error describing the case where an XML document contains no main tag, or any tags at all" } ; +{ $class-description "XML parsing error describing the case where an XML document contains no main tag, or any tags at all" } +{ $xml-error "" } ; HELP: extra-attrs -{ $class-description "XML parsing error describing the case where the XML prolog (" { $snippet "" } ") contains attributes other than the three allowed ones, standalone, version and encoding. Contains one slot, attrs, which is a hashtable of all the extra attributes' names. Delegates to " { $link xml-error-at } "." } ; +{ $class-description "XML parsing error describing the case where the XML prolog (" { $snippet "" } ") contains attributes other than the three allowed ones, " { $snippet "standalone" } ", " { $snippet "version" } " and " { $snippet "encoding" } ". Contains one slot, " { $snippet "attrs" } ", which is a hashtable of all the extra attributes' names. This is a subclass of " { $link xml-error-at } "." } +{ $xml-error "\n" } ; HELP: nonexist-ns -{ $class-description "XML parsing error describing the case where a namespace doesn't exist but it is used in a tag. Contains one slot, name, which contains the name of the undeclared namespace, and delegates to " { $link xml-error-at } "." } ; +{ $class-description "XML parsing error describing the case where a namespace doesn't exist but it is used in a tag. Contains one slot, " { $snippet "name" } ", which contains the name of the undeclared namespace, and is a subclass of " { $link xml-error-at } "." } +{ $xml-error "c" } ; HELP: not-yes/no -{ $class-description "XML parsing error used to describe the case where standalone is set in the XML prolog to something other than 'yes' or 'no'. Delegates to " { $link xml-error-at } " and contains one slot, text, which contains offending value." } ; +{ $class-description "XML parsing error used to describe the case where standalone is set in the XML prolog to something other than " { $snippet "yes" } " or " { $snippet "no" } ". This is a subclass of " { $link xml-error-at } " and contains one slot, text, which contains offending value." } +{ $xml-error "\n" } ; HELP: unclosed -{ $class-description "XML parsing error used to describe the case where the XML document contains classes which are not closed by the end of the document. Contains one slot, tags, a sequence of names." } ; +{ $class-description "XML parsing error used to describe the case where the XML document contains classes which are not closed by the end of the document. Contains one slot, " { $snippet "tags" } ", a sequence of names." } +{ $xml-error "some text" } ; HELP: mismatched -{ $class-description "XML parsing error describing mismatched tags, eg " { $snippet "" } ". Contains two slots: open is the name of the opening tag and close is the name of the closing tag. Delegates to " { $link xml-error-at } " showing the location of the closing tag" } ; +{ $class-description "XML parsing error describing mismatched tags. Contains two slots: " { $snippet "open" } " is the name of the opening tag and " { $snippet "close" } " is the name of the closing tag. This is a subclass of " { $link xml-error-at } " showing the location of the closing tag" } +{ $xml-error "" } ; HELP: expected -{ $class-description "XML parsing error describing when an expected token was not present. Delegates to " { $link xml-error-at } ". Contains two slots, should-be, which has the expected string, and was, which has the actual string." } ; +{ $class-description "XML parsing error describing when an expected token was not present. Delegates to " { $link xml-error-at } ". Contains two slots, " { $snippet "should-be" } ", which has the expected string, and " { $snippet "was" } ", which has the actual string." } ; HELP: no-entity -{ $class-description "XML parsing error describing the use of an undefined entity in a case where standalone is marked yes. Delegates to " { $link xml-error-at } ". Contains one slot, thing, containing a string representing the entity." } ; +{ $class-description "XML parsing error describing the use of an undefined entity. This is a subclass of " { $link xml-error-at } ". Contains one slot, thing, containing a string representing the entity." } +{ $xml-error "&foo;" } ; HELP: pre/post-content -{ $class-description "Describes the error where a non-whitespace string is used before or after the main tag in an XML document. Contains two slots: string contains the offending string, and pre? is t if it occured before the main tag and f if it occured after" } ; - -HELP: unclosed-quote -{ $class-description "Describes the error where a quotation for an attribute value is opened but not closed before the end of the document." } ; +{ $class-description "Describes the error where a non-whitespace string is used before or after the main tag in an XML document. Contains two slots: " { $snippet "string" } " contains the offending string, and " { $snippet "pre?" } " is " { $snippet "t" } " if it occured before the main tag and " { $snippet "f" } " if it occured after." } +{ $xml-error "hello\n" } ; HELP: bad-name -{ $class-description "Describes the error where a name is used, for example in an XML tag or attribute key, which is invalid." } ; +{ $class-description "Describes the error where a name is used, for example in an XML tag or attribute key, which is invalid." } +{ $xml-error "<%>\n" } ; HELP: quoteless-attr -{ $class-description "Describes the error where an attribute of an XML tag is missing quotes around a value." } ; +{ $class-description "Describes the error where an attribute of an XML tag is missing quotes around a value." } +{ $xml-error "" } ; HELP: disallowed-char { $class-description "Describes the error where a disallowed character occurs in an XML document." } ; @@ -53,25 +68,30 @@ HELP: unexpected-end { $class-description "Describes the error where a document unexpectedly ends, and the XML parser expected it to continue." } ; HELP: duplicate-attr -{ $class-description "Describes the error where there is more than one attribute of the same key." } ; +{ $class-description "Describes the error where there is more than one attribute of the same key." } +{ $xml-error "" } ; HELP: bad-cdata -{ $class-description "Describes the error where CDATA is used outside of the main tag of an XML document." } ; +{ $class-description "Describes the error where CDATA is used outside of the main tag of an XML document." } +{ $xml-error "y\n" } ; HELP: text-w/]]> -{ $class-description "Describes the error where a text node contains the literal string " { $snippet "]]>" } " which is disallowed." } ; +{ $class-description "Describes the error where a text node contains the literal string " { $snippet "]]>" } " which is disallowed." } +{ $xml-error "Here's some text: ]]> there it was" } ; HELP: attr-w/< -{ $class-description "Describes the error where an attribute value contains the literal character " { $snippet "<" } " which is disallowed." } ; +{ $class-description "Describes the error where an attribute value contains the literal character " { $snippet "<" } " which is disallowed." } +{ $xml-error "" } ; HELP: misplaced-directive -{ $class-description "Describes the error where an internal DTD directive is used outside of a DOCTYPE or DTD file, or where a DOCTYPE occurs somewhere other than before the main tag of an XML document." } ; +{ $class-description "Describes the error where an internal DTD directive is used outside of a DOCTYPE or DTD file, or where a DOCTYPE occurs somewhere other than before the main tag of an XML document." } +{ $xml-error "" } ; HELP: xml-error { $class-description "The exception class that all parsing errors in XML documents are in." } ; ARTICLE: "xml.errors" "XML parsing errors" -"The " { $vocab-link "xml.errors" } " vocabulary provides a rich and highly inspectable set of parsing errors. All XML errors are described by the union class " { $link xml-error } " but there are many classes contained in that:" +"The " { $vocab-link "xml.errors" } " vocabulary provides a rich and highly inspectable set of parsing errors. All XML errors are described by the union class " { $link xml-error } "." { $subsection multitags } { $subsection notags } { $subsection extra-attrs } @@ -93,7 +113,7 @@ ARTICLE: "xml.errors" "XML parsing errors" { $subsection text-w/]]> } { $subsection attr-w/< } { $subsection misplaced-directive } - "Additionally, most of these errors are a kind of " { $link xml-error-at } " which provides more information" + "Additionally, most of these errors are a kind of " { $link xml-error-at } " which provides more information about where the error occurred." $nl "Note that, in parsing an XML document, only the first error is reported." ; diff --git a/basis/xml/errors/errors.factor b/basis/xml/errors/errors.factor index df38724412..304b38f2bd 100644 --- a/basis/xml/errors/errors.factor +++ b/basis/xml/errors/errors.factor @@ -194,7 +194,7 @@ M: bad-prolog summary ( obj -- str ) [ dup call-next-method write "Misplaced XML prolog" print - prolog>> write-prolog nl + prolog>> write-xml nl ] with-string-writer ; TUPLE: capitalized-prolog < xml-error-at name ; @@ -258,7 +258,7 @@ M: misplaced-directive summary ( obj -- str ) [ dup call-next-method write "Misplaced directive:" print - dir>> write-xml-chunk nl + dir>> write-xml nl ] with-string-writer ; TUPLE: bad-name < xml-error-at name ; diff --git a/basis/xml/interpolate/interpolate-tests.factor b/basis/xml/interpolate/interpolate-tests.factor index 35c4e793ea..9be85a11e2 100644 --- a/basis/xml/interpolate/interpolate-tests.factor +++ b/basis/xml/interpolate/interpolate-tests.factor @@ -51,8 +51,8 @@ IN: xml.interpolate.tests false=<-> url=<-> string=<-> word=<->/> XML> pprint-xml>string ] unit-test -[ "3" ] [ 3 [XML <-> XML] xml-chunk>string ] unit-test -[ "" ] [ f [XML <-> XML] xml-chunk>string ] unit-test +[ "3" ] [ 3 [XML <-> XML] xml>string ] unit-test +[ "" ] [ f [XML <-> XML] xml>string ] unit-test \ parsed ] dip [ \ interpolate-xml parsed ] when ; inline diff --git a/basis/xml/name/name.factor b/basis/xml/name/name.factor index 83132d4d29..1907a83a83 100644 --- a/basis/xml/name/name.factor +++ b/basis/xml/name/name.factor @@ -47,7 +47,7 @@ SYMBOL: ns-stack : valid-name? ( str -- ? ) [ f ] [ - version=1.0? swap { + version-1.0? swap { [ first name-start? ] [ rest-slice [ name-char? ] with all? ] } 2&& @@ -66,7 +66,7 @@ SYMBOL: ns-stack ] ?if ; : take-name ( -- string ) - version=1.0? '[ _ get-char name-char? not ] take-until ; + version-1.0? '[ _ get-char name-char? not ] take-until ; : parse-name ( -- name ) take-name interpret-name ; diff --git a/basis/xml/state/state.factor b/basis/xml/state/state.factor index 059d8267a0..eba94220e3 100644 --- a/basis/xml/state/state.factor +++ b/basis/xml/state/state.factor @@ -3,7 +3,7 @@ USING: accessors kernel namespaces io ; IN: xml.state -TUPLE: spot char line column next check ; +TUPLE: spot char line column next check version-1.0? ; C: spot @@ -17,11 +17,12 @@ C: spot : set-next ( char -- ) spot get swap >>next drop ; : get-check ( -- ? ) spot get check>> ; : check ( -- ) spot get t >>check drop ; +: version-1.0? ( -- ? ) spot get version-1.0?>> ; +: set-version ( string -- ) + spot get swap "1.0" = >>version-1.0? drop ; SYMBOL: xml-stack -SYMBOL: prolog-data - SYMBOL: depth SYMBOL: interpolating? diff --git a/basis/xml/tests/templating.factor b/basis/xml/tests/templating.factor index b35d7372e3..618e785d05 100644 --- a/basis/xml/tests/templating.factor +++ b/basis/xml/tests/templating.factor @@ -9,10 +9,10 @@ SYMBOL: ref-table GENERIC: (r-ref) ( xml -- ) M: tag (r-ref) - sub-tag over at* [ + dup sub-tag attr [ ref-table get at >>children drop - ] [ 2drop ] if ; + ] [ drop ] if* ; M: object (r-ref) drop ; : template ( xml -- ) diff --git a/basis/xml/tests/test.factor b/basis/xml/tests/test.factor index 97793f2ab2..337c19bfe1 100644 --- a/basis/xml/tests/test.factor +++ b/basis/xml/tests/test.factor @@ -51,14 +51,18 @@ SYMBOL: xml-file [ "foo" ] [ "" string>xml children>string ] unit-test [ "" string>xml ] must-fail [ ] [ "" string>xml drop ] unit-test -[ T{ element-decl f "br" "EMPTY" } ] [ "" string>dtd directives>> first ] unit-test -[ T{ element-decl f "p" "(#PCDATA|emph)*" } ] [ "" string>dtd directives>> first ] unit-test -[ T{ element-decl f "%name.para;" "%content.para;" } ] [ "" string>dtd directives>> first ] unit-test -[ T{ element-decl f "container" "ANY" } ] [ "" string>dtd directives>> first ] unit-test -[ T{ doctype-decl f "foo" } ] [ "" string>xml-chunk first ] unit-test -[ T{ doctype-decl f "foo" } ] [ "" string>xml-chunk first ] unit-test -[ T{ doctype-decl f "foo" T{ system-id f "blah.dtd" } } ] [ "" string>xml-chunk first ] unit-test -[ T{ doctype-decl f "foo" T{ system-id f "blah.dtd" } } ] [ "" string>xml-chunk first ] unit-test + +: first-thing ( seq -- elt ) + [ "" = not ] filter first ; + +[ T{ element-decl f "br" "EMPTY" } ] [ "" string>dtd directives>> first-thing ] unit-test +[ T{ element-decl f "p" "(#PCDATA|emph)*" } ] [ "" string>dtd directives>> first-thing ] unit-test +[ T{ element-decl f "%name.para;" "%content.para;" } ] [ "" string>dtd directives>> first-thing ] unit-test +[ T{ element-decl f "container" "ANY" } ] [ "" string>dtd directives>> first-thing ] unit-test +[ T{ doctype-decl f "foo" } ] [ "" string>xml-chunk first-thing ] unit-test +[ T{ doctype-decl f "foo" } ] [ "" string>xml-chunk first-thing ] unit-test +[ T{ doctype-decl f "foo" T{ system-id f "blah.dtd" } } ] [ "" string>xml-chunk first-thing ] unit-test +[ T{ doctype-decl f "foo" T{ system-id f "blah.dtd" } } ] [ "" string>xml-chunk first-thing ] unit-test [ 958 ] [ [ "ξ" string>xml-chunk ] with-html-entities first first ] unit-test [ "x" "<" ] [ "" string>xml [ name>> main>> ] [ "value" attr ] bi ] unit-test [ "foo" ] [ "]>&bar;" string>xml children>string ] unit-test diff --git a/basis/xml/tests/xmltest.factor b/basis/xml/tests/xmltest.factor index a6a28e15a3..a8024ce151 100644 --- a/basis/xml/tests/xmltest.factor +++ b/basis/xml/tests/xmltest.factor @@ -11,7 +11,7 @@ TUPLE: xml-test id uri sections description type ; [ "ID" attr >>id ] [ "URI" attr >>uri ] [ "SECTIONS" attr >>sections ] - [ children>> xml-chunk>string >>description ] + [ children>> xml>string >>description ] } cleave ; : parse-tests ( xml -- tests ) diff --git a/basis/xml/tokenize/tokenize.factor b/basis/xml/tokenize/tokenize.factor index b629d46455..50ab43ca7b 100644 --- a/basis/xml/tokenize/tokenize.factor +++ b/basis/xml/tokenize/tokenize.factor @@ -6,12 +6,9 @@ circular xml.entities assocs make splitting math.parser locals combinators arrays ; IN: xml.tokenize -: version=1.0? ( -- ? ) - prolog-data get [ version>> "1.0" = ] [ t ] if* ; - : assure-good-char ( ch -- ch ) [ - version=1.0? over text? not get-check and + version-1.0? over text? not get-check and [ disallowed-char ] when ] [ f ] if* ; @@ -36,7 +33,7 @@ IN: xml.tokenize get-char [ unexpected-end ] unless (next) record ; : init-parser ( -- ) - 0 1 0 f f spot set + 0 1 0 f f t spot set read1 set-next next ; : with-state ( stream quot -- ) diff --git a/basis/xml/utilities/utilities.factor b/basis/xml/utilities/utilities.factor index 48cbeceb22..924ae56aa4 100644 --- a/basis/xml/utilities/utilities.factor +++ b/basis/xml/utilities/utilities.factor @@ -38,7 +38,7 @@ IN: xml.utilities tags@ swap [ tag-named? ] with filter ; : tag-with-attr? ( elem attr-value attr-name -- ? ) - rot dup tag? [ at = ] [ 3drop f ] if ; + rot dup tag? [ swap attr = ] [ 3drop f ] if ; : tag-with-attr ( tag attr-value attr-name -- matching-tag ) assure-name '[ _ _ tag-with-attr? ] find nip ; diff --git a/basis/xml/writer/writer-docs.factor b/basis/xml/writer/writer-docs.factor index b470403e84..38f97bd5f8 100644 --- a/basis/xml/writer/writer-docs.factor +++ b/basis/xml/writer/writer-docs.factor @@ -1,56 +1,67 @@ ! Copyright (C) 2005, 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. -USING: help.syntax help.markup io strings ; +USING: help.syntax help.markup io strings xml.data multiline ; IN: xml.writer ABOUT: "xml.writer" ARTICLE: "xml.writer" "Writing XML" - "These words are used in implementing prettyprint" - { $subsection write-xml-chunk } - "These words are used to print XML normally" - { $subsection xml>string } + "These words are used to print XML preserving whitespace in text nodes" { $subsection write-xml } + { $subsection xml>string } "These words are used to prettyprint XML" { $subsection pprint-xml>string } - { $subsection pprint-xml>string-but } { $subsection pprint-xml } - { $subsection pprint-xml-but } ; - -HELP: write-xml-chunk -{ $values { "object" "an XML element" } } -{ $description "writes an XML element to " { $link output-stream } "." } -{ $see-also write-xml-chunk write-xml } ; + "Certain variables can be changed to mainpulate prettyprinting" + { $subsection sensitive-tags } + { $subsection indenter } + "All of these words operate on arbitrary pieces of XML: they can take, as in put, XML documents, comments, tags, strings (text nodes), XML chunks, etc." ; HELP: xml>string -{ $values { "xml" "an xml document" } { "string" "a string" } } -{ $description "converts an XML document into a string" } -{ $notes "does not preserve what type of quotes were used or what data was omitted from version declaration" } ; +{ $values { "xml" "an XML document" } { "string" "a string" } } +{ $description "This converts an XML document " { $link xml } " into a string. It can also be used to convert any piece of XML to a string, eg an " { $link xml-chunk } " or " { $link comment } "." } +{ $notes "This does not preserve what type of quotes were used or what data was omitted from version declaration, as that information isn't present in the XML data representation. The whitespace in the text nodes of the original document is preserved." } ; HELP: pprint-xml>string -{ $values { "xml" "an xml document" } { "string" "a string" } } +{ $values { "xml" "an XML document" } { "string" "a string" } } { $description "converts an XML document into a string in a prettyprinted form." } -{ $notes "does not preserve what type of quotes were used or what data was omitted from version declaration" } ; +{ $notes "This does not preserve what type of quotes were used or what data was omitted from version declaration, as that information isn't present in the XML data representation. The whitespace in the text nodes of the original document is preserved." } ; HELP: write-xml { $values { "xml" "an XML document" } } { $description "prints the contents of an XML document to " { $link output-stream } "." } -{ $notes "does not preserve what type of quotes were used or what data was omitted from version declaration" } ; +{ $notes "This does not preserve what type of quotes were used or what data was omitted from version declaration, as that information isn't present in the XML data representation. The whitespace in the text nodes of the original document is preserved." } ; HELP: pprint-xml { $values { "xml" "an XML document" } } { $description "prints the contents of an XML document to " { $link output-stream } " in a prettyprinted form." } -{ $notes "does not preserve what type of quotes were used or what data was omitted from version declaration" } ; +{ $notes "This does not preserve what type of quotes were used or what data was omitted from version declaration, as that information isn't present in the XML data representation. Whitespace is also not preserved." } ; -HELP: pprint-xml-but -{ $values { "xml" "an XML document" } { "sensitive-tags" "a sequence of names" } } -{ $description "Prettyprints an XML document, leaving the whitespace of the tags with names in sensitive-tags intact." } -{ $notes "does not preserve what type of quotes were used or what data was omitted from version declaration" } ; +{ xml>string write-xml pprint-xml pprint-xml>string } related-words -HELP: pprint-xml>string-but -{ $values { "xml" "an XML document" } { "sensitive-tags" "a sequence of names" } { "string" string } } -{ $description "Prettyprints an XML document, returning the result as a string and leaving the whitespace of the tags with names in sensitive-tags intact." } -{ $notes "does not preserve what type of quotes were used or what data was omitted from version declaration" } ; - -{ xml>string write-xml pprint-xml pprint-xml>string pprint-xml>string-but pprint-xml-but } related-words +HELP: indenter +{ $var-description "Contains the string which is used for indenting in the XML prettyprinter. For example, to print an XML document using " { $snippet "%%%%" } " for indentation, you can use the following:" } +{ $example {" USING: xml.interpolate xml.writer namespaces ; +[XML bar XML] "%%%%" indenter [ pprint-xml ] with-variable "} {" + +%%%%bar +"} } ; +HELP: sensitive-tags +{ $var-description "Contains a sequence of " { $link name } "s where whitespace should be considered significant for prettyprinting purposes. The sequence can contain " { $link string } "s in place of names. For example, to preserve whitespace inside a " { $snippet "pre" } " tag:" } +{ $example {" USING: xml.interpolate xml.writer namespaces ; +[XML something
bing
+bang
+   bong
XML] { "pre" } sensitive-tags [ pprint-xml ] with-variable "} {" + + + + something + + + +
bing
+bang
+   bong
+ +"} } ; diff --git a/basis/xml/writer/writer-tests.factor b/basis/xml/writer/writer-tests.factor index dcf7f1023d..d09ae08b3f 100644 --- a/basis/xml/writer/writer-tests.factor +++ b/basis/xml/writer/writer-tests.factor @@ -7,7 +7,7 @@ IN: xml.writer.tests \ write-xml must-infer \ xml>string must-infer \ pprint-xml must-infer -\ pprint-xml-but must-infer +! Add a test for pprint-xml with sensitive-tags [ "foo" ] [ T{ name { main "foo" } } name>string ] unit-test [ "foo" ] [ T{ name { space "" } { main "foo" } } name>string ] unit-test @@ -51,11 +51,11 @@ IN: xml.writer.tests ]> &foo;"} pprint-reprints-as -[ t ] [ "" dup string>xml-chunk xml-chunk>string = ] unit-test +[ t ] [ "" dup string>xml-chunk xml>string = ] unit-test [ "
" ] [ "" string>xml xml>string ] unit-test [ "bar baz" ] [ "bar" string>xml [ " baz" append ] map xml>string ] unit-test [ "\n\n bar\n" ] [ " bar " string>xml pprint-xml>string ] unit-test -[ "" ] [ "" xml-chunk>string ] unit-test +[ "" ] [ "" xml>string ] unit-test diff --git a/basis/xml/writer/writer.factor b/basis/xml/writer/writer.factor index 8e2dc4bfbf..92bc18054a 100644 --- a/basis/xml/writer/writer.factor +++ b/basis/xml/writer/writer.factor @@ -5,14 +5,15 @@ assocs combinators io io.streams.string accessors xml.data wrap xml.entities unicode.categories fry ; IN: xml.writer -SYMBOL: xml-pprint? SYMBOL: sensitive-tags -SYMBOL: indentation SYMBOL: indenter " " indenter set-global " write ; -M: contained-tag write-xml-chunk +M: contained-tag write-xml write-tag "/>" write ; : write-children ( tag -- ) indent children>> ?filter-children - [ write-xml-chunk ] each unindent ; + [ write-xml ] each unindent ; : write-end-tag ( tag -- ) ?indent " write1 ; -M: open-tag write-xml-chunk +M: open-tag write-xml xml-pprint? get [ { - [ sensitive? not xml-pprint? get and xml-pprint? set ] [ write-start-tag ] + [ sensitive? not xml-pprint? get and xml-pprint? set ] [ write-children ] [ write-end-tag ] } cleave ] dip xml-pprint? set ; -M: unescaped write-xml-chunk +M: unescaped write-xml string>> write ; -M: comment write-xml-chunk +M: comment write-xml "" write ; -M: element-decl write-xml-chunk - "> write " " write ] - [ content-spec>> write ">" write ] - bi ; +: write-decl ( decl name quot: ( decl -- slot ) -- ) + "> write bl ] + swap '[ @ write ">" write ] bi ; inline -M: attlist-decl write-xml-chunk - "> write " " write ] - [ att-defs>> write ">" write ] - bi ; +M: element-decl write-xml + "ELEMENT" [ content-spec>> ] write-decl ; -M: notation-decl write-xml-chunk - "> write " " write ] - [ id>> write ">" write ] - bi ; +M: attlist-decl write-xml + "ATTLIST" [ att-defs>> ] write-decl ; -M: entity-decl write-xml-chunk +M: notation-decl write-xml + "NOTATION" [ id>> ] write-decl ; + +M: entity-decl write-xml "> [ " % " write ] when ] [ name>> write " \"" write ] [ def>> f xml-pprint? - [ write-xml-chunk ] with-variable + [ write-xml ] with-variable "\">" write ] tri ; -M: system-id write-xml-chunk - "SYSTEM '" write system-literal>> write "'" write ; +M: system-id write-xml + "SYSTEM" write bl system-literal>> write-quoted ; -M: public-id write-xml-chunk - "PUBLIC '" write - [ pubid-literal>> write "' '" write ] - [ system-literal>> write "'" write ] bi ; +M: public-id write-xml + "PUBLIC" write bl + [ pubid-literal>> write-quoted bl ] + [ system-literal>> write-quoted ] bi ; : write-internal-subset ( dtd -- ) [ "[" write indent - directives>> [ ?indent write-xml-chunk ] each + directives>> [ ?indent write-xml ] each unindent ?indent "]" write ] when* ; -M: doctype-decl write-xml-chunk +M: doctype-decl write-xml ?indent "> write " " write ] - [ external-id>> [ write-xml-chunk " " write ] when* ] + [ external-id>> [ write-xml " " write ] when* ] [ internal-subset>> write-internal-subset ">" write ] tri ; -M: directive write-xml-chunk +M: directive write-xml "> write CHAR: > write1 nl ; -M: instruction write-xml-chunk +M: instruction write-xml "> write "?>" write ; -M: number write-xml-chunk +M: number write-xml "Numbers are not allowed in XML" throw ; -M: sequence write-xml-chunk - [ write-xml-chunk ] each ; +M: sequence write-xml + [ write-xml ] each ; -PRIVATE> +M: prolog write-xml + "> write-quoted ] + [ " encoding=" write encoding>> write-quoted ] + [ standalone>> [ " standalone=\"yes\"" write ] when ] tri + "?>" write ; -: write-prolog ( xml -- ) - "> write - "\" encoding=\"" write dup encoding>> write - standalone>> [ "\" standalone=\"yes" write ] when - "\"?>" write ; - -: write-xml ( xml -- ) +M: xml write-xml { - [ prolog>> write-prolog ] - [ before>> write-xml-chunk ] - [ body>> write-xml-chunk ] - [ after>> write-xml-chunk ] + [ prolog>> write-xml ] + [ before>> write-xml ] + [ body>> write-xml ] + [ after>> write-xml ] } cleave ; -M: xml write-xml-chunk - body>> write-xml-chunk ; +PRIVATE> : xml>string ( xml -- string ) [ write-xml ] with-string-writer ; -: xml-chunk>string ( object -- string ) - [ write-xml-chunk ] with-string-writer ; - -: pprint-xml-but ( xml sensitive-tags -- ) +: pprint-xml ( xml -- ) [ - [ assure-name ] map sensitive-tags set + sensitive-tags [ [ assure-name ] map ] change 0 indentation set xml-pprint? on write-xml ] with-scope ; -: pprint-xml ( xml -- ) - f pprint-xml-but ; - -: pprint-xml>string-but ( xml sensitive-tags -- string ) - [ pprint-xml-but ] with-string-writer ; - : pprint-xml>string ( xml -- string ) - f pprint-xml>string-but ; + [ pprint-xml ] with-string-writer ; diff --git a/basis/xml/xml-docs.factor b/basis/xml/xml-docs.factor index 26d4319b5e..901fce2dd4 100644 --- a/basis/xml/xml-docs.factor +++ b/basis/xml/xml-docs.factor @@ -20,21 +20,20 @@ HELP: file>xml HELP: read-xml-chunk { $values { "stream" "an input stream" } { "seq" "a sequence of elements" } } -{ $description "Rather than parse a document, as " { $link read-xml } " does, this word parses and returns a sequence of XML elements (tags, strings, etc), ie a document fragment. This is useful for pieces of XML which may have more than one main tag." } +{ $description "Rather than parse a document, as " { $link read-xml } " does, this word parses and returns a sequence of XML elements (tags, strings, etc), ie a document fragment. This is useful for pieces of XML which may have more than one main tag. The encoding is not automatically detected, and a stream with an encoding (ie. one which returns strings from " { $link read } ") should be used as input." } { $see-also read-xml } ; HELP: each-element { $values { "stream" "an input stream" } { "quot" "a quotation ( xml-elem -- )" } } -{ $description "Parses the XML document, and whenever an event is encountered (a tag piece, comment, parsing instruction, directive or string element), the quotation is called with that event on the stack. The quotation has all responsibility to deal with the event properly, and it is advised that generic words be used in dispatching on the event class." } -{ $notes "It is important to note that this is not SAX, merely an event-based XML view" } +{ $description "Parses the XML document, and whenever an event is encountered (a tag piece, comment, parsing instruction, directive or string element), the quotation is called with that event on the stack. The quotation has all responsibility to deal with the event properly. The encoding of the stream is automatically detected, so a binary input stream should be used." } { $see-also read-xml } ; HELP: pull-xml -{ $class-description "Represents the state of a pull-parser for XML. Has one slot, scope, which is a namespace which contains all relevant state information." } +{ $class-description "Represents the state of a pull-parser for XML. Has one slot, " { $snippet "scope" } ", which is a namespace which contains all relevant state information." } { $see-also pull-event pull-elem } ; HELP: -{ $values { "pull-xml" "a pull-xml tuple" } } +{ $values { "pull-xml" pull-xml } } { $description "Creates an XML pull-based parser which reads from " { $link input-stream } ", executing all initial XML commands to set up the parser." } { $see-also pull-xml pull-elem pull-event } ; @@ -87,7 +86,7 @@ ARTICLE: { "xml" "events" } "Event-based XML parsing" { $subsection pull-elem } ; ARTICLE: "xml" "XML parser" -"The " { $vocab-link "xml" } " vocabulary implements the XML 1.0 and 1.1 standards, converting strings of text into XML and vice versa." +"The " { $vocab-link "xml" } " vocabulary implements the XML 1.0 and 1.1 standards, converting strings of text into XML and vice versa. The parser checks for well-formedness but is not validating. There is only partial support for processing DTDs." { $subsection { "xml" "reading" } } { $subsection { "xml" "events" } } { $vocab-subsection "Writing XML" "xml.writer" } diff --git a/basis/xml/xml.factor b/basis/xml/xml.factor index 5369b04d9c..fd749ce905 100644 --- a/basis/xml/xml.factor +++ b/basis/xml/xml.factor @@ -3,7 +3,8 @@ USING: accessors arrays io io.encodings.binary io.files io.streams.string kernel namespaces sequences strings io.encodings.utf8 xml.data xml.errors xml.elements ascii xml.entities -xml.writer xml.state xml.autoencoding assocs xml.tokenize xml.name ; +xml.writer xml.state xml.autoencoding assocs xml.tokenize +combinators.short-circuit xml.name ; IN: xml > ] [ attrs>> ] bi @@ -49,17 +54,14 @@ M: closer process : init-xml-stack ( -- ) V{ } clone xml-stack set - extra-entities [ H{ } assoc-like ] change f push-xml ; : default-prolog ( -- prolog ) "1.0" "UTF-8" f ; -: reset-prolog ( -- ) - default-prolog prolog-data set ; - : init-xml ( -- ) - reset-prolog init-xml-stack init-ns-stack ; + init-ns-stack + extra-entities [ H{ } assoc-like ] change ; : assert-blanks ( seq pre? -- ) swap [ string? ] filter @@ -80,7 +82,11 @@ M: closer process ! this does *not* affect the contents of the stack [ notags ] unless* ; -: make-xml-doc ( prolog seq -- xml-doc ) +: get-prolog ( seq -- prolog ) + first dup prolog? [ drop default-prolog ] unless ; + +: make-xml-doc ( seq -- xml-doc ) + [ get-prolog ] keep dup [ tag? ] find [ assure-tags cut rest no-pre/post no-post-tags ] dip swap ; @@ -95,8 +101,7 @@ TUPLE: pull-xml scope ; : ( -- pull-xml ) [ input-stream [ ] change ! bring var in this scope - init-parser reset-prolog init-ns-stack - text-now? on + init-xml text-now? on ] H{ } make-assoc pull-xml boa ; ! pull-xml needs to call start-document somewhere @@ -135,50 +140,43 @@ PRIVATE> get-char [ make-tag call-under xml-loop ] [ drop ] if ; inline recursive +: read-seq ( stream quot n -- seq ) + rot [ + depth set + init-xml init-xml-stack + call + [ process ] xml-loop + done? [ unclosed ] unless + xml-stack get first second + ] with-state ; inline + PRIVATE> : each-element ( stream quot: ( xml-elem -- ) -- ) swap [ - reset-prolog init-ns-stack + init-xml start-document [ call-under ] when* xml-loop ] with-state ; inline -: (read-xml) ( -- ) - start-document [ process ] when* - [ process ] xml-loop ; inline - -: (read-xml-chunk) ( stream -- prolog seq ) - [ - init-xml (read-xml) - done? [ unclosed ] unless - xml-stack get first second - prolog-data get swap - ] with-state ; - : read-xml ( stream -- xml ) - 0 depth - [ (read-xml-chunk) make-xml-doc ] with-variable ; + [ start-document [ process ] when* ] + 0 read-seq make-xml-doc ; : read-xml-chunk ( stream -- seq ) - 1 depth - [ (read-xml-chunk) nip ] with-variable - ; + [ check ] 1 read-seq ; : string>xml ( string -- xml ) - t string-input? - [ read-xml ] with-variable ; + [ check ] 0 read-seq make-xml-doc ; : string>xml-chunk ( string -- xml ) - t string-input? - [ read-xml-chunk ] with-variable ; + read-xml-chunk ; : file>xml ( filename -- xml ) binary read-xml ; : read-dtd ( stream -- dtd ) [ - reset-prolog H{ } clone extra-entities set take-internal-subset ] with-state ; diff --git a/basis/xmode/loader/syntax/syntax.factor b/basis/xmode/loader/syntax/syntax.factor index 9b53000e02..f63191d5f6 100644 --- a/basis/xmode/loader/syntax/syntax.factor +++ b/basis/xmode/loader/syntax/syntax.factor @@ -31,7 +31,7 @@ SYMBOL: ignore-case? ! PROP, PROPS : parse-prop-tag ( tag -- key value ) - "NAME" over at "VALUE" rot at ; + [ "NAME" attr ] [ "VALUE" attr ] bi ; : parse-props-tag ( tag -- assoc ) child-tags @@ -40,7 +40,7 @@ SYMBOL: ignore-case? : position-attrs ( tag -- at-line-start? at-whitespace-end? at-word-start? ) ! XXX Wrong logic! { "AT_LINE_START" "AT_WHITESPACE_END" "AT_WORD_START" } - swap [ at string>boolean ] curry map first3 ; + [ attr string>boolean ] with map first3 ; : parse-literal-matcher ( tag -- matcher ) dup children>string diff --git a/extra/4DNav/4DNav-docs.factor b/unmaintained/4DNav/4DNav-docs.factor similarity index 100% rename from extra/4DNav/4DNav-docs.factor rename to unmaintained/4DNav/4DNav-docs.factor diff --git a/extra/4DNav/4DNav.factor b/unmaintained/4DNav/4DNav.factor similarity index 100% rename from extra/4DNav/4DNav.factor rename to unmaintained/4DNav/4DNav.factor diff --git a/extra/4DNav/authors.txt b/unmaintained/4DNav/authors.txt similarity index 100% rename from extra/4DNav/authors.txt rename to unmaintained/4DNav/authors.txt diff --git a/extra/4DNav/camera/authors.txt b/unmaintained/4DNav/camera/authors.txt similarity index 100% rename from extra/4DNav/camera/authors.txt rename to unmaintained/4DNav/camera/authors.txt diff --git a/extra/4DNav/camera/camera-docs.factor b/unmaintained/4DNav/camera/camera-docs.factor similarity index 100% rename from extra/4DNav/camera/camera-docs.factor rename to unmaintained/4DNav/camera/camera-docs.factor diff --git a/extra/4DNav/camera/camera.factor b/unmaintained/4DNav/camera/camera.factor similarity index 100% rename from extra/4DNav/camera/camera.factor rename to unmaintained/4DNav/camera/camera.factor diff --git a/extra/4DNav/deep/deep-docs.factor b/unmaintained/4DNav/deep/deep-docs.factor similarity index 100% rename from extra/4DNav/deep/deep-docs.factor rename to unmaintained/4DNav/deep/deep-docs.factor diff --git a/extra/4DNav/deep/deep.factor b/unmaintained/4DNav/deep/deep.factor similarity index 100% rename from extra/4DNav/deep/deep.factor rename to unmaintained/4DNav/deep/deep.factor diff --git a/extra/4DNav/deploy.factor b/unmaintained/4DNav/deploy.factor similarity index 100% rename from extra/4DNav/deploy.factor rename to unmaintained/4DNav/deploy.factor diff --git a/extra/4DNav/file-chooser/authors.txt b/unmaintained/4DNav/file-chooser/authors.txt similarity index 100% rename from extra/4DNav/file-chooser/authors.txt rename to unmaintained/4DNav/file-chooser/authors.txt diff --git a/extra/4DNav/file-chooser/file-chooser.factor b/unmaintained/4DNav/file-chooser/file-chooser.factor similarity index 100% rename from extra/4DNav/file-chooser/file-chooser.factor rename to unmaintained/4DNav/file-chooser/file-chooser.factor diff --git a/extra/4DNav/hypercube.xml b/unmaintained/4DNav/hypercube.xml similarity index 100% rename from extra/4DNav/hypercube.xml rename to unmaintained/4DNav/hypercube.xml diff --git a/extra/4DNav/light_test.xml b/unmaintained/4DNav/light_test.xml similarity index 100% rename from extra/4DNav/light_test.xml rename to unmaintained/4DNav/light_test.xml diff --git a/extra/4DNav/multi solids.xml b/unmaintained/4DNav/multi solids.xml similarity index 100% rename from extra/4DNav/multi solids.xml rename to unmaintained/4DNav/multi solids.xml diff --git a/extra/4DNav/prismetriagone.xml b/unmaintained/4DNav/prismetriagone.xml similarity index 100% rename from extra/4DNav/prismetriagone.xml rename to unmaintained/4DNav/prismetriagone.xml diff --git a/extra/4DNav/space-file-decoder/authors.txt b/unmaintained/4DNav/space-file-decoder/authors.txt similarity index 100% rename from extra/4DNav/space-file-decoder/authors.txt rename to unmaintained/4DNav/space-file-decoder/authors.txt diff --git a/extra/4DNav/space-file-decoder/space-file-decoder-docs.factor b/unmaintained/4DNav/space-file-decoder/space-file-decoder-docs.factor similarity index 100% rename from extra/4DNav/space-file-decoder/space-file-decoder-docs.factor rename to unmaintained/4DNav/space-file-decoder/space-file-decoder-docs.factor diff --git a/extra/4DNav/space-file-decoder/space-file-decoder.factor b/unmaintained/4DNav/space-file-decoder/space-file-decoder.factor similarity index 100% rename from extra/4DNav/space-file-decoder/space-file-decoder.factor rename to unmaintained/4DNav/space-file-decoder/space-file-decoder.factor diff --git a/extra/4DNav/summary.txt b/unmaintained/4DNav/summary.txt similarity index 100% rename from extra/4DNav/summary.txt rename to unmaintained/4DNav/summary.txt diff --git a/extra/4DNav/tags.txt b/unmaintained/4DNav/tags.txt similarity index 100% rename from extra/4DNav/tags.txt rename to unmaintained/4DNav/tags.txt diff --git a/extra/4DNav/triancube.xml b/unmaintained/4DNav/triancube.xml similarity index 100% rename from extra/4DNav/triancube.xml rename to unmaintained/4DNav/triancube.xml diff --git a/extra/4DNav/turtle/authors.txt b/unmaintained/4DNav/turtle/authors.txt similarity index 100% rename from extra/4DNav/turtle/authors.txt rename to unmaintained/4DNav/turtle/authors.txt diff --git a/extra/4DNav/turtle/turtle-docs.factor b/unmaintained/4DNav/turtle/turtle-docs.factor similarity index 100% rename from extra/4DNav/turtle/turtle-docs.factor rename to unmaintained/4DNav/turtle/turtle-docs.factor diff --git a/extra/4DNav/turtle/turtle.factor b/unmaintained/4DNav/turtle/turtle.factor similarity index 100% rename from extra/4DNav/turtle/turtle.factor rename to unmaintained/4DNav/turtle/turtle.factor diff --git a/extra/4DNav/window3D/authors.txt b/unmaintained/4DNav/window3D/authors.txt similarity index 100% rename from extra/4DNav/window3D/authors.txt rename to unmaintained/4DNav/window3D/authors.txt diff --git a/extra/4DNav/window3D/window3D-docs.factor b/unmaintained/4DNav/window3D/window3D-docs.factor similarity index 100% rename from extra/4DNav/window3D/window3D-docs.factor rename to unmaintained/4DNav/window3D/window3D-docs.factor diff --git a/extra/4DNav/window3D/window3D.factor b/unmaintained/4DNav/window3D/window3D.factor similarity index 100% rename from extra/4DNav/window3D/window3D.factor rename to unmaintained/4DNav/window3D/window3D.factor diff --git a/extra/adsoda/adsoda-docs.factor b/unmaintained/adsoda/adsoda-docs.factor similarity index 100% rename from extra/adsoda/adsoda-docs.factor rename to unmaintained/adsoda/adsoda-docs.factor diff --git a/extra/adsoda/adsoda-tests.factor b/unmaintained/adsoda/adsoda-tests.factor similarity index 100% rename from extra/adsoda/adsoda-tests.factor rename to unmaintained/adsoda/adsoda-tests.factor diff --git a/extra/adsoda/adsoda.factor b/unmaintained/adsoda/adsoda.factor similarity index 100% rename from extra/adsoda/adsoda.factor rename to unmaintained/adsoda/adsoda.factor diff --git a/extra/adsoda/adsoda.tests b/unmaintained/adsoda/adsoda.tests similarity index 100% rename from extra/adsoda/adsoda.tests rename to unmaintained/adsoda/adsoda.tests diff --git a/extra/adsoda/authors.txt b/unmaintained/adsoda/authors.txt similarity index 100% rename from extra/adsoda/authors.txt rename to unmaintained/adsoda/authors.txt diff --git a/extra/adsoda/combinators/authors.txt b/unmaintained/adsoda/combinators/authors.txt similarity index 100% rename from extra/adsoda/combinators/authors.txt rename to unmaintained/adsoda/combinators/authors.txt diff --git a/extra/adsoda/combinators/combinators-docs.factor b/unmaintained/adsoda/combinators/combinators-docs.factor similarity index 100% rename from extra/adsoda/combinators/combinators-docs.factor rename to unmaintained/adsoda/combinators/combinators-docs.factor diff --git a/extra/adsoda/combinators/combinators-tests.factor b/unmaintained/adsoda/combinators/combinators-tests.factor similarity index 100% rename from extra/adsoda/combinators/combinators-tests.factor rename to unmaintained/adsoda/combinators/combinators-tests.factor diff --git a/extra/adsoda/combinators/combinators.factor b/unmaintained/adsoda/combinators/combinators.factor similarity index 100% rename from extra/adsoda/combinators/combinators.factor rename to unmaintained/adsoda/combinators/combinators.factor diff --git a/extra/adsoda/solution2/solution2.factor b/unmaintained/adsoda/solution2/solution2.factor similarity index 100% rename from extra/adsoda/solution2/solution2.factor rename to unmaintained/adsoda/solution2/solution2.factor diff --git a/extra/adsoda/solution2/summary.txt b/unmaintained/adsoda/solution2/summary.txt similarity index 100% rename from extra/adsoda/solution2/summary.txt rename to unmaintained/adsoda/solution2/summary.txt diff --git a/extra/adsoda/summary.txt b/unmaintained/adsoda/summary.txt similarity index 100% rename from extra/adsoda/summary.txt rename to unmaintained/adsoda/summary.txt diff --git a/extra/adsoda/tags.txt b/unmaintained/adsoda/tags.txt similarity index 100% rename from extra/adsoda/tags.txt rename to unmaintained/adsoda/tags.txt diff --git a/extra/adsoda/tools/authors.txt b/unmaintained/adsoda/tools/authors.txt similarity index 100% rename from extra/adsoda/tools/authors.txt rename to unmaintained/adsoda/tools/authors.txt diff --git a/extra/adsoda/tools/tools-docs.factor b/unmaintained/adsoda/tools/tools-docs.factor similarity index 100% rename from extra/adsoda/tools/tools-docs.factor rename to unmaintained/adsoda/tools/tools-docs.factor diff --git a/extra/adsoda/tools/tools-tests.factor b/unmaintained/adsoda/tools/tools-tests.factor similarity index 100% rename from extra/adsoda/tools/tools-tests.factor rename to unmaintained/adsoda/tools/tools-tests.factor diff --git a/extra/adsoda/tools/tools.factor b/unmaintained/adsoda/tools/tools.factor similarity index 100% rename from extra/adsoda/tools/tools.factor rename to unmaintained/adsoda/tools/tools.factor diff --git a/extra/ui/gadgets/plot/plot.factor b/unmaintained/ui/gadgets/plot/plot.factor similarity index 100% rename from extra/ui/gadgets/plot/plot.factor rename to unmaintained/ui/gadgets/plot/plot.factor diff --git a/extra/ui/gadgets/slate/authors.txt b/unmaintained/ui/gadgets/slate/authors.txt similarity index 100% rename from extra/ui/gadgets/slate/authors.txt rename to unmaintained/ui/gadgets/slate/authors.txt diff --git a/extra/ui/gadgets/slate/slate.factor b/unmaintained/ui/gadgets/slate/slate.factor similarity index 100% rename from extra/ui/gadgets/slate/slate.factor rename to unmaintained/ui/gadgets/slate/slate.factor diff --git a/extra/ui/gadgets/tiling/tiling.factor b/unmaintained/ui/gadgets/tiling/tiling.factor similarity index 100% rename from extra/ui/gadgets/tiling/tiling.factor rename to unmaintained/ui/gadgets/tiling/tiling.factor