From 02b09fdca465dda07ea1512784981a22c3e16ab0 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 26 Jan 2009 16:11:30 -0600 Subject: [PATCH] Documentation, unit tests for XML --- basis/xml/data/data-docs.factor | 28 ++-- basis/xml/elements/elements.factor | 9 +- basis/xml/errors/errors-docs.factor | 60 ++++++-- basis/xml/errors/errors-tests.factor | 6 +- basis/xml/errors/errors.factor | 132 +++++++++--------- basis/xml/interpolate/interpolate-docs.factor | 58 ++++++++ .../xml/interpolate/interpolate-tests.factor | 10 +- basis/xml/interpolate/interpolate.factor | 24 ++-- basis/xml/tests/test.factor | 2 +- 9 files changed, 216 insertions(+), 113 deletions(-) create mode 100644 basis/xml/interpolate/interpolate-docs.factor diff --git a/basis/xml/data/data-docs.factor b/basis/xml/data/data-docs.factor index 9a8c535f91..52394ccc5c 100644 --- a/basis/xml/data/data-docs.factor +++ b/basis/xml/data/data-docs.factor @@ -4,7 +4,7 @@ IN: xml.data ABOUT: "xml.data" ARTICLE: "xml.data" "XML data types" -{ $vocab-link "xml.data" } " defines a simple document object model for XML. Everything is simply a tuple and can be manipulated as such." +"The " { $vocab-link "xml.data" } " vocabulary defines a simple document object model for XML. Everything is simply a tuple and can be manipulated as such." { $subsection { "xml.data" "classes" } } { $subsection { "xml.data" "constructors" } } "Simple words for manipulating names:" @@ -49,7 +49,7 @@ ARTICLE: { "xml.data" "constructors" } "XML data constructors" { $subsection } ; HELP: tag -{ $class-description "tuple representing an XML tag, delegating to a " { $link +{ $class-description "Tuple representing an XML tag, delegating to a " { $link name } ", containing the slots attrs (an alist of names to strings) and children (a sequence). Tags implement the sequence protocol by acting like a sequence of its chidren, and the assoc protocol by acting like its attributes." } { $see-also name contained-tag xml } ; @@ -58,32 +58,32 @@ HELP: { "attrs" "an alist of names to strings" } { "children" sequence } { "tag" tag } } -{ $description "constructs an XML " { $link tag } " with the name (not a string) and tag attributes specified in attrs and children specified" } +{ $description "Constructs an XML " { $link tag } " with the name (not a string) and tag attributes specified in attrs and children specified." } { $see-also tag } ; HELP: name -{ $class-description "represents an XML name, with the fields space (a string representing the namespace, as written in the document, tag (a string of the actual name of the tag) and url (a string of the URL that the namespace points to)" } +{ $class-description "Represents an XML name, with the fields space (a string representing the namespace, as written in the document, tag (a string of the actual name of the tag) and url (a string of the URL that the namespace points to)." } { $see-also tag } ; HELP: { $values { "space" "a string" } { "main" "a string" } { "url" "a string" } { "name" "an XML tag name" } } -{ $description "creates a name tuple with the name-space space and the tag-name tag and the tag-url url." } +{ $description "Creates a name tuple with the namespace prefix space, the the given main part of the name, and the namespace URL given by url." } { $see-also name } ; HELP: contained-tag -{ $class-description "delegates to tag representing a tag like with no contents. The tag attributes are accessed with tag-attrs" } +{ $class-description "This is a subclass of " { $link tag } " consisting of tags with no body, like " { $snippet "" } "." } { $see-also tag } ; HELP: { $values { "name" "an XML tag name" } { "attrs" "an alist from names to strings" } { "tag" tag } } -{ $description "creates an empty tag (like ) with the specified name and tag attributes. This delegates to tag" } +{ $description "Creates an empty tag (like " { $snippet "" } ") with the specified name and tag attributes." } { $see-also contained-tag } ; HELP: xml -{ $class-description "tuple representing an XML document, delegating to the main tag, containing the fields prolog (the header ), before (whatever comes between the prolog and the main tag) and after (whatever comes after the main tag)" } +{ $class-description "Tuple representing an XML document, delegating to the main tag, containing the fields prolog (the header " { $snippet "" } "), before (whatever comes between the prolog and the main tag) and after (whatever comes after the main tag)." } { $see-also tag prolog } ; HELP: @@ -159,35 +159,35 @@ HELP: { $description "Creates an element declaration object, of the class " { $link element-decl } } ; HELP: attlist-decl -{ $class-description "Describes the class of element declarations, like ." } ; +{ $class-description "Describes the class of element declarations, like " { $snippet "" } "." } ; HELP: { $values { "name" name } { "att-defs" string } { "attlist-decl" attlist-decl } } { $description "Creates an element declaration object, of the class " { $link attlist-decl } } ; HELP: entity-decl -{ $class-description "Describes the class of element declarations, like ." } ; +{ $class-description "Describes the class of element declarations, like " { $snippet "" } "." } ; HELP: { $values { "name" name } { "def" string } { "pe?" "t or f" } { "entity-decl" entity-decl } } -{ $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 and f if the object is like , that is, it can be used outside of the DTD." } ; +{ $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 " } ; +{ $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 } } { $description "Constructs a " { $link system-id } " tuple." } ; HELP: public-id -{ $class-description "Describes the class of public identifiers within an XML DTD directive, such as " } ; +{ $class-description "Describes the class of public identifiers within an XML DTD directive, such as " { $snippet "" } } ; HELP: { $values { "pubid-literal" string } { "system-literal" string } { "public-id" public-id } } { $description "Constructs a " { $link system-id } " tuple." } ; HELP: notation-decl -{ $class-description "Describes the class of element declarations, like ." } ; +{ $class-description "Describes the class of element declarations, like " { $snippet "" } "." } ; HELP: { $values { "name" string } { "id" id } { "notation-decl" notation-decl } } diff --git a/basis/xml/elements/elements.factor b/basis/xml/elements/elements.factor index b2280bacb4..57e91cc24e 100644 --- a/basis/xml/elements/elements.factor +++ b/basis/xml/elements/elements.factor @@ -3,16 +3,15 @@ USING: kernel namespaces xml.tokenize xml.state xml.name xml.data accessors arrays make xml.char-classes fry assocs sequences math xml.errors sets combinators io.encodings io.encodings.iana -unicode.case xml.dtd strings xml.entities ; +unicode.case xml.dtd strings xml.entities unicode.categories ; IN: xml.elements : take-interpolated ( quot -- interpolated ) interpolating? get [ drop get-char CHAR: > = - [ next f ] [ - pass-blank " \t\r\n-" take-to - pass-blank "->" expect - ] if + [ next f ] + [ "->" take-string [ blank? ] trim ] + if ] [ call ] if ; inline : interpolate-quote ( -- interpolated ) diff --git a/basis/xml/errors/errors-docs.factor b/basis/xml/errors/errors-docs.factor index b95aecc47a..46c4fbe466 100644 --- a/basis/xml/errors/errors-docs.factor +++ b/basis/xml/errors/errors-docs.factor @@ -10,44 +10,68 @@ HELP: notags { $class-description "XML parsing error describing the case where an XML document contains no main tag, or any tags at all" } ; HELP: extra-attrs -{ $class-description "XML parsing error describing the case where the XML prolog () 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 parsing-error } "." } ; +{ $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 } "." } ; 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 parsing-error } "." } ; +{ $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 } "." } ; 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 parsing-error } " 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 'yes' or 'no'. Delegates to " { $link xml-error-at } " and contains one slot, text, which contains offending value." } ; 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." } ; HELP: mismatched -{ $class-description "XML parsing error describing mismatched tags, eg . Contains two slots: open is the name of the opening tag and close is the name of the closing tag. Delegates to " { $link parsing-error } " showing the location of the closing tag" } ; +{ $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" } ; HELP: expected -{ $class-description "XML parsing error describing when an expected token was not present. Delegates to " { $link parsing-error } ". 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, should-be, which has the expected string, and 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 parsing-error } ". Contains one slot, thing, containing a string representing the 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." } ; 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" } ; +{ $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 quotation for an attribute value is opened but not closed before the end of the document." } ; 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." } ; 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." } ; -HELP: xml-parse-error -{ $class-description "the exception class that all parsing errors in XML documents are in." } ; +HELP: disallowed-char +{ $class-description "Describes the error where a disallowed character occurs in an XML document." } ; + +HELP: missing-close +{ $class-description "Describes the error where a particular closing token is missing." } ; + +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." } ; + +HELP: bad-cdata +{ $class-description "Describes the error where CDATA is used outside of the main tag of an XML document." } ; + +HELP: text-w/]]> +{ $class-description "Describes the error where a text node contains the literal string " { $snippet "]]>" } " which is disallowed." } ; + +HELP: attr-w/< +{ $class-description "Describes the error where an attribute value contains the literal character " { $snippet "<" } " which is disallowed." } ; + +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." } ; + +HELP: xml-error +{ $class-description "The exception class that all parsing errors in XML documents are in." } ; ARTICLE: "xml.errors" "XML parsing errors" - { $vocab-link "xml.errors" } " provides a rich and highly inspectable set of parsing errors. All XML errors are described by the union class " { $link xml-parse-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 } " but there are many classes contained in that:" { $subsection multitags } { $subsection notags } { $subsection extra-attrs } @@ -61,7 +85,15 @@ ARTICLE: "xml.errors" "XML parsing errors" { $subsection unclosed-quote } { $subsection bad-name } { $subsection quoteless-attr } - "Additionally, most of these errors are a kind of " { $link parsing-error } " which provides more information" + { $subsection disallowed-char } + { $subsection missing-close } + { $subsection unexpected-end } + { $subsection duplicate-attr } + { $subsection bad-cdata } + { $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" $nl "Note that, in parsing an XML document, only the first error is reported." ; diff --git a/basis/xml/errors/errors-tests.factor b/basis/xml/errors/errors-tests.factor index bf02f4b6ca..4204979941 100644 --- a/basis/xml/errors/errors-tests.factor +++ b/basis/xml/errors/errors-tests.factor @@ -27,12 +27,16 @@ T{ pre/post-content f "x" t } "x" xml-error-test T{ versionless-prolog f 1 8 } "" xml-error-test T{ unclosed-quote f 1 13 } "" xml-error-test T{ text-w/]]> f 1 6 } "]]>" xml-error-test T{ duplicate-attr f 1 21 T{ name { space "" } { main "this" } } V{ "a" "b" } } "" xml-error-test T{ bad-cdata f 1 3 } "" xml-error-test T{ bad-cdata f 1 7 } "" xml-error-test -T{ pre/post-content f "&" t } "&32;" xml-error-test +T{ pre/post-content f "&" t } " " xml-error-test T{ bad-doctype f 1 17 "a" } "" xml-error-test T{ bad-doctype f 1 22 T{ opener { name T{ name f "" "foo" "" } } { attrs T{ attrs } } } } " ]>" xml-error-test +T{ disallowed-char f 1 3 1 } "\u000001" xml-error-test +T{ missing-close f 1 9 } "