diff --git a/basis/eval/eval-tests.factor b/basis/eval/eval-tests.factor index db4b95acdc..675921944a 100644 --- a/basis/eval/eval-tests.factor +++ b/basis/eval/eval-tests.factor @@ -1,4 +1,4 @@ IN: eval.tests USING: eval tools.test ; -[ "4\n" ] [ "USING: math prettyprint ; 2 2 + ." eval>string ] unit-testv \ No newline at end of file +[ "4\n" ] [ "USING: math prettyprint ; 2 2 + ." eval>string ] unit-test diff --git a/basis/farkup/farkup-docs.factor b/basis/farkup/farkup-docs.factor index 8e7270cc01..8c6b07a01c 100644 --- a/basis/farkup/farkup-docs.factor +++ b/basis/farkup/farkup-docs.factor @@ -14,8 +14,8 @@ HELP: parse-farkup ( string -- farkup ) { $description "Parses Farkup and outputs a tree of " { $link "farkup-ast" } "." } ; HELP: (write-farkup) -{ $values { "farkup" "a Farkup syntax tree node" } } -{ $description "Writes a Farkup syntax tree as HTML on " { $link output-stream } "." } ; +{ $values { "farkup" "a Farkup syntax tree node" } { "xml" "an XML chunk" } } +{ $description "Converts a Farkup syntax tree node to XML." } ; ARTICLE: "farkup-ast" "Farkup syntax tree nodes" "The " { $link parse-farkup } " word outputs a tree of nodes corresponding to the Farkup syntax of the input string. This tree can be programatically traversed and mutated before being passed on to " { $link write-farkup } "." diff --git a/basis/formatting/formatting-docs.factor b/basis/formatting/formatting-docs.factor index 8db3567c23..196302f203 100644 --- a/basis/formatting/formatting-docs.factor +++ b/basis/formatting/formatting-docs.factor @@ -7,7 +7,7 @@ HELP: printf { $values { "format-string" string } } { $description "Writes the arguments (specified on the stack) formatted according to the format string.\n" - "\n" + $nl "Several format specifications exist for handling arguments of different types, and " "specifying attributes for the result string, including such things as maximum width, " "padding, and decimals.\n" @@ -24,10 +24,10 @@ HELP: printf { "%+Px" "Hexadecimal" "hex" } { "%+PX" "Hexadecimal uppercase" "hex" } } - "\n" + $nl "A plus sign ('+') is used to optionally specify that the number should be " "formatted with a '+' preceeding it if positive.\n" - "\n" + $nl "Padding ('P') is used to optionally specify the minimum width of the result " "string, the padding character, and the alignment. By default, the padding " "character defaults to a space and the alignment defaults to right-aligned. " @@ -38,7 +38,7 @@ HELP: printf "\"%'#5f\" formats a float padding with '#' up to 3 characters wide." "\"%-10d\" formats an integer to 10 characters wide and left-aligns." } - "\n" + $nl "Digits ('D') is used to optionally specify the maximum digits in the result " "string. For example:\n" { $list @@ -83,7 +83,7 @@ HELP: strftime { $values { "format-string" string } } { $description "Writes the timestamp (specified on the stack) formatted according to the format string.\n" - "\n" + $nl "Different attributes of the timestamp can be retrieved using format specifications.\n" { $table { "%a" "Abbreviated weekday name." } @@ -118,7 +118,7 @@ HELP: strftime } ; ARTICLE: "formatting" "Formatted printing" -"The " { $vocab-link "formatting" } " vocabulary is used for formatted printing.\n" +"The " { $vocab-link "formatting" } " vocabulary is used for formatted printing." { $subsection printf } { $subsection sprintf } { $subsection strftime } diff --git a/basis/furnace/auth/auth-docs.factor b/basis/furnace/auth/auth-docs.factor index 2ddd626873..f1f68c975d 100644 --- a/basis/furnace/auth/auth-docs.factor +++ b/basis/furnace/auth/auth-docs.factor @@ -121,7 +121,7 @@ $nl { $subsection "furnace.auth.providers.db" } ; ARTICLE: "furnace.auth.features" "Optional authentication features" -"Vocabularies having names prefixed by " { $code "furnace.auth.features" } " implement optional features which can be enabled by calling special words. These words define new actions on an authentication realm." +"Vocabularies having names prefixed by " { $code "furnace.auth.features" } " implement optional features which can be enabled by calling special words. These words define new actions on an authentication realm." { $subsection "furnace.auth.features.deactivate-user" } { $subsection "furnace.auth.features.edit-profile" } { $subsection "furnace.auth.features.recover-password" } diff --git a/basis/furnace/syndication/syndication-docs.factor b/basis/furnace/syndication/syndication-docs.factor index 94a69ccd0e..1ce1cd7da1 100644 --- a/basis/furnace/syndication/syndication-docs.factor +++ b/basis/furnace/syndication/syndication-docs.factor @@ -29,7 +29,7 @@ HELP: feed-entry-date HELP: feed-entry-description { $values { "object" object } - { "description" null } + { "description" string } } { $contract "Outputs a feed entry description." } ; diff --git a/basis/help/tutorial/tutorial.factor b/basis/help/tutorial/tutorial.factor index 32cccee257..efb1e0a0f7 100644 --- a/basis/help/tutorial/tutorial.factor +++ b/basis/help/tutorial/tutorial.factor @@ -30,7 +30,7 @@ ARTICLE: "first-program-logic" "Writing some logic in your first program" "! See http://factorcode.org/license.txt for BSD license." "IN: palindrome" } -"We will now write our first word using " { $link POSTPONE: : } ". This word will test if a string is a palindrome; it will take a string as input, and give back a boolean as output. We will call this word " { $snippet "palindrome?" } ", following a naming convention that words returning booleans have names ending with " { $snippet "?" } "." +"We will now write our first word using " { $link POSTPONE: : } ". This word will test if a string is a palindrome; it will take a string as input, and give back a boolean as output. We will call this word " { $snippet "palindrome?" } ", following a naming convention that words returning booleans have names ending with " { $snippet "?" } "." $nl "Recall that a string is a palindrome if it is spelled the same forwards or backwards; that is, if the string is equal to its reverse. We can express this in Factor as follows:" { $code ": palindrome? ( string -- ? ) dup reverse = ;" } diff --git a/basis/html/components/components-docs.factor b/basis/html/components/components-docs.factor index d131cc3e03..39c17a4708 100644 --- a/basis/html/components/components-docs.factor +++ b/basis/html/components/components-docs.factor @@ -70,8 +70,8 @@ HELP: render { $description "Renders an HTML component to the " { $link output-stream } "." } ; HELP: render* -{ $values { "value" "a value" } { "name" "a value name" } { "renderer" "a component renderer" } } -{ $contract "Renders an HTML component to the " { $link output-stream } "." } ; +{ $values { "value" "a value" } { "name" "a value name" } { "renderer" "a component renderer" } { "xml" "an XML chunk" } } +{ $contract "Renders an HTML component, outputting an XHTML snippet." } ; ARTICLE: "html.components" "HTML components" "The " { $vocab-link "html.components" } " vocabulary provides various HTML form components." diff --git a/basis/html/components/components.factor b/basis/html/components/components.factor index c8a4b20ca7..e63447ec55 100644 --- a/basis/html/components/components.factor +++ b/basis/html/components/components.factor @@ -3,7 +3,7 @@ USING: accessors kernel namespaces io math.parser assocs classes classes.tuple words arrays sequences splitting mirrors hashtables combinators continuations math strings inspector -fry locals calendar calendar.format xml.entities +fry locals calendar calendar.format xml.entities xml.data validators urls present xml.writer xml.interpolate xml xmode.code2html lcs.diff2html farkup io.streams.string html.elements html.streams html.forms ; @@ -65,12 +65,15 @@ TUPLE: textarea rows cols ; : XML] ; +M:: textarea render* ( value name area -- xml ) + area rows>> :> rows + area cols>> :> cols + [XML + + XML] ; ! Choice TUPLE: choice size multiple choices ; @@ -160,8 +163,9 @@ M: farkup render* SINGLETON: inspector M: inspector render* - 2drop [ [ describe ] with-html-writer ] with-string-writer - string>xml-chunk ; + 2drop [ + [ describe ] with-html-writer + ] with-string-writer ; ! Diff component SINGLETON: comparison diff --git a/basis/html/templates/chloe/chloe-tests.factor b/basis/html/templates/chloe/chloe-tests.factor index 542dfa0e05..19b67f7018 100644 --- a/basis/html/templates/chloe/chloe-tests.factor +++ b/basis/html/templates/chloe/chloe-tests.factor @@ -159,7 +159,7 @@ TUPLE: person first-name last-name ; "true" "b" set-value ] unit-test -[ "ab" ] [ +[ "ab" ] [ [ "test12" test-template call-template ] run-template diff --git a/basis/interval-maps/interval-maps-docs.factor b/basis/interval-maps/interval-maps-docs.factor index 1a862fbe2d..de18458546 100644 --- a/basis/interval-maps/interval-maps-docs.factor +++ b/basis/interval-maps/interval-maps-docs.factor @@ -18,7 +18,8 @@ HELP: { $description "From a specification, produce an interval tree. The specification is an assoc where the keys are intervals, or pairs of numbers to represent intervals, or individual numbers to represent singleton intervals. The values are the values int he interval map. Construction time is O(n log n)." } ; ARTICLE: "interval-maps" "Interval maps" -"Interval maps are a mechanism, similar to assocs, where a set of closed intervals of keys are associated with values. As such, interval maps do not conform to the assoc protocol, because intervals of floats, for example, can be used, and it is impossible to get a list of keys in between." +"The " { $vocab-link "interval-maps" } " vocabulary implements a data structure, similar to assocs, where a set of closed intervals of keys are associated with values. As such, interval maps do not conform to the assoc protocol, because intervals of floats, for example, can be used, and it is impossible to get a list of keys in between." +$nl "The following operations are used to query interval maps:" { $subsection interval-at* } { $subsection interval-at } diff --git a/basis/io/encodings/8-bit/8-bit-docs.factor b/basis/io/encodings/8-bit/8-bit-docs.factor index 8f5e955998..9ba4fcf44d 100644 --- a/basis/io/encodings/8-bit/8-bit-docs.factor +++ b/basis/io/encodings/8-bit/8-bit-docs.factor @@ -4,7 +4,7 @@ USING: help.syntax help.markup io.encodings.8-bit.private strings ; IN: io.encodings.8-bit -ARTICLE: "io.encodings.8-bit" "8-bit encodings" +ARTICLE: "io.encodings.8-bit" "Legacy 8-bit encodings" "Many encodings are a simple mapping of bytes onto characters. The " { $vocab-link "io.encodings.8-bit" } " vocabulary implements these generically using existing resource files. These encodings should be used with extreme caution, as fully general Unicode encodings like UTF-8 are nearly always more appropriate. The following 8-bit encodings are already defined:" { $subsection latin1 } { $subsection latin2 } diff --git a/basis/persistent/sequences/sequences-docs.factor b/basis/persistent/sequences/sequences-docs.factor index 986b16c737..6928d03f55 100644 --- a/basis/persistent/sequences/sequences-docs.factor +++ b/basis/persistent/sequences/sequences-docs.factor @@ -14,7 +14,7 @@ HELP: ppop { $contract "Persistent analogue of " { $link pop* } ". Outputs a new sequence with all elements of " { $snippet "seq" } " except for the final element." } ; ARTICLE: "persistent.sequences" "Persistent sequence protocol" -"The persistent sequence protocol consists of the non-mutating sequence protocol words, such as " { $link length } " and " { $link nth } ", together with the following operations:" +"The persistent sequence protocol consists of the non-mutating sequence protocol words, such as " { $link length } " and " { $link nth } ", together with the following operations:" { $subsection new-nth } { $subsection ppush } { $subsection ppop } diff --git a/basis/sorting/human/human-docs.factor b/basis/sorting/human/human-docs.factor index 5cd04c8090..5952b3e3f9 100644 --- a/basis/sorting/human/human-docs.factor +++ b/basis/sorting/human/human-docs.factor @@ -55,7 +55,7 @@ HELP: human-sort-values { <=> >=< human-compare human-sort human-sort-keys human-sort-values } related-words -ARTICLE: "sorting.human" "sorting.human" +ARTICLE: "sorting.human" "Human-friendly sorting" "The " { $vocab-link "sorting.human" } " vocabulary sorts by numbers as a human would -- by comparing their magnitudes -- rather than in a lexicographic way. For example, sorting a1, a10, a03, a2 with human sort returns a1, a2, a03, a10, while sorting with natural sort returns a03, a1, a10, a2." $nl "Comparing two objects:" { $subsection human<=> } diff --git a/basis/ui/tools/tools-docs.factor b/basis/ui/tools/tools-docs.factor index 8e1cc8d8f0..2caea23480 100644 --- a/basis/ui/tools/tools-docs.factor +++ b/basis/ui/tools/tools-docs.factor @@ -85,7 +85,7 @@ ARTICLE: "ui-completion-vocabs" "Vocabulary completion popup" { $operations "kernel" vocab } ; ARTICLE: "ui-completion-sources" "Source file completion popup" -"The source file completion popup lists all source files which have been previously loaded by " { $link run-file } ". Clicking a source file or pressing " { $snippet "RET" } " opens the source file in your editor with " { $link edit } "." +"The source file completion popup lists all source files which have been previously loaded by " { $link run-file } ". Clicking a source file or pressing " { $snippet "RET" } " opens the source file in your editor with " { $link edit } "." { $operations P" " } ; ARTICLE: "ui-completion" "UI completion popups" diff --git a/basis/ui/ui-docs.factor b/basis/ui/ui-docs.factor index 64a98fee03..5c0085bc45 100644 --- a/basis/ui/ui-docs.factor +++ b/basis/ui/ui-docs.factor @@ -185,7 +185,9 @@ $nl { $subsection add-gadgets } { $subsection clear-gadget } "The children of a gadget are available via the " -{ $snippet "children" } " slot. " "Working with gadget children:" +{ $snippet "children" } " slot. " +$nl +"Working with gadget children:" { $subsection gadget-child } { $subsection nth-gadget } { $subsection each-child } @@ -199,7 +201,7 @@ $nl { $subsection relayout-1 } "Gadgets implement a generic word to inform their parents of their preferred size:" { $subsection pref-dim* } -"To get a gadget's preferred size, do not call the above word, instead use " { $link pref-dim } ", which caches the result." ; +"To get a gadget's preferred size, do not call the above word, instead use " { $link pref-dim } ", which caches the result." ; ARTICLE: "ui-null-layout" "Manual layouts" "When automatic layout is not appropriate, gadgets can be added to a parent with no layout policy, and then positioned and sized manually by setting the " { $snippet "loc" } " field." ; diff --git a/basis/unix/groups/groups-docs.factor b/basis/unix/groups/groups-docs.factor index 07911bc96b..05b22d3413 100644 --- a/basis/unix/groups/groups-docs.factor +++ b/basis/unix/groups/groups-docs.factor @@ -83,7 +83,6 @@ ARTICLE: "unix.groups" "Unix groups" $nl "Listing all groups:" { $subsection all-groups } -"Returning a passwd tuple:" "Real groups:" { $subsection real-group-name } { $subsection real-group-id } diff --git a/basis/unix/users/users-docs.factor b/basis/unix/users/users-docs.factor index 2d46ab2d81..faee36d076 100644 --- a/basis/unix/users/users-docs.factor +++ b/basis/unix/users/users-docs.factor @@ -91,7 +91,6 @@ ARTICLE: "unix.users" "Unix users" $nl "Listing all users:" { $subsection all-users } -"Returning a passwd tuple:" "Real user:" { $subsection real-user-name } { $subsection real-user-id } diff --git a/basis/xml/data/data.factor b/basis/xml/data/data.factor index c44250035a..5dc13adf16 100644 --- a/basis/xml/data/data.factor +++ b/basis/xml/data/data.factor @@ -219,3 +219,6 @@ PREDICATE: open-tag < tag children>> ; UNION: xml-data tag comment string directive instruction ; + +TUPLE: unescaped string ; +C: unescaped diff --git a/basis/xml/data/tags.txt b/basis/xml/data/tags.txt new file mode 100644 index 0000000000..2a501370ae --- /dev/null +++ b/basis/xml/data/tags.txt @@ -0,0 +1,2 @@ +collections +assocs diff --git a/basis/xml/dispatch/authors.txt b/basis/xml/dispatch/authors.txt new file mode 100644 index 0000000000..f990dd0ed2 --- /dev/null +++ b/basis/xml/dispatch/authors.txt @@ -0,0 +1 @@ +Daniel Ehrenberg diff --git a/basis/xml/dispatch/summary.txt b/basis/xml/dispatch/summary.txt new file mode 100644 index 0000000000..6751e55e63 --- /dev/null +++ b/basis/xml/dispatch/summary.txt @@ -0,0 +1 @@ +'Generic words' that dispatch on XML tag names diff --git a/basis/xml/dispatch/tags.txt b/basis/xml/dispatch/tags.txt new file mode 100644 index 0000000000..71c0ff7282 --- /dev/null +++ b/basis/xml/dispatch/tags.txt @@ -0,0 +1 @@ +syntax diff --git a/basis/xml/interpolate/interpolate-docs.factor b/basis/xml/interpolate/interpolate-docs.factor index 2633ef11cb..23972ba7a4 100644 --- a/basis/xml/interpolate/interpolate-docs.factor +++ b/basis/xml/interpolate/interpolate-docs.factor @@ -23,10 +23,11 @@ ARTICLE: { "xml.interpolate" "in-depth" } "XML interpolation syntax" $nl "These forms can be used where a tag might go, as in " { $snippet "[XML <-> XML]" } " or where an attribute might go, as in " { $snippet "[XML /> XML]" } ". When an attribute is spliced in, it is not included if the value is " { $snippet "f" } " and if the value is not a string, the value is put through " { $link present } ". Here is an example of the fry style of XML interpolation:" { $example -{" "one two three" " " split +{" USING: splitting sequences xml.writer xml.interpolate ; +"one two three" " " split [ [XML <-> XML] ] map -<-> XML> pprint-xml>string "} -{" <' +<-> XML> pprint-xml"} +{" one @@ -37,10 +38,11 @@ $nl three -'> "} } +"} } "Here is an example of the locals version:" { $example -{" [let | +{" USING: locals urls xml.interpolate xml.writer ; +[let | number [ 3 ] false [ f ] url [ URL" http://factorcode.org/" ] @@ -53,6 +55,6 @@ $nl url=<-url-> string=<-string-> word=<-word-> /> - XML> pprint-xml>string ] "} -{" <' -'> "} } ; + XML> pprint-xml ] "} +{" +"} } ; diff --git a/basis/xml/interpolate/interpolate-tests.factor b/basis/xml/interpolate/interpolate-tests.factor index 621480abb9..817cb453fa 100644 --- a/basis/xml/interpolate/interpolate-tests.factor +++ b/basis/xml/interpolate/interpolate-tests.factor @@ -53,3 +53,7 @@ IN: xml.interpolate.tests [ "3" ] [ 3 [XML <-> XML] xml-chunk>string ] unit-test [ "" ] [ f [XML <-> XML] xml-chunk>string ] unit-test + +\ parse-def must-infer +[ "" interpolate-chunk ] must-infer +[ [XML <-> /> XML] ] must-infer diff --git a/basis/xml/interpolate/interpolate.factor b/basis/xml/interpolate/interpolate.factor index 9e39ba8fdc..0b3bb15456 100644 --- a/basis/xml/interpolate/interpolate.factor +++ b/basis/xml/interpolate/interpolate.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: xml xml.state kernel sequences fry assocs xml.data accessors strings make multiline parser namespaces macros -sequences.deep generalizations locals words combinators +sequences.deep generalizations words combinators math present arrays ; IN: xml.interpolate @@ -48,23 +48,23 @@ M: interpolated interpolate-item : interpolate-xml-doc ( table xml -- xml ) (clone) [ interpolate-tag ] change-body ; -GENERIC# (each-interpolated) 1 ( item quot -- ) inline -M: interpolated (each-interpolated) call ; -M: tag (each-interpolated) - swap attrs>> values - [ interpolated? ] filter - swap each ; -M: xml (each-interpolated) - [ body>> ] dip (each-interpolated) ; -M: object (each-interpolated) 2drop ; +: (each-interpolated) ( item quot: ( interpolated -- ) -- ) + { + { [ over interpolated? ] [ call ] } + { [ over tag? ] [ + [ attrs>> values [ interpolated? ] filter ] dip each + ] } + { [ over xml? ] [ [ body>> ] dip (each-interpolated) ] } + [ 2drop ] + } cond ; inline recursive : each-interpolated ( xml quot -- ) '[ _ (each-interpolated) ] deep-each ; inline -:: number<-> ( doc -- doc ) - 0 :> n! doc [ - dup var>> [ n >>var n 1+ n! ] unless drop - ] each-interpolated doc ; +: number<-> ( doc -- dup ) + 0 over [ + dup var>> [ over >>var [ 1+ ] dip ] unless drop + ] each-interpolated drop ; MACRO: interpolate-xml ( string -- doc ) string>doc number<-> '[ _ interpolate-xml-doc ] ; diff --git a/basis/xml/interpolate/summary.txt b/basis/xml/interpolate/summary.txt new file mode 100644 index 0000000000..7c18fc8c76 --- /dev/null +++ b/basis/xml/interpolate/summary.txt @@ -0,0 +1 @@ +Syntax for XML interpolation diff --git a/basis/xml/interpolate/tags.txt b/basis/xml/interpolate/tags.txt new file mode 100644 index 0000000000..d236e9679f --- /dev/null +++ b/basis/xml/interpolate/tags.txt @@ -0,0 +1,2 @@ +syntax +enterprise diff --git a/basis/xml/tests/test.factor b/basis/xml/tests/test.factor index 99b660276c..e3a7fdbc7a 100644 --- a/basis/xml/tests/test.factor +++ b/basis/xml/tests/test.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2005, 2006 Daniel Ehrenberg +! Copyright (C) 2005, 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. IN: xml.tests USING: kernel xml tools.test io namespaces make sequences @@ -8,7 +8,7 @@ sequences.deep accessors io.streams.string ; ! This is insufficient \ read-xml must-infer -[ [ drop ] sax ] must-infer +[ [ drop ] each-element ] must-infer \ string>xml must-infer SYMBOL: xml-file diff --git a/basis/xml/utilities/tags.txt b/basis/xml/utilities/tags.txt new file mode 100644 index 0000000000..71c0ff7282 --- /dev/null +++ b/basis/xml/utilities/tags.txt @@ -0,0 +1 @@ +syntax diff --git a/basis/xml/writer/writer-tests.factor b/basis/xml/writer/writer-tests.factor index 2d3a90cc15..e9959c1ef4 100644 --- a/basis/xml/writer/writer-tests.factor +++ b/basis/xml/writer/writer-tests.factor @@ -59,3 +59,4 @@ IN: xml.writer.tests [ "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 diff --git a/basis/xml/writer/writer.factor b/basis/xml/writer/writer.factor index a19fe69444..8e2dc4bfbf 100644 --- a/basis/xml/writer/writer.factor +++ b/basis/xml/writer/writer.factor @@ -98,6 +98,9 @@ M: open-tag write-xml-chunk } cleave ] dip xml-pprint? set ; +M: unescaped write-xml-chunk + string>> write ; + M: comment write-xml-chunk "" write ; diff --git a/basis/xml/xml-docs.factor b/basis/xml/xml-docs.factor index 264a71c8e9..26d4319b5e 100644 --- a/basis/xml/xml-docs.factor +++ b/basis/xml/xml-docs.factor @@ -1,66 +1,82 @@ ! Copyright (C) 2005, 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. -USING: help.markup help.syntax xml.data io ; +USING: help.markup help.syntax xml.data io strings ; IN: xml HELP: string>xml -{ $values { "string" "a string" } { "xml" "an xml document" } } -{ $description "converts a string into an " { $link xml } - " datatype for further processing" } ; +{ $values { "string" string } { "xml" xml } } +{ $description "Converts a string into an " { $link xml } + " tree for further processing." } ; HELP: read-xml -{ $values { "stream" "a stream that supports readln" } - { "xml" "an XML document" } } -{ $description "exausts the given stream, reading an XML document from it. A binary stream, one without encoding, should be used as input, and the encoding is automatically detected." } ; +{ $values { "stream" "an input stream" } { "xml" xml } } +{ $description "Exausts the given stream, reading an XML document from it. A binary stream, one without encoding, should be used as input, and the encoding is automatically detected." } ; HELP: file>xml -{ $values { "filename" "a string representing a filename" } - { "xml" "an XML document" } } -{ $description "opens the given file, reads it in as XML, closes the file and returns the corresponding XML tree" } ; +{ $values { "filename" string } { "xml" xml } } +{ $description "Opens the given file, reads it in as XML, closes the file and returns the corresponding XML tree. The encoding is automatically detected." } ; { string>xml read-xml file>xml } related-words 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." } { $see-also read-xml } ; -HELP: sax +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." } +{ $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" } { $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, 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" } } -{ $description "creates an XML pull-based parser which reads from " { $link input-stream } ", executing all initial XML commands to set up the parser." } +{ $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 } ; HELP: pull-elem { $values { "pull" "an XML pull parser" } { "xml-elem/f" "an XML tag, string, or f" } } -{ $description "gets the next XML element from the given XML pull parser. Returns f upon exhaustion." } +{ $description "Gets the next XML element from the given XML pull parser. Returns f upon exhaustion." } { $see-also pull-xml pull-event } ; HELP: pull-event { $values { "pull" "an XML pull parser" } { "xml-event/f" "an XML tag event, string, or f" } } -{ $description "gets the next XML event from the given XML pull parser. Returns f upon exhaustion." } +{ $description "Gets the next XML event from the given XML pull parser. Returns f upon exhaustion." } { $see-also pull-xml pull-elem } ; +HELP: read-dtd +{ $values { "stream" "an input stream" } { "dtd" dtd } } +{ $description "Exhausts a stream, producing a " { $link dtd } " from the contents." } ; + +HELP: file>dtd +{ $values { "filename" string } { "dtd" dtd } } +{ $description "Reads a file in UTF-8, converting it into an XML " { $link dtd } "." } ; + +HELP: string>dtd +{ $values { "string" string } { "dtd" dtd } } +{ $description "Interprets a string as an XML " { $link dtd } "." } ; + +{ read-dtd file>dtd string>dtd } related-words + ARTICLE: { "xml" "reading" } "Reading XML" "The following words are used to read something into an XML document" { $subsection string>xml } { $subsection read-xml } { $subsection read-xml-chunk } { $subsection string>xml-chunk } - { $subsection file>xml } ; + { $subsection file>xml } + "To read a DTD:" + { $subsection read-dtd } + { $subsection file>dtd } + { $subsection string>dtd } ; ARTICLE: { "xml" "events" } "Event-based XML parsing" "In addition to DOM-style parsing based around " { $link read-xml } ", the XML module also provides SAX-style event-based parsing. This uses much of the same data structures as normal XML, with the exception of the classes " { $link xml } " and " { $link tag } " and as such, the article " { $vocab-link "xml.data" } " may be useful in learning how to process documents in this way. Other useful words are:" - { $subsection sax } + { $subsection each-element } { $subsection opener } { $subsection closer } { $subsection contained } diff --git a/basis/xml/xml.factor b/basis/xml/xml.factor index fdabbdc4df..b043d5771e 100644 --- a/basis/xml/xml.factor +++ b/basis/xml/xml.factor @@ -6,7 +6,7 @@ xml.data xml.errors xml.elements ascii xml.entities xml.writer xml.state xml.autoencoding assocs xml.tokenize xml.name ; IN: xml -! -- Overall parser with data tree + + TUPLE: pull-xml scope ; : ( -- pull-xml ) [ @@ -106,6 +108,8 @@ TUPLE: pull-xml scope ; ] if text-now? set ] bind ; + + : pull-elem ( pull -- xml-elem/f ) [ init-xml-stack (pull-elem) ] with-scope ; + + +: each-element ( stream quot: ( xml-elem -- ) -- ) swap [ reset-prolog init-ns-stack start-document [ call-under ] when* - sax-loop - ] with-state ; inline recursive + xml-loop + ] with-state ; inline : (read-xml) ( -- ) start-document [ process ] when* - [ process ] sax-loop ; inline + [ process ] xml-loop ; inline : (read-xml-chunk) ( stream -- prolog seq ) [ @@ -155,7 +165,8 @@ TUPLE: pull-xml scope ; [ (read-xml-chunk) nip ] with-variable ; : string>xml ( string -- xml ) - read-xml ; + t string-input? + [ read-xml ] with-variable ; : string>xml-chunk ( string -- xml ) t string-input? diff --git a/basis/xmode/code2html/code2html.factor b/basis/xmode/code2html/code2html.factor index 4cdef4043e..962b0e9fbf 100644 --- a/basis/xmode/code2html/code2html.factor +++ b/basis/xmode/code2html/code2html.factor @@ -15,7 +15,7 @@ IN: xmode.code2html tokenize-line htmlize-tokens ; : htmlize-lines ( lines mode -- xml ) - f -rot load-mode [ htmlize-line ] curry map nip ; + [ f ] 2dip load-mode [ htmlize-line ] curry map nip ; : default-stylesheet ( -- xml ) "resource:basis/xmode/code2html/stylesheet.css" diff --git a/core/continuations/continuations-docs.factor b/core/continuations/continuations-docs.factor index 3364f44657..2cc44bee1b 100644 --- a/core/continuations/continuations-docs.factor +++ b/core/continuations/continuations-docs.factor @@ -1,6 +1,6 @@ USING: help.markup help.syntax kernel kernel.private continuations.private vectors arrays namespaces -assocs words quotations lexer sequences ; +assocs words quotations lexer sequences math ; IN: continuations ARTICLE: "errors-restartable" "Restartable errors" @@ -26,7 +26,7 @@ ARTICLE: "errors-anti-examples" "Common error handling pitfalls" $nl "In most other cases, " { $link cleanup } " should be used instead to handle an error and rethrow it automatically." { $heading "Anti-pattern #3: Dropping and rethrowing" } -"Do not use " { $link recover } " to handle an error by dropping it and throwing a new error. By losing the original error message, you signal to the user that something failed without leaving any indication of what actually went wrong. Either wrap the error in a new error containing additional information, or rethrow the original error. A more subtle form of this is using " { $link throw } " instead of " { $link rethrow } ". The " { $link throw } " word should only be used when throwing new errors, and never when rethrowing errors that have been caught." +"Do not use " { $link recover } " to handle an error by dropping it and throwing a new error. By losing the original error message, you signal to the user that something failed without leaving any indication of what actually went wrong. Either wrap the error in a new error containing additional information, or rethrow the original error. A more subtle form of this is using " { $link throw } " instead of " { $link rethrow } ". The " { $link throw } " word should only be used when throwing new errors, and never when rethrowing errors that have been caught." { $heading "Anti-pattern #4: Logging and rethrowing" } "If you are going to rethrow an error, do not log a message. If you do so, the user will see two log messages for the same error, which will clutter logs without adding any useful information." ; @@ -241,7 +241,7 @@ HELP: attempt-all HELP: retry { $values - { "quot" quotation } { "n" null } + { "quot" quotation } { "n" integer } } { $description "Tries the quotation up to " { $snippet "n" } " times until it returns true. Retries the quotation if an exception is thrown or if the quotation returns " { $link f } ". The quotation is expected to have side effects that may fail, such as generating a random name for a new file until successful." } { $examples diff --git a/core/parser/parser-docs.factor b/core/parser/parser-docs.factor index 4da76468e8..23bc41a1bb 100644 --- a/core/parser/parser-docs.factor +++ b/core/parser/parser-docs.factor @@ -41,7 +41,7 @@ ARTICLE: "defining-words" "Defining words" { $subsection parse-definition } "The " { $link POSTPONE: ; } " word is just a delimiter; an unpaired occurrence throws a parse error:" { $see POSTPONE: ; } -"There are additional parsing words whose syntax is delimited by " { $link POSTPONE: ; } ", and they are all implemented by calling " { $link parse-definition } "." ; +"There are additional parsing words whose syntax is delimited by " { $link POSTPONE: ; } ", and they are all implemented by calling " { $link parse-definition } "." ; ARTICLE: "parsing-tokens" "Parsing raw tokens" "So far we have seen how to read individual tokens, or read a sequence of parsed objects until a delimiter. It is also possible to read raw tokens from the input and perform custom processing." diff --git a/core/slots/slots-docs.factor b/core/slots/slots-docs.factor index c9ce334388..bdc5a5ba07 100644 --- a/core/slots/slots-docs.factor +++ b/core/slots/slots-docs.factor @@ -84,10 +84,9 @@ $nl { $subsection initial-value } ; ARTICLE: "slots" "Slots" -"A " { $emphasis "slot" } " is a component of an object which can store a value." +"The " { $vocab-link "slots" } " vocabulary contains words for introspecting the slots of an object. A " { $emphasis "slot" } " is a component of an object which can store a value." $nl { $link "tuples" } " are composed entirely of slots, and instances of " { $link "builtin-classes" } " consist of slots together with intrinsic data." -"The " { $vocab-link "slots" } " vocabulary contains words for introspecting the slots of an object." $nl "The " { $snippet "\"slots\"" } " word property of built-in and tuple classes holds an array of " { $emphasis "slot specifiers" } " describing the slot layout of each instance." { $subsection slot-spec } diff --git a/core/syntax/syntax-docs.factor b/core/syntax/syntax-docs.factor index d8cd56ff3d..c99c226a0c 100644 --- a/core/syntax/syntax-docs.factor +++ b/core/syntax/syntax-docs.factor @@ -5,7 +5,7 @@ assocs words.symbol words.alias words.constant ; IN: syntax ARTICLE: "parser-algorithm" "Parser algorithm" -"At the most abstract level, Factor syntax consists of whitespace-separated tokens. The parser tokenizes the input on whitespace boundaries. The parser is case-sensitive and whitespace between tokens is significant, so the following three expressions tokenize differently:" +"At the most abstract level, Factor syntax consists of whitespace-separated tokens. The parser tokenizes the input on whitespace boundaries. The parser is case-sensitive and whitespace between tokens is significant, so the following three expressions tokenize differently:" { $code "2X+\n2 X +\n2 x +" } "As the parser reads tokens it makes a distinction between numbers, ordinary words, and parsing words. Tokens are appended to the parse tree, the top level of which is a quotation returned by the original parser invocation. Nested levels of the parse tree are created by parsing words." $nl diff --git a/extra/partial-continuations/partial-continuations-docs.factor b/extra/partial-continuations/partial-continuations-docs.factor index a70109347b..ef15565172 100644 --- a/extra/partial-continuations/partial-continuations-docs.factor +++ b/extra/partial-continuations/partial-continuations-docs.factor @@ -12,9 +12,9 @@ HELP: bshift { $notes "It is important to note that even if the quotation discards items on the stack, the stack will be restored to the way it was before it is called (which is true of continuation usage in general)." } ; ARTICLE: "partial-continuations" "Partial continuations" -"Based on Scheme code for bshift and breset from" +"Based on Scheme code for bshift and breset from " { $url "http://groups.google.com/group/comp.lang.scheme/msg/9f0d61da01540816" } "." -"See this blog entry for more details:" +" See this blog entry for more details:" { $url "http://www.bluishcoder.co.nz/2006/03/factor-partial-continuation-updates.html" } { $subsection breset } { $subsection bshift } ; diff --git a/extra/sequences/n-based/n-based-docs.factor b/extra/sequences/n-based/n-based-docs.factor index ca5ac57cec..6c56300f6d 100644 --- a/extra/sequences/n-based/n-based-docs.factor +++ b/extra/sequences/n-based/n-based-docs.factor @@ -57,7 +57,7 @@ IN: scratchpad { n-based-assoc } related-words -ARTICLE: "sequences.n-based" "sequences.n-based" +ARTICLE: "sequences.n-based" "N-based sequences" "The " { $vocab-link "sequences.n-based" } " vocabulary provides a sequence adaptor that allows a sequence to be treated as an assoc with non-zero-based keys." { $subsection n-based-assoc } { $subsection }