]> gitweb.factorcode.org Git - factor.git/commitdiff
Moving XML vocabularies around
authorDaniel Ehrenberg <littledan@Macintosh-103.local>
Fri, 6 Feb 2009 03:17:03 +0000 (21:17 -0600)
committerDaniel Ehrenberg <littledan@Macintosh-103.local>
Fri, 6 Feb 2009 03:17:03 +0000 (21:17 -0600)
67 files changed:
basis/farkup/farkup-tests.factor
basis/farkup/farkup.factor
basis/furnace/chloe-tags/chloe-tags.factor
basis/help/html/html.factor
basis/html/components/components-docs.factor
basis/html/components/components.factor
basis/html/elements/elements.factor
basis/html/forms/forms.factor
basis/html/html.factor
basis/html/streams/streams.factor
basis/html/templates/chloe/chloe.factor
basis/html/templates/chloe/syntax/syntax.factor
basis/html/templates/templates.factor
basis/http/http-tests.factor
basis/http/server/responses/responses.factor
basis/http/server/static/static.factor
basis/lcs/diff2html/diff2html.factor
basis/syndication/syndication.factor
basis/xml-rpc/xml-rpc.factor
basis/xml/data/data-docs.factor
basis/xml/dispatch/authors.txt [deleted file]
basis/xml/dispatch/dispatch-docs.factor [deleted file]
basis/xml/dispatch/dispatch-tests.factor [deleted file]
basis/xml/dispatch/dispatch.factor [deleted file]
basis/xml/dispatch/summary.txt [deleted file]
basis/xml/dispatch/tags.txt [deleted file]
basis/xml/literals/authors.txt [deleted file]
basis/xml/literals/literals-docs.factor [deleted file]
basis/xml/literals/literals-tests.factor [deleted file]
basis/xml/literals/literals.factor [deleted file]
basis/xml/literals/summary.txt [deleted file]
basis/xml/literals/tags.txt [deleted file]
basis/xml/syntax/authors.txt [new file with mode: 0644]
basis/xml/syntax/summary.txt [new file with mode: 0644]
basis/xml/syntax/syntax-docs.factor [new file with mode: 0644]
basis/xml/syntax/syntax-tests.factor [new file with mode: 0644]
basis/xml/syntax/syntax.factor [new file with mode: 0644]
basis/xml/syntax/tags.txt [new file with mode: 0644]
basis/xml/tests/encodings.factor
basis/xml/tests/soap.factor
basis/xml/tests/templating.factor
basis/xml/tests/test.factor
basis/xml/tests/xmltest.factor
basis/xml/traversal/authors.txt [new file with mode: 0755]
basis/xml/traversal/summary.txt [new file with mode: 0644]
basis/xml/traversal/tags.txt [new file with mode: 0644]
basis/xml/traversal/traversal-docs.factor [new file with mode: 0644]
basis/xml/traversal/traversal-tests.factor [new file with mode: 0644]
basis/xml/traversal/traversal.factor [new file with mode: 0755]
basis/xml/utilities/authors.txt [deleted file]
basis/xml/utilities/summary.txt [deleted file]
basis/xml/utilities/tags.txt [deleted file]
basis/xml/utilities/utilities-docs.factor [deleted file]
basis/xml/utilities/utilities-tests.factor [deleted file]
basis/xml/utilities/utilities.factor [deleted file]
basis/xml/writer/writer-docs.factor
basis/xml/writer/writer-tests.factor
basis/xml/xml-docs.factor
basis/xmode/code2html/code2html.factor
basis/xmode/loader/loader.factor
basis/xmode/loader/syntax/syntax.factor
basis/xmode/utilities/utilities.factor
extra/4DNav/space-file-decoder/space-file-decoder.factor
extra/msxml-to-csv/msxml-to-csv.factor
extra/svg/svg-tests.factor
extra/svg/svg.factor
extra/yahoo/yahoo.factor

index 49c4dab0dbaf13febb714850d2983e0cd372a687..60a9f785e63a58a193bab712e61368a510ca9ec0 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: farkup kernel peg peg.ebnf tools.test namespaces xml
-urls.encoding assocs xml.utilities xml.data ;
+urls.encoding assocs xml.traversal xml.data ;
 IN: farkup.tests
 
 relative-link-prefix off
index bad41296ee882dc36d6249a85331627e69c23130..a5951a5080795fbe94b7603e17624ed6e6587b3c 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays combinators io
 io.streams.string kernel math namespaces peg peg.ebnf
-sequences sequences.deep strings xml.entities xml.literals
+sequences sequences.deep strings xml.entities xml.syntax
 vectors splitting xmode.code2html urls.encoding xml.data
 xml.writer ;
 IN: farkup
index dd24d8dcde6a4a8481962f466d0739e25a28319a..6024607d37893a2ef7b1f2c500b9784989395f2f 100644 (file)
@@ -7,8 +7,8 @@ xml
 xml.data
 xml.entities
 xml.writer
-xml.utilities
-xml.literals
+xml.traversal
+xml.syntax
 html.components
 html.elements
 html.forms
index 26fc4e263711c07598921d42a3fba52ebcf3a424..cccf320e4437ac3b787865c7eeefcb44ecd647c0 100644 (file)
@@ -5,7 +5,7 @@ io.files io.files.temp io.directories html.streams help kernel
 assocs sequences make words accessors arrays help.topics vocabs
 tools.vocabs tools.vocabs.browser namespaces prettyprint io
 vocabs.loader serialize fry memoize unicode.case math.order
-sorting debugger html xml.literals xml.writer ;
+sorting debugger html xml.syntax xml.writer ;
 IN: help.html
 
 : escape-char ( ch -- )
index ce4bddde6a1ab1833d1d94d5c4251f4f15e669e1..b432cc0cc6679aaae1fb28ffff0f6830eac4d7ae 100644 (file)
@@ -100,6 +100,6 @@ $nl
 { $subsection farkup }
 "Creating custom components:"
 { $subsection render* }
-"Custom components can emit HTML using the " { $vocab-link "xml.literals" } " vocabulary." ;
+"Custom components can emit HTML using the " { $vocab-link "xml.syntax" } " vocabulary." ;
 
 ABOUT: "html.components"
index f811343df29d54d48a5d968b8b651594b0509404..82bb75015e2fff10cf645afb27d63b0a7e5fb8fb 100644 (file)
@@ -4,7 +4,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 xml.data
-validators urls present xml.writer xml.literals xml
+validators urls present xml.writer xml.syntax xml
 xmode.code2html lcs.diff2html farkup io.streams.string
 html html.streams html.forms ;
 IN: html.components
index e23d929d6df286a37150c793f1a4e2273f858f1c..85df4f7b27bcaab694f0211072306663b3e07d56 100644 (file)
@@ -2,7 +2,7 @@
 ! 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
-xml.data xml.literals urls math math.parser combinators
+xml.data urls math math.parser combinators
 present fry io.streams.string xml.writer html ;
 IN: html.elements
 
index 0a69e2ed70320238f1018273eab9ffe284f0c86e..d5c744beab540c65f160e252f314073212879daa 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel accessors strings namespaces assocs hashtables io
 mirrors math fry sequences words continuations
-xml.entities xml.writer xml.literals ;
+xml.entities xml.writer xml.syntax ;
 IN: html.forms
 
 TUPLE: form errors values validation-failed ;
index 5e86add10e2338ddc96944cc91e2b91f21f7ed54..e86b4917d73322ca458d4a7930c82a839f16c4c2 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2009 Chris Double, Daniel Ehrenberg,
 ! Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel xml.data xml.writer xml.literals urls.encoding ;
+USING: kernel xml.data xml.writer xml.syntax urls.encoding ;
 IN: html
 
 : simple-page ( title head body -- xml )
@@ -21,4 +21,4 @@ IN: html
     [XML <span class="error"><-></span> XML] ;
 
 : simple-link ( xml url -- xml' )
-    url-encode swap [XML <a href=<->><-></a> XML] ;
\ No newline at end of file
+    url-encode swap [XML <a href=<->><-></a> XML] ;
index 0a4b8eddd4b6cbc2f432aabcf0333f84ab7ffdcd..28d6e6d5de4f0d589a4a4827470f458a45565808 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel assocs io io.styles math math.order math.parser
-sequences strings make words combinators macros xml.literals html fry
+sequences strings make words combinators macros xml.syntax html fry
 destructors ;
 IN: html.streams
 
index e5b40fcfaadc2a1316841a644b62b98fd19927be..6ab6722afe65f675c10b0924f9214cf028b79e49 100644 (file)
@@ -5,7 +5,7 @@ namespaces make classes.tuple assocs splitting words arrays io
 io.files io.files.info io.encodings.utf8 io.streams.string
 unicode.case mirrors math urls present multiline quotations xml
 logging continuations
-xml.data xml.writer xml.literals strings
+xml.data xml.writer xml.syntax strings
 html.forms
 html
 html.elements
index c2ecd4506b342a4d98f18356c47545217aac4d20..f149c3fe474dbb3608c2a77338b24e76013c57f2 100644 (file)
@@ -5,7 +5,7 @@ USING: accessors kernel sequences combinators kernel namespaces
 classes.tuple assocs splitting words arrays memoize parser lexer
 io io.files io.encodings.utf8 io.streams.string
 unicode.case mirrors fry math urls
-multiline xml xml.data xml.writer xml.utilities
+multiline xml xml.data xml.writer xml.syntax
 html.components
 html.templates ;
 
index efaf8d6a62ad940f4d486eaeb3fb590f1a4f0f1a..4aca73cc577a652931798df77ff7817aeb205f2b 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors kernel fry io io.encodings.utf8 io.files
 debugger prettyprint continuations namespaces boxes sequences
 arrays strings html io.streams.string
-quotations xml.data xml.writer xml.literals ;
+quotations xml.data xml.writer xml.syntax ;
 IN: html.templates
 
 MIXIN: template
index f593980467b8321b18414762cd7955c0348f85e2..49acdb639cfdfc97c03b645c06a338e913ea7197 100644 (file)
@@ -299,7 +299,7 @@ test-db [
 [ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test
 
 USING: html.components html.forms
-xml xml.utilities validators
+xml xml.traversal validators
 furnace furnace.conversations ;
 
 SYMBOL: a
index c9b4600ac8338a8e8b36afe293dda90b285d25d4..3902b7f5e284ec32c77149ed81e9348e3c646a8c 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: math.parser http accessors kernel xml.literals xml.writer
+USING: math.parser http accessors kernel xml.syntax xml.writer
 io io.streams.string io.encodings.utf8 ;
 IN: http.server.responses
 
index 2df883806167d7040ebeaf74c07db3dd8e9a0d39..53d3d4f917e8ebabf526673b2c81d7ca9e628d0a 100644 (file)
@@ -4,7 +4,7 @@ USING: calendar kernel math math.order math.parser namespaces
 parser sequences strings assocs hashtables debugger mime.types\r
 sorting logging calendar.format accessors splitting io io.files\r
 io.files.info io.directories io.pathnames io.encodings.binary\r
-fry xml.entities destructors urls html xml.literals\r
+fry xml.entities destructors urls html xml.syntax\r
 html.templates.fhtml http http.server http.server.responses\r
 http.server.redirection xml.writer ;\r
 IN: http.server.static\r
index 16e6cc8d9764d25e31b66ae08442210d421d71d9..ca9e48eb057623509324bba81db54a788ff0baeb 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: lcs xml.literals xml.writer kernel strings ;
+USING: lcs xml.syntax xml.writer kernel strings ;
 FROM: accessors => item>> ;
 FROM: io => write ;
 FROM: sequences => each if-empty when-empty map ;
index 4cd5ef17b36d66047ec9229d289987bfe300d6c8..9901fd4ce4a7b86044e36a1029899568e197d1c5 100755 (executable)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2006 Chris Double, Daniel Ehrenberg.
 ! Portions copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: xml.utilities kernel assocs math.order
+USING: xml.traversal kernel assocs math.order
     strings sequences xml.data xml.writer
     io.streams.string combinators xml xml.entities.html io.files io
-    http.client namespaces make xml.literals hashtables
+    http.client namespaces make xml.syntax hashtables
     calendar.format accessors continuations urls present ;
 IN: syndication
 
index 24dfabc8ffcbd1ed26a70f0bbd5772d6e2d53085..9632cbb1acb9b9f8c771e530e4957ab5531163e5 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel xml arrays math generic http.client
 combinators hashtables namespaces io base64 sequences strings
-calendar xml.data xml.writer xml.utilities assocs math.parser
-debugger calendar.format math.order xml.literals xml.dispatch ;
+calendar xml.data xml.writer xml.traversal assocs math.parser
+debugger calendar.format math.order xml.syntax ;
 IN: xml-rpc
 
 ! * Sending RPC requests
index 639ef5591c0e152238419113b1e1164dc63a5dc7..8c837fdf198e23bc0ec815103790c6cc334bb3d9 100644 (file)
@@ -10,7 +10,7 @@ ARTICLE: "xml.data" "XML data types"
 "Simple words for manipulating names:"
     { $subsection names-match? }
     { $subsection assure-name }
-"For high-level tools for manipulating XML, see " { $vocab-link "xml.utilities" } ;
+"For high-level tools for manipulating XML, see " { $vocab-link "xml.traversal" } ;
 
 ARTICLE: { "xml.data" "classes" } "XML data classes"
     "XML documents and chunks are made of the following classes:"
diff --git a/basis/xml/dispatch/authors.txt b/basis/xml/dispatch/authors.txt
deleted file mode 100644 (file)
index f990dd0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Daniel Ehrenberg
diff --git a/basis/xml/dispatch/dispatch-docs.factor b/basis/xml/dispatch/dispatch-docs.factor
deleted file mode 100644 (file)
index d3d24d7..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-! Copyright (C) 2005, 2009 Daniel Ehrenberg
-! See http://factorcode.org/license.txt for BSD license.
-USING: help.markup help.syntax ;
-IN: xml.dispatch
-
-ABOUT: "xml.dispatch"
-
-ARTICLE: "xml.dispatch" "Dispatch on XML tag names"
-"The " { $link "xml.dispatch" } " vocabulary defines a system, analogous to generic words, for processing XML. A word can dispatch off the name of the tag that is passed to it. To define such a word, use"
-{ $subsection POSTPONE: TAGS: }
-"and to define a new 'method' for this word, use"
-{ $subsection POSTPONE: TAG: } ;
-
-HELP: TAGS:
-{ $syntax "TAGS: word" }
-{ $values { "word" "a new word to define" } }
-{ $description "Creates a new word to which dispatches on XML tag names." }
-{ $see-also POSTPONE: TAG: } ;
-
-HELP: TAG:
-{ $syntax "TAG: tag word definition... ;" }
-{ $values { "tag" "an XML tag name" } { "word" "an XML process" } }
-{ $description "Defines a 'method' on a word created with " { $link POSTPONE: TAGS: } ". It determines what such a word should do for an argument that is has the given name." }
-{ $examples { $code "TAGS: x ( tag -- )\nTAG: a x drop \"hi\" write ;" } }
-{ $see-also POSTPONE: TAGS: } ;
diff --git a/basis/xml/dispatch/dispatch-tests.factor b/basis/xml/dispatch/dispatch-tests.factor
deleted file mode 100644 (file)
index e76a759..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-! Copyright (C) 2005, 2009 Daniel Ehrenberg
-! See http://factorcode.org/license.txt for BSD license.
-USING: xml io kernel math sequences strings xml.utilities
-tools.test math.parser xml.dispatch ;
-IN: xml.dispatch.tests
-
-TAGS: calculate ( tag -- n )
-
-: calc-2children ( tag -- n n )
-    children-tags first2 [ calculate ] dip calculate ;
-
-TAG: number calculate
-    children>string string>number ;
-TAG: add calculate
-    calc-2children + ;
-TAG: minus calculate
-    calc-2children - ;
-TAG: times calculate
-    calc-2children * ;
-TAG: divide calculate
-    calc-2children / ;
-TAG: neg calculate
-    children-tags first calculate neg ;
-
-: calc-arith ( string -- n )
-    string>xml first-child-tag calculate ;
-
-[ 32 ] [
-    "<math><times><add><number>1</number><number>3</number></add><neg><number>-8</number></neg></times></math>"
-    calc-arith
-] unit-test
-
-\ calc-arith must-infer
diff --git a/basis/xml/dispatch/dispatch.factor b/basis/xml/dispatch/dispatch.factor
deleted file mode 100644 (file)
index af47f7c..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-! Copyright (C) 2005, 2009 Daniel Ehrenberg
-! See http://factorcode.org/license.txt for BSD license.
-USING: words assocs kernel accessors parser sequences summary
-lexer splitting fry combinators locals ;
-IN: xml.dispatch
-
-TUPLE: no-tag name word ;
-M: no-tag summary
-    drop "The tag-dispatching word has no method for the given tag name" ;
-
-<PRIVATE
-
-: compile-tags ( word xtable -- quot )
-    >alist swap '[ _ no-tag boa throw ] suffix
-    '[ dup main>> _ case ] ;
-
-PRIVATE>
-
-: define-tags ( word -- )
-    dup dup "xtable" word-prop compile-tags define ;
-
-:: define-tag ( string word quot -- )
-    quot string word "xtable" word-prop set-at
-    word define-tags ;
-
-: TAGS:
-    CREATE
-    [ H{ } clone "xtable" set-word-prop ]
-    [ define-tags ] bi ; parsing
-
-: TAG:
-    scan scan-word parse-definition define-tag ; parsing
diff --git a/basis/xml/dispatch/summary.txt b/basis/xml/dispatch/summary.txt
deleted file mode 100644 (file)
index 6751e55..0000000
+++ /dev/null
@@ -1 +0,0 @@
-'Generic words' that dispatch on XML tag names
diff --git a/basis/xml/dispatch/tags.txt b/basis/xml/dispatch/tags.txt
deleted file mode 100644 (file)
index 71c0ff7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-syntax
diff --git a/basis/xml/literals/authors.txt b/basis/xml/literals/authors.txt
deleted file mode 100644 (file)
index 29e7963..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Daniel Ehrenberg
\ No newline at end of file
diff --git a/basis/xml/literals/literals-docs.factor b/basis/xml/literals/literals-docs.factor
deleted file mode 100644 (file)
index a37fcbd..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-USING: help.markup help.syntax present multiline xml.data ;
-IN: xml.literals
-
-ABOUT: "xml.literals"
-
-ARTICLE: "xml.literals" "XML literals"
-"The " { $vocab-link "xml.literals" } " vocabulary provides a convenient syntax for generating XML documents and chunks. It defines the following parsing words:"
-{ $subsection POSTPONE: <XML }
-{ $subsection POSTPONE: [XML }
-"These can be used for creating an XML literal, which can be used with variables or a fry-like syntax to interpolate data into XML."
-{ $subsection { "xml.literals" "interpolation" } } ;
-
-HELP: <XML
-{ $syntax "<XML <?xml version=\"1.0\"?><document>...</document> XML>" }
-{ $description "This gives syntax for literal XML documents. When evaluated, there is an XML document (" { $link xml } ") on the stack. It can be used for interpolation as well, if interpolation slots are used. For more information about XML interpolation, see " { $link { "xml.literals" "interpolation" } } "." } ;
-
-HELP: [XML
-{ $syntax "[XML foo <x>...</x> bar <y>...</y> baz XML]" }
-{ $description "This gives syntax for literal XML documents. When evaluated, there is an XML chunk (" { $link xml-chunk } ") on the stack. For more information about XML interpolation, see " { $link { "xml.literals" "interpolation" } } "." } ;
-
-ARTICLE: { "xml.literals" "interpolation" } "XML interpolation syntax"
-"XML interpolation has two forms for each of the words " { $link POSTPONE: <XML } " and " { $link POSTPONE: [XML } ": a fry-like form and a locals form. To splice locals in, use the syntax " { $snippet "<-variable->" } ". To splice something in from the stack, in the style of " { $vocab-link "fry" } ", use the syntax " { $snippet "<->" } ". An XML interpolation form may only use one of these styles."
-$nl
-"These forms can be used where a tag might go, as in " { $snippet "[XML <foo><-></foo> XML]" } " or where an attribute might go, as in " { $snippet "[XML <foo bar=<->/> 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 
-{" USING: splitting sequences xml.writer xml.literals ;
-"one two three" " " split
-[ [XML <item><-></item> XML] ] map
-<XML <doc><-></doc> XML> pprint-xml"}
-{" <?xml version="1.0" encoding="UTF-8"?>
-<doc>
-  <item>
-    one
-  </item>
-  <item>
-    two
-  </item>
-  <item>
-    three
-  </item>
-</doc>"} }
-"Here is an example of the locals version:"
-{ $example
-{" USING: locals urls xml.literals xml.writer ;
-[let |
-    number [ 3 ]
-    false [ f ]
-    url [ URL" http://factorcode.org/" ]
-    string [ "hello" ]
-    word [ \ drop ] |
-    <XML
-        <x
-            number=<-number->
-            false=<-false->
-            url=<-url->
-            string=<-string->
-            word=<-word-> />
-    XML> pprint-xml ] "}
-{" <?xml version="1.0" encoding="UTF-8"?>
-<x number="3" url="http://factorcode.org/" string="hello" word="drop"/>"} } ;
diff --git a/basis/xml/literals/literals-tests.factor b/basis/xml/literals/literals-tests.factor
deleted file mode 100644 (file)
index 0d8367c..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-! Copyright (C) 2009 Daniel Ehrenberg.
-! See http://factorcode.org/license.txt for BSD license.
-USING: tools.test xml.literals multiline kernel assocs
-sequences accessors xml.writer xml.literals.private
-locals splitting urls xml.data classes ;
-IN: xml.literals.tests
-
-[ "a" "c" { "a" "c" f } ] [
-    "<?xml version='1.0'?><x><-a-><b val=<-c->/><-></x>"
-    string>doc
-    [ second var>> ]
-    [ fourth "val" attr var>> ]
-    [ extract-variables ] tri
-] unit-test
-
-[ {" <?xml version="1.0" encoding="UTF-8"?>
-<x>
-  one
-  <b val="two"/>
-  y
-  <foo/>
-</x>"} ] [
-    [let* | a [ "one" ] c [ "two" ] x [ "y" ]
-           d [ [XML <-x-> <foo/> XML] ] |
-        <XML
-            <x> <-a-> <b val=<-c->/> <-d-> </x>
-        XML> pprint-xml>string
-    ]
-] unit-test
-
-[ {" <?xml version="1.0" encoding="UTF-8"?>
-<doc>
-  <item>
-    one
-  </item>
-  <item>
-    two
-  </item>
-  <item>
-    three
-  </item>
-</doc>"} ] [
-    "one two three" " " split
-    [ [XML <item><-></item> XML] ] map
-    <XML <doc><-></doc> XML> pprint-xml>string
-] unit-test
-
-[ {" <?xml version="1.0" encoding="UTF-8"?>
-<x number="3" url="http://factorcode.org/" string="hello" word="drop"/>"} ]
-[ 3 f URL" http://factorcode.org/" "hello" \ drop
-  <XML <x number=<-> false=<-> url=<-> string=<-> word=<->/> XML>
-  pprint-xml>string  ] unit-test
-
-[ "<x>3</x>" ] [ 3 [XML <x><-></x> XML] xml>string ] unit-test
-[ "<x></x>" ] [ f [XML <x><-></x> XML] xml>string ] unit-test
-
-\ <XML must-infer
-[ [XML <-> XML] ] must-infer
-[ [XML <foo><-></foo> <bar val=<->/> XML] ] must-infer
-
-[ xml-chunk ] [ [ [XML <foo/> XML] ] first class ] unit-test
-[ xml ] [ [ <XML <foo/> XML> ] first class ] unit-test
-[ xml-chunk ] [ [ [XML <foo val=<->/> XML] ] third class ] unit-test
-[ xml ] [ [ <XML <foo val=<->/> XML> ] third class ] unit-test
-[ 1 ] [ [ [XML <foo/> XML] ] length ] unit-test
-[ 1 ] [ [ <XML <foo/> XML> ] length ] unit-test
-
-[ "" ] [ [XML XML] concat ] unit-test
-
-USE: inverse
-
-[ "foo" ] [ [XML <a>foo</a> XML] [ [XML <a><-></a> XML] ] undo ] unit-test
-[ "foo" ] [ [XML <a bar='foo'/> XML] [ [XML <a bar=<-> /> XML] ] undo ] unit-test
-[ "foo" "baz" ] [ [XML <a bar='foo'>baz</a> XML] [ [XML <a bar=<->><-></a> XML] ] undo ] unit-test
-
-: dispatch ( xml -- string )
-    {
-        { [ [XML <a><-></a> XML] ] [ "a" prepend ] }
-        { [ [XML <b><-></b> XML] ] [ "b" prepend ] }
-        { [ [XML <b val='yes'/> XML] ] [ "byes" ] }
-        { [ [XML <b val=<->/> XML] ] [ "bno" prepend ] }
-    } switch ;
-
-[ "apple" ] [ [XML <a>pple</a> XML] dispatch ] unit-test
-[ "banana" ] [ [XML <b>anana</b> XML] dispatch ] unit-test
-[ "byes" ] [ [XML <b val="yes"/> XML] dispatch ] unit-test
-[ "bnowhere" ] [ [XML <b val="where"/> XML] dispatch ] unit-test
-[ "baboon" ] [ [XML <b val="something">aboon</b> XML] dispatch ] unit-test
-[ "apple" ] [ <XML <a>pple</a> XML> dispatch ] unit-test
-[ "apple" ] [ <XML <a>pple</a> XML> body>> dispatch ] unit-test
-
-: dispatch-doc ( xml -- string )
-    {
-        { [ <XML <a><-></a> XML> ] [ "a" prepend ] }
-        { [ <XML <b><-></b> XML> ] [ "b" prepend ] }
-        { [ <XML <b val='yes'/> XML> ] [ "byes" ] }
-        { [ <XML <b val=<->/> XML> ] [ "bno" prepend ] }
-    } switch ;
-
-[ "apple" ] [ <XML <a>pple</a> XML> dispatch-doc ] unit-test
-[ "apple" ] [ [XML <a>pple</a> XML] dispatch-doc ] unit-test
-[ "apple" ] [ <XML <a>pple</a> XML> body>> dispatch-doc ] unit-test
diff --git a/basis/xml/literals/literals.factor b/basis/xml/literals/literals.factor
deleted file mode 100644 (file)
index 4648f7b..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-! Copyright (C) 2009 Daniel Ehrenberg.
-! 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 words combinators
-math present arrays unicode.categories locals.backend
-quotations ;
-IN: xml.literals
-
-<PRIVATE
-
-: each-attrs ( attrs quot -- )
-    [ values [ interpolated? ] filter ] dip each ; inline
-
-: (each-interpolated) ( item quot: ( interpolated -- ) -- )
-     {
-        { [ over interpolated? ] [ call ] }
-        { [ over tag? ] [ [ attrs>> ] dip each-attrs ] }
-        { [ over attrs? ] [ each-attrs ] }
-        { [ over xml? ] [ [ body>> ] dip (each-interpolated) ] }
-        [ 2drop ]
-     } cond ; inline recursive
-
-: each-interpolated ( xml quot -- )
-    '[ _ (each-interpolated) ] deep-each ; inline
-
-: has-interpolated? ( xml -- ? )
-    ! If this becomes a performance problem, it can be improved
-    f swap [ 2drop t ] each-interpolated ;
-
-: when-interpolated ( xml quot -- genquot )
-    [ dup has-interpolated? ] dip [ '[ _ swap ] ] if ; inline
-
-: string>chunk ( string -- chunk )
-    t interpolating? [ string>xml-chunk ] with-variable ;
-
-: string>doc ( string -- xml )
-    t interpolating? [ string>xml ] with-variable ;
-
-DEFER: interpolate-sequence
-
-: get-interpolated ( interpolated -- quot )
-    var>> '[ [ _ swap at ] keep ] ;
-
-: ?present ( object -- string )
-    dup [ present ] when ;
-
-: interpolate-attr ( key value -- quot )
-    dup interpolated?
-    [ get-interpolated '[ _ swap @ [ ?present 2array ] dip ] ]
-    [ 2array '[ _ swap ] ] if ;
-
-: filter-nulls ( assoc -- newassoc )
-    [ nip ] assoc-filter ;
-
-: interpolate-attrs ( attrs -- quot )
-    [
-        [ [ interpolate-attr ] { } assoc>map [ ] join ]
-        [ assoc-size ] bi
-        '[ @ _ swap [ narray filter-nulls <attrs> ] dip ]
-    ] when-interpolated ;
-
-: interpolate-tag ( tag -- quot )
-    [
-        [ name>> ]
-        [ attrs>> interpolate-attrs ]
-        [ children>> interpolate-sequence ] tri
-        '[ _ swap @ @ [ <tag> ] dip ]
-    ] when-interpolated ;
-
-GENERIC: push-item ( item -- )
-M: string push-item , ;
-M: xml-data push-item , ;
-M: object push-item present , ;
-M: sequence push-item
-    dup xml-data? [ , ] [ [ push-item ] each ] if ;
-M: number push-item present , ;
-M: xml-chunk push-item % ;
-
-: concat-interpolate ( array -- newarray )
-    [ [ push-item ] each ] { } make ;
-
-GENERIC: interpolate-item ( item -- quot )
-M: object interpolate-item [ swap ] curry ;
-M: tag interpolate-item interpolate-tag ;
-M: interpolated interpolate-item get-interpolated ;
-
-: interpolate-sequence ( seq -- quot )
-    [
-        [ [ interpolate-item ] map concat ]
-        [ length ] bi
-        '[ @ _ swap [ narray concat-interpolate ] dip ]
-    ] when-interpolated ;
-
-GENERIC: [interpolate-xml] ( xml -- quot )
-
-M: xml [interpolate-xml]
-    dup body>> interpolate-tag
-    '[ _ (clone) swap @ drop >>body ] ;
-
-M: xml-chunk [interpolate-xml]
-    interpolate-sequence
-    '[ @ drop <xml-chunk> ] ;
-
-MACRO: interpolate-xml ( xml -- quot )
-    [interpolate-xml] ;
-
-: number<-> ( doc -- dup )
-    0 over [
-        dup var>> [
-            over >>var [ 1+ ] dip
-        ] unless drop
-    ] each-interpolated drop ;
-
-: >search-hash ( seq -- hash )
-    [ dup search ] H{ } map>assoc ;
-
-: extract-variables ( xml -- seq )
-    [ [ var>> , ] each-interpolated ] { } make ;
-
-: nenum ( ... n -- assoc )
-    narray <enum> ; inline
-
-: collect ( accum variables -- accum ? )
-    {
-        { [ dup empty? ] [ drop f ] } ! Just a literal
-        { [ dup [ ] all? ] [ >search-hash parsed t ] } ! locals
-        { [ dup [ not ] all? ] [ length parsed \ nenum parsed t ] } ! fry
-        [ drop "XML interpolation contains both fry and locals" throw ] ! mixed
-    } cond ;
-
-: parse-def ( accum delimiter quot -- accum )
-    [ parse-multiline-string [ blank? ] trim ] dip call
-    [ extract-variables collect ] keep swap
-    [ number<-> parsed ] dip
-    [ \ interpolate-xml parsed ] when ; inline
-
-PRIVATE>
-
-: <XML
-    "XML>" [ string>doc ] parse-def ; parsing
-
-: [XML
-    "XML]" [ string>chunk ] parse-def ; parsing
-
-USING: inverse sorting fry combinators.short-circuit ;
-
-: remove-blanks ( seq -- newseq )
-    [ { [ string? not ] [ [ blank? ] all? not ] } 1|| ] filter ;
-
-GENERIC: >xml ( xml -- tag )
-M: xml >xml body>> ;
-M: tag >xml ;
-M: xml-chunk >xml
-    remove-blanks
-    [ length 1 =/fail ]
-    [ first dup tag? [ fail ] unless ] bi ;
-M: object >xml fail ;
-
-: 1chunk ( object -- xml-chunk )
-    1array <xml-chunk> ;
-
-GENERIC: >xml-chunk ( xml -- chunk )
-M: xml >xml-chunk body>> 1chunk ;
-M: xml-chunk >xml-chunk ;
-M: object >xml-chunk 1chunk ;
-
-GENERIC: [undo-xml] ( xml -- quot )
-
-M: xml [undo-xml]
-    body>> [undo-xml] '[ >xml @ ] ;
-
-M: xml-chunk [undo-xml]
-    seq>> [undo-xml] '[ >xml-chunk @ ] ;
-
-: undo-attrs ( attrs -- quot: ( attrs -- ) )
-    [
-        [ main>> ] dip dup interpolated?
-        [ var>> '[ _ attr _ set ] ]
-        [ '[ _ attr _ =/fail ] ] if
-    ] { } assoc>map '[ _ cleave ] ;
-
-M: tag [undo-xml] ( tag -- quot: ( tag -- ) )
-    {
-        [ name>> main>> '[ name>> main>> _ =/fail ] ]
-        [ attrs>> undo-attrs ] 
-        [ children>> [undo-xml] '[ children>> @ ] ]
-    } cleave '[ _ _ _ tri ] ;
-
-: firstn-strong ( seq n -- ... )
-    [ swap length =/fail ]
-    [ firstn ] 2bi ; inline
-
-M: sequence [undo-xml] ( sequence -- quot: ( seq -- ) )
-    remove-blanks [ length ] [ [ [undo-xml] ] { } map-as ] bi
-    '[ remove-blanks _ firstn-strong _ spread ] ;
-
-M: string [undo-xml] ( string -- quot: ( string -- ) )
-    '[ _ =/fail ] ;
-
-M: xml-data [undo-xml] ( datum -- quot: ( datum -- ) )
-    '[ _ =/fail ] ;
-
-M: interpolated [undo-xml]
-    var>> '[ _ set ] ;
-
-: >enum ( assoc -- enum )
-    ! Assumes keys are 0..n
-    >alist sort-keys values <enum> ;
-
-: undo-xml ( xml -- quot )
-    [undo-xml] '[ H{ } clone [ _ bind ] keep >enum ] ;
-
-\ interpolate-xml 1 [ undo-xml ] define-pop-inverse
diff --git a/basis/xml/literals/summary.txt b/basis/xml/literals/summary.txt
deleted file mode 100644 (file)
index 7c18fc8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Syntax for XML interpolation
diff --git a/basis/xml/literals/tags.txt b/basis/xml/literals/tags.txt
deleted file mode 100644 (file)
index d236e96..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-syntax
-enterprise
diff --git a/basis/xml/syntax/authors.txt b/basis/xml/syntax/authors.txt
new file mode 100644 (file)
index 0000000..f990dd0
--- /dev/null
@@ -0,0 +1 @@
+Daniel Ehrenberg
diff --git a/basis/xml/syntax/summary.txt b/basis/xml/syntax/summary.txt
new file mode 100644 (file)
index 0000000..6751e55
--- /dev/null
@@ -0,0 +1 @@
+'Generic words' that dispatch on XML tag names
diff --git a/basis/xml/syntax/syntax-docs.factor b/basis/xml/syntax/syntax-docs.factor
new file mode 100644 (file)
index 0000000..19f0590
--- /dev/null
@@ -0,0 +1,91 @@
+! Copyright (C) 2005, 2009 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax xml.data present multiline ;
+IN: xml.syntax
+
+ABOUT: "xml.syntax"
+
+ARTICLE: "xml.syntax" "Syntax extensions for XML"
+"The " { $link "xml.syntax" } " vocabulary defines a number of new parsing words forXML processing."
+{ $subsection { "xml.syntax" "tags" } }
+{ $subsection { "xml.syntax" "literals" } }
+{ $subsection POSTPONE: XML-NS: } ;
+
+ARTICLE: { "xml.syntax" "tags" } "Dispatch on XML tag names"
+"There is a system, analogous to generic words, for processing XML. A word can dispatch off the name of the tag that is passed to it. To define such a word, use"
+{ $subsection POSTPONE: TAGS: }
+"and to define a new 'method' for this word, use"
+{ $subsection POSTPONE: TAG: } ;
+
+HELP: TAGS:
+{ $syntax "TAGS: word" }
+{ $values { "word" "a new word to define" } }
+{ $description "Creates a new word to which dispatches on XML tag names." }
+{ $see-also POSTPONE: TAG: } ;
+
+HELP: TAG:
+{ $syntax "TAG: tag word definition... ;" }
+{ $values { "tag" "an XML tag name" } { "word" "an XML process" } }
+{ $description "Defines a 'method' on a word created with " { $link POSTPONE: TAGS: } ". It determines what such a word should do for an argument that is has the given name." }
+{ $examples { $code "TAGS: x ( tag -- )\nTAG: a x drop \"hi\" write ;" } }
+{ $see-also POSTPONE: TAGS: } ;
+
+ARTICLE: { "xml.syntax" "literals" } "XML literals"
+"The following words provide syntax for XML literals:"
+{ $subsection POSTPONE: <XML }
+{ $subsection POSTPONE: [XML }
+"These can be used for creating an XML literal, which can be used with variables or a fry-like syntax to interpolate data into XML."
+{ $subsection { "xml.syntax" "interpolation" } } ;
+
+HELP: <XML
+{ $syntax "<XML <?xml version=\"1.0\"?><document>...</document> XML>" }
+{ $description "This gives syntax for literal XML documents. When evaluated, there is an XML document (" { $link xml } ") on the stack. It can be used for interpolation as well, if interpolation slots are used. For more information about XML interpolation, see " { $link { "xml.syntax" "interpolation" } } "." } ;
+
+HELP: [XML
+{ $syntax "[XML foo <x>...</x> bar <y>...</y> baz XML]" }
+{ $description "This gives syntax for literal XML documents. When evaluated, there is an XML chunk (" { $link xml-chunk } ") on the stack. For more information about XML interpolation, see " { $link { "xml.syntax" "interpolation" } } "." } ;
+
+ARTICLE: { "xml.syntax" "interpolation" } "XML interpolation syntax"
+"XML interpolation has two forms for each of the words " { $link POSTPONE: <XML } " and " { $link POSTPONE: [XML } ": a fry-like form and a locals form. To splice locals in, use the syntax " { $snippet "<-variable->" } ". To splice something in from the stack, in the style of " { $vocab-link "fry" } ", use the syntax " { $snippet "<->" } ". An XML interpolation form may only use one of these styles."
+$nl
+"These forms can be used where a tag might go, as in " { $snippet "[XML <foo><-></foo> XML]" } " or where an attribute might go, as in " { $snippet "[XML <foo bar=<->/> 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 
+{" USING: splitting sequences xml.writer xml.syntax ;
+"one two three" " " split
+[ [XML <item><-></item> XML] ] map
+<XML <doc><-></doc> XML> pprint-xml"}
+{" <?xml version="1.0" encoding="UTF-8"?>
+<doc>
+  <item>
+    one
+  </item>
+  <item>
+    two
+  </item>
+  <item>
+    three
+  </item>
+</doc>"} }
+"Here is an example of the locals version:"
+{ $example
+{" USING: locals urls xml.syntax xml.writer ;
+[let |
+    number [ 3 ]
+    false [ f ]
+    url [ URL" http://factorcode.org/" ]
+    string [ "hello" ]
+    word [ \ drop ] |
+    <XML
+        <x
+            number=<-number->
+            false=<-false->
+            url=<-url->
+            string=<-string->
+            word=<-word-> />
+    XML> pprint-xml ] "}
+{" <?xml version="1.0" encoding="UTF-8"?>
+<x number="3" url="http://factorcode.org/" string="hello" word="drop"/>"} } ;
+
+HELP: XML-NS:
+{ $syntax "XML-NS: name http://url" }
+{ $description "Defines a new word of the given name which constructs XML names in the namespace of the given URL. The names constructed are memoized." } ;
diff --git a/basis/xml/syntax/syntax-tests.factor b/basis/xml/syntax/syntax-tests.factor
new file mode 100644 (file)
index 0000000..10ab961
--- /dev/null
@@ -0,0 +1,138 @@
+! Copyright (C) 2005, 2009 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
+USING: xml io kernel math sequences strings xml.traversal
+tools.test math.parser xml.syntax xml.data xml.syntax.private
+accessors multiline locals inverse xml.writer splitting classes ;
+IN: xml.syntax.tests
+
+! TAGS test
+
+TAGS: calculate ( tag -- n )
+
+: calc-2children ( tag -- n n )
+    children-tags first2 [ calculate ] dip calculate ;
+
+TAG: number calculate
+    children>string string>number ;
+TAG: add calculate
+    calc-2children + ;
+TAG: minus calculate
+    calc-2children - ;
+TAG: times calculate
+    calc-2children * ;
+TAG: divide calculate
+    calc-2children / ;
+TAG: neg calculate
+    children-tags first calculate neg ;
+
+: calc-arith ( string -- n )
+    string>xml first-child-tag calculate ;
+
+[ 32 ] [
+    "<math><times><add><number>1</number><number>3</number></add><neg><number>-8</number></neg></times></math>"
+    calc-arith
+] unit-test
+
+\ calc-arith must-infer
+
+XML-NS: foo http://blah.com
+
+[ T{ name { main "bling" } { url "http://blah.com" } } ] [ "bling" foo ] unit-test
+
+! XML literals
+
+[ "a" "c" { "a" "c" f } ] [
+    "<?xml version='1.0'?><x><-a-><b val=<-c->/><-></x>"
+    string>doc
+    [ second var>> ]
+    [ fourth "val" attr var>> ]
+    [ extract-variables ] tri
+] unit-test
+
+[ {" <?xml version="1.0" encoding="UTF-8"?>
+<x>
+  one
+  <b val="two"/>
+  y
+  <foo/>
+</x>"} ] [
+    [let* | a [ "one" ] c [ "two" ] x [ "y" ]
+           d [ [XML <-x-> <foo/> XML] ] |
+        <XML
+            <x> <-a-> <b val=<-c->/> <-d-> </x>
+        XML> pprint-xml>string
+    ]
+] unit-test
+
+[ {" <?xml version="1.0" encoding="UTF-8"?>
+<doc>
+  <item>
+    one
+  </item>
+  <item>
+    two
+  </item>
+  <item>
+    three
+  </item>
+</doc>"} ] [
+    "one two three" " " split
+    [ [XML <item><-></item> XML] ] map
+    <XML <doc><-></doc> XML> pprint-xml>string
+] unit-test
+
+[ {" <?xml version="1.0" encoding="UTF-8"?>
+<x number="3" url="http://factorcode.org/" string="hello" word="drop"/>"} ]
+[ 3 f "http://factorcode.org/" "hello" \ drop
+  <XML <x number=<-> false=<-> url=<-> string=<-> word=<->/> XML>
+  pprint-xml>string  ] unit-test
+
+[ "<x>3</x>" ] [ 3 [XML <x><-></x> XML] xml>string ] unit-test
+[ "<x></x>" ] [ f [XML <x><-></x> XML] xml>string ] unit-test
+
+\ <XML must-infer
+[ [XML <-> XML] ] must-infer
+[ [XML <foo><-></foo> <bar val=<->/> XML] ] must-infer
+
+[ xml-chunk ] [ [ [XML <foo/> XML] ] first class ] unit-test
+[ xml ] [ [ <XML <foo/> XML> ] first class ] unit-test
+[ xml-chunk ] [ [ [XML <foo val=<->/> XML] ] third class ] unit-test
+[ xml ] [ [ <XML <foo val=<->/> XML> ] third class ] unit-test
+[ 1 ] [ [ [XML <foo/> XML] ] length ] unit-test
+[ 1 ] [ [ <XML <foo/> XML> ] length ] unit-test
+
+[ "" ] [ [XML XML] concat ] unit-test
+
+USE: inverse
+
+[ "foo" ] [ [XML <a>foo</a> XML] [ [XML <a><-></a> XML] ] undo ] unit-test
+[ "foo" ] [ [XML <a bar='foo'/> XML] [ [XML <a bar=<-> /> XML] ] undo ] unit-test
+[ "foo" "baz" ] [ [XML <a bar='foo'>baz</a> XML] [ [XML <a bar=<->><-></a> XML] ] undo ] unit-test
+
+: dispatch ( xml -- string )
+    {
+        { [ [XML <a><-></a> XML] ] [ "a" prepend ] }
+        { [ [XML <b><-></b> XML] ] [ "b" prepend ] }
+        { [ [XML <b val='yes'/> XML] ] [ "byes" ] }
+        { [ [XML <b val=<->/> XML] ] [ "bno" prepend ] }
+    } switch ;
+
+[ "apple" ] [ [XML <a>pple</a> XML] dispatch ] unit-test
+[ "banana" ] [ [XML <b>anana</b> XML] dispatch ] unit-test
+[ "byes" ] [ [XML <b val="yes"/> XML] dispatch ] unit-test
+[ "bnowhere" ] [ [XML <b val="where"/> XML] dispatch ] unit-test
+[ "baboon" ] [ [XML <b val="something">aboon</b> XML] dispatch ] unit-test
+[ "apple" ] [ <XML <a>pple</a> XML> dispatch ] unit-test
+[ "apple" ] [ <XML <a>pple</a> XML> body>> dispatch ] unit-test
+
+: dispatch-doc ( xml -- string )
+    {
+        { [ <XML <a><-></a> XML> ] [ "a" prepend ] }
+        { [ <XML <b><-></b> XML> ] [ "b" prepend ] }
+        { [ <XML <b val='yes'/> XML> ] [ "byes" ] }
+        { [ <XML <b val=<->/> XML> ] [ "bno" prepend ] }
+    } switch ;
+
+[ "apple" ] [ <XML <a>pple</a> XML> dispatch-doc ] unit-test
+[ "apple" ] [ [XML <a>pple</a> XML] dispatch-doc ] unit-test
+[ "apple" ] [ <XML <a>pple</a> XML> body>> dispatch-doc ] unit-test
diff --git a/basis/xml/syntax/syntax.factor b/basis/xml/syntax/syntax.factor
new file mode 100644 (file)
index 0000000..8e6bebf
--- /dev/null
@@ -0,0 +1,243 @@
+! Copyright (C) 2005, 2009 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
+USING: words assocs kernel accessors parser sequences summary
+lexer splitting combinators locals xml.data memoize sequences.deep
+xml.data xml.state xml namespaces present arrays generalizations strings
+make math macros multiline inverse combinators.short-circuit 
+sorting fry unicode.categories ;
+IN: xml.syntax
+
+<PRIVATE
+
+TUPLE: no-tag name word ;
+M: no-tag summary
+    drop "The tag-dispatching word has no method for the given tag name" ;
+
+: compile-tags ( word xtable -- quot )
+    >alist swap '[ _ no-tag boa throw ] suffix
+    '[ dup main>> _ case ] ;
+
+: define-tags ( word -- )
+    dup dup "xtable" word-prop compile-tags define ;
+
+:: define-tag ( string word quot -- )
+    quot string word "xtable" word-prop set-at
+    word define-tags ;
+
+PRIVATE>
+
+: TAGS:
+    CREATE
+    [ H{ } clone "xtable" set-word-prop ]
+    [ define-tags ] bi ; parsing
+
+: TAG:
+    scan scan-word parse-definition define-tag ; parsing
+
+: XML-NS:
+    CREATE-WORD (( string -- name )) over set-stack-effect
+    scan '[ f swap _ <name> ] define-memoized ; parsing
+
+<PRIVATE
+
+: each-attrs ( attrs quot -- )
+    [ values [ interpolated? ] filter ] dip each ; inline
+
+: (each-interpolated) ( item quot: ( interpolated -- ) -- )
+     {
+        { [ over interpolated? ] [ call ] }
+        { [ over tag? ] [ [ attrs>> ] dip each-attrs ] }
+        { [ over attrs? ] [ each-attrs ] }
+        { [ over xml? ] [ [ body>> ] dip (each-interpolated) ] }
+        [ 2drop ]
+     } cond ; inline recursive
+
+: each-interpolated ( xml quot -- )
+    '[ _ (each-interpolated) ] deep-each ; inline
+
+: has-interpolated? ( xml -- ? )
+    ! If this becomes a performance problem, it can be improved
+    f swap [ 2drop t ] each-interpolated ;
+
+: when-interpolated ( xml quot -- genquot )
+    [ dup has-interpolated? ] dip [ '[ _ swap ] ] if ; inline
+
+: string>chunk ( string -- chunk )
+    t interpolating? [ string>xml-chunk ] with-variable ;
+
+: string>doc ( string -- xml )
+    t interpolating? [ string>xml ] with-variable ;
+
+DEFER: interpolate-sequence
+
+: get-interpolated ( interpolated -- quot )
+    var>> '[ [ _ swap at ] keep ] ;
+
+: ?present ( object -- string )
+    dup [ present ] when ;
+
+: interpolate-attr ( key value -- quot )
+    dup interpolated?
+    [ get-interpolated '[ _ swap @ [ ?present 2array ] dip ] ]
+    [ 2array '[ _ swap ] ] if ;
+
+: filter-nulls ( assoc -- newassoc )
+    [ nip ] assoc-filter ;
+
+: interpolate-attrs ( attrs -- quot )
+    [
+        [ [ interpolate-attr ] { } assoc>map [ ] join ]
+        [ assoc-size ] bi
+        '[ @ _ swap [ narray filter-nulls <attrs> ] dip ]
+    ] when-interpolated ;
+
+: interpolate-tag ( tag -- quot )
+    [
+        [ name>> ]
+        [ attrs>> interpolate-attrs ]
+        [ children>> interpolate-sequence ] tri
+        '[ _ swap @ @ [ <tag> ] dip ]
+    ] when-interpolated ;
+
+GENERIC: push-item ( item -- )
+M: string push-item , ;
+M: xml-data push-item , ;
+M: object push-item present , ;
+M: sequence push-item
+    dup xml-data? [ , ] [ [ push-item ] each ] if ;
+M: number push-item present , ;
+M: xml-chunk push-item % ;
+
+: concat-interpolate ( array -- newarray )
+    [ [ push-item ] each ] { } make ;
+
+GENERIC: interpolate-item ( item -- quot )
+M: object interpolate-item [ swap ] curry ;
+M: tag interpolate-item interpolate-tag ;
+M: interpolated interpolate-item get-interpolated ;
+
+: interpolate-sequence ( seq -- quot )
+    [
+        [ [ interpolate-item ] map concat ]
+        [ length ] bi
+        '[ @ _ swap [ narray concat-interpolate ] dip ]
+    ] when-interpolated ;
+
+GENERIC: [interpolate-xml] ( xml -- quot )
+
+M: xml [interpolate-xml]
+    dup body>> interpolate-tag
+    '[ _ (clone) swap @ drop >>body ] ;
+
+M: xml-chunk [interpolate-xml]
+    interpolate-sequence
+    '[ @ drop <xml-chunk> ] ;
+
+MACRO: interpolate-xml ( xml -- quot )
+    [interpolate-xml] ;
+
+: number<-> ( doc -- dup )
+    0 over [
+        dup var>> [
+            over >>var [ 1+ ] dip
+        ] unless drop
+    ] each-interpolated drop ;
+
+: >search-hash ( seq -- hash )
+    [ dup search ] H{ } map>assoc ;
+
+: extract-variables ( xml -- seq )
+    [ [ var>> , ] each-interpolated ] { } make ;
+
+: nenum ( ... n -- assoc )
+    narray <enum> ; inline
+
+: collect ( accum variables -- accum ? )
+    {
+        { [ dup empty? ] [ drop f ] } ! Just a literal
+        { [ dup [ ] all? ] [ >search-hash parsed t ] } ! locals
+        { [ dup [ not ] all? ] [ length parsed \ nenum parsed t ] } ! fry
+        [ drop "XML interpolation contains both fry and locals" throw ] ! mixed
+    } cond ;
+
+: parse-def ( accum delimiter quot -- accum )
+    [ parse-multiline-string [ blank? ] trim ] dip call
+    [ extract-variables collect ] keep swap
+    [ number<-> parsed ] dip
+    [ \ interpolate-xml parsed ] when ; inline
+
+PRIVATE>
+
+: <XML
+    "XML>" [ string>doc ] parse-def ; parsing
+
+: [XML
+    "XML]" [ string>chunk ] parse-def ; parsing
+
+: remove-blanks ( seq -- newseq )
+    [ { [ string? not ] [ [ blank? ] all? not ] } 1|| ] filter ;
+
+GENERIC: >xml ( xml -- tag )
+M: xml >xml body>> ;
+M: tag >xml ;
+M: xml-chunk >xml
+    remove-blanks
+    [ length 1 =/fail ]
+    [ first dup tag? [ fail ] unless ] bi ;
+M: object >xml fail ;
+
+: 1chunk ( object -- xml-chunk )
+    1array <xml-chunk> ;
+
+GENERIC: >xml-chunk ( xml -- chunk )
+M: xml >xml-chunk body>> 1chunk ;
+M: xml-chunk >xml-chunk ;
+M: object >xml-chunk 1chunk ;
+
+GENERIC: [undo-xml] ( xml -- quot )
+
+M: xml [undo-xml]
+    body>> [undo-xml] '[ >xml @ ] ;
+
+M: xml-chunk [undo-xml]
+    seq>> [undo-xml] '[ >xml-chunk @ ] ;
+
+: undo-attrs ( attrs -- quot: ( attrs -- ) )
+    [
+        [ main>> ] dip dup interpolated?
+        [ var>> '[ _ attr _ set ] ]
+        [ '[ _ attr _ =/fail ] ] if
+    ] { } assoc>map '[ _ cleave ] ;
+
+M: tag [undo-xml] ( tag -- quot: ( tag -- ) )
+    {
+        [ name>> main>> '[ name>> main>> _ =/fail ] ]
+        [ attrs>> undo-attrs ] 
+        [ children>> [undo-xml] '[ children>> @ ] ]
+    } cleave '[ _ _ _ tri ] ;
+
+: firstn-strong ( seq n -- ... )
+    [ swap length =/fail ]
+    [ firstn ] 2bi ; inline
+
+M: sequence [undo-xml] ( sequence -- quot: ( seq -- ) )
+    remove-blanks [ length ] [ [ [undo-xml] ] { } map-as ] bi
+    '[ remove-blanks _ firstn-strong _ spread ] ;
+
+M: string [undo-xml] ( string -- quot: ( string -- ) )
+    '[ _ =/fail ] ;
+
+M: xml-data [undo-xml] ( datum -- quot: ( datum -- ) )
+    '[ _ =/fail ] ;
+
+M: interpolated [undo-xml]
+    var>> '[ _ set ] ;
+
+: >enum ( assoc -- enum )
+    ! Assumes keys are 0..n
+    >alist sort-keys values <enum> ;
+
+: undo-xml ( xml -- quot )
+    [undo-xml] '[ H{ } clone [ _ bind ] keep >enum ] ;
+
+\ interpolate-xml 1 [ undo-xml ] define-pop-inverse
diff --git a/basis/xml/syntax/tags.txt b/basis/xml/syntax/tags.txt
new file mode 100644 (file)
index 0000000..71c0ff7
--- /dev/null
@@ -0,0 +1 @@
+syntax
index 35076d2930bc1a088f0ada3c94285051e9b13d55..aec3e40a52d1799e558b64140b2c17705106d91c 100644 (file)
@@ -1,4 +1,4 @@
-USING: xml xml.data xml.utilities tools.test accessors kernel
+USING: xml xml.data xml.traversal tools.test accessors kernel
 io.encodings.8-bit ;
 
 [ "\u000131" ] [ "resource:basis/xml/tests/latin5.xml" file>xml children>string ] unit-test
index d2568a24e1a93efe37b11bacd4b7aec9850569aa..3d1ac2379e0fd18446a0e5e8b349991593267739 100644 (file)
@@ -1,4 +1,4 @@
-USING: sequences xml kernel arrays xml.utilities io.files tools.test ;
+USING: sequences xml kernel arrays xml.traversal io.files tools.test ;
 IN: xml.tests
 
 : assemble-data ( tag -- 3array )
index 618e785d057c7556cec8a97f4890944445f31c7a..4861f86d7b98f00e234ef5e65099b5a2c702521d 100644 (file)
@@ -1,5 +1,5 @@
 USING: kernel xml sequences assocs tools.test io arrays namespaces fry
-accessors xml.data xml.utilities xml.writer generic sequences.deep multiline ;
+accessors xml.data xml.traversal xml.writer generic sequences.deep multiline ;
 IN: xml.tests
 
 : sub-tag
index dcd428d9e60631fbb1fadc2589adf535276ec6f7..b1f6cf002f77738fe259fb1cf97de2191aaee442 100644 (file)
@@ -3,7 +3,7 @@
 IN: xml.tests
 USING: kernel xml tools.test io namespaces make sequences
 xml.errors xml.entities.html parser strings xml.data io.files
-xml.utilities continuations assocs
+xml.traversal continuations assocs
 sequences.deep accessors io.streams.string ;
 
 ! This is insufficient
index a8024ce151bebe0b58aaf7c1f7cb290487cb88de..80472fc788806cb5d5a371eac309cba95653e091 100644 (file)
@@ -1,6 +1,6 @@
 USING: accessors assocs combinators continuations fry generalizations
 io.pathnames kernel macros sequences stack-checker tools.test xml
-xml.utilities xml.writer arrays xml.data ; 
+xml.traversal xml.writer arrays xml.data ; 
 IN: xml.tests.suite
 
 TUPLE: xml-test id uri sections description type ;
diff --git a/basis/xml/traversal/authors.txt b/basis/xml/traversal/authors.txt
new file mode 100755 (executable)
index 0000000..f990dd0
--- /dev/null
@@ -0,0 +1 @@
+Daniel Ehrenberg
diff --git a/basis/xml/traversal/summary.txt b/basis/xml/traversal/summary.txt
new file mode 100644 (file)
index 0000000..365ec87
--- /dev/null
@@ -0,0 +1 @@
+Utilities for traversing an XML DOM tree
diff --git a/basis/xml/traversal/tags.txt b/basis/xml/traversal/tags.txt
new file mode 100644 (file)
index 0000000..71c0ff7
--- /dev/null
@@ -0,0 +1 @@
+syntax
diff --git a/basis/xml/traversal/traversal-docs.factor b/basis/xml/traversal/traversal-docs.factor
new file mode 100644 (file)
index 0000000..1329c49
--- /dev/null
@@ -0,0 +1,63 @@
+! Copyright (C) 2005, 2009 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax xml.data sequences strings ;
+IN: xml.traversal
+
+ABOUT: "xml.traversal"
+
+ARTICLE: "xml.traversal" "Utilities for traversing XML"
+    "The " { $vocab-link "xml.traversal" } " vocabulary provides utilities for traversing an XML DOM tree and viewing the contents of a single tag. The following words are defined:"
+    $nl
+    "Note: the difference between deep-tag-named and tag-named is that the former searches recursively among all children and children of children of the tag, while the latter only looks at the direct children, and is therefore more efficient."
+    { $subsection tag-named }
+    { $subsection tags-named }
+    { $subsection deep-tag-named }
+    { $subsection deep-tags-named }
+    { $subsection get-id }
+    "To get at the contents of a single tag, use"
+    { $subsection children>string }
+    { $subsection children-tags }
+    { $subsection first-child-tag }
+    { $subsection assert-tag } ;
+
+HELP: deep-tag-named
+{ $values { "tag" "an XML tag or document" } { "name/string" "an XML name or string representing a name" } { "matching-tag" tag } }
+{ $description "Finds an XML tag with a matching name, recursively searching children and children of children." }
+{ $see-also tags-named tag-named deep-tags-named } ;
+
+HELP: deep-tags-named
+{ $values { "tag" "an XML tag or document" } { "name/string" "an XML name or string representing a name" } { "tags-seq" "a sequence of tags" } }
+{ $description "Returns a sequence of all tags of a matching name, recursively searching children and children of children." }
+{ $see-also tag-named deep-tag-named tags-named } ;
+
+HELP: children>string
+{ $values { "tag" "an XML tag or document" } { "string" "a string" } }
+{ $description "Concatenates the children of the tag, throwing an exception when there is a non-string child." } ;
+
+HELP: children-tags
+{ $values { "tag" "an XML tag or document" } { "sequence" sequence } }
+{ $description "Gets the children of the tag that are themselves tags." }
+{ $see-also first-child-tag } ;
+
+HELP: first-child-tag
+{ $values { "tag" "an XML tag or document" } { "tag" tag } }
+{ $description "Returns the first child of the given tag that is a tag." }
+{ $see-also children-tags } ;
+
+HELP: tag-named
+{ $values { "tag" "an XML tag or document" }
+    { "name/string" "an XML name or string representing the name" }
+    { "matching-tag" tag } }
+{ $description "Finds the first tag with matching name which is the direct child of the given tag." }
+{ $see-also deep-tags-named deep-tag-named tags-named } ;
+
+HELP: tags-named
+{ $values { "tag" "an XML tag or document" }
+    { "name/string" "an XML name or string representing the name" }
+    { "tags-seq" "a sequence of tags" } }
+{ $description "Finds all tags with matching name that are the direct children of the given tag." }
+{ $see-also deep-tag-named deep-tags-named tag-named } ;
+
+HELP: get-id
+{ $values { "tag" "an XML tag or document" } { "id" "a string" } { "elem" "an XML element or f" } }
+{ $description "Finds the XML tag with the specified id, ignoring the namespace." } ;
diff --git a/basis/xml/traversal/traversal-tests.factor b/basis/xml/traversal/traversal-tests.factor
new file mode 100644 (file)
index 0000000..165ca34
--- /dev/null
@@ -0,0 +1,18 @@
+! Copyright (C) 2005, 2009 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
+USING: xml xml.traversal tools.test xml.data sequences ;
+IN: xml.traversal.tests
+
+[ "bar" ] [ "<foo>bar</foo>" string>xml children>string ] unit-test
+
+[ "" ] [ "<foo></foo>" string>xml children>string ] unit-test
+
+[ "" ] [ "<foo/>" string>xml children>string ] unit-test
+
+[ "blah" ] [ "<foo attr='blah'/>" string>xml-chunk "foo" deep-tag-named "attr" attr ] unit-test
+
+[ { "blah" } ] [ "<foo attr='blah'/>" string>xml-chunk "foo" deep-tags-named [ "attr" attr ] map ] unit-test
+
+[ "blah" ] [ "<foo attr='blah'/>" string>xml "foo" deep-tag-named "attr" attr ] unit-test
+
+[ { "blah" } ] [ "<foo attr='blah'/>" string>xml "foo" deep-tags-named [ "attr" attr ] map ] unit-test
diff --git a/basis/xml/traversal/traversal.factor b/basis/xml/traversal/traversal.factor
new file mode 100755 (executable)
index 0000000..b337ea1
--- /dev/null
@@ -0,0 +1,68 @@
+! Copyright (C) 2005, 2009 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors kernel namespaces sequences words io assocs
+quotations strings parser lexer arrays xml.data xml.writer debugger
+splitting vectors sequences.deep combinators fry memoize ;
+IN: xml.traversal
+
+: children>string ( tag -- string )
+    children>> {
+        { [ dup empty? ] [ drop "" ] }
+        {
+            [ dup [ string? not ] any? ]
+            [ "XML tag unexpectedly contains non-text children" throw ]
+        }
+        [ concat ]
+    } cond ;
+
+: children-tags ( tag -- sequence )
+    children>> [ tag? ] filter ;
+
+: first-child-tag ( tag -- tag )
+    children>> [ tag? ] find nip ;
+
+: tag-named? ( name elem -- ? )
+    dup tag? [ names-match? ] [ 2drop f ] if ;
+
+: tag-named ( tag name/string -- matching-tag )
+    assure-name '[ _ swap tag-named? ] find nip ;
+
+: tags-named ( tag name/string -- tags-seq )
+    assure-name '[ _ swap tag-named? ] filter { } like ;
+
+<PRIVATE
+
+: prepare-deep ( xml name/string -- tag name/string )
+    [ dup xml? [ body>> ] when ] [ assure-name ] bi* ;
+
+PRIVATE>
+
+: deep-tag-named ( tag name/string -- matching-tag )
+    prepare-deep '[ _ swap tag-named? ] deep-find ;
+
+: deep-tags-named ( tag name/string -- tags-seq )
+    prepare-deep '[ _ swap tag-named? ] deep-filter { } like ;
+
+: tag-with-attr? ( elem attr-value attr-name -- ? )
+    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 ;
+
+: tags-with-attr ( tag attr-value attr-name -- tags-seq )
+    assure-name '[ _ _ tag-with-attr? ] filter children>> ;
+
+: deep-tag-with-attr ( tag attr-value attr-name -- matching-tag )
+    assure-name '[ _ _ tag-with-attr? ] deep-find ;
+
+: deep-tags-with-attr ( tag attr-value attr-name -- tags-seq )
+    assure-name '[ _ _ tag-with-attr? ] deep-filter ;
+
+: get-id ( tag id -- elem )
+    "id" deep-tag-with-attr ;
+
+: deep-tags-named-with-attr ( tag tag-name attr-value attr-name -- tags )
+    [ deep-tags-named ] 2dip tags-with-attr ;
+
+: assert-tag ( name name -- )
+    names-match? [ "Unexpected XML tag found" throw ] unless ;
diff --git a/basis/xml/utilities/authors.txt b/basis/xml/utilities/authors.txt
deleted file mode 100755 (executable)
index f990dd0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Daniel Ehrenberg
diff --git a/basis/xml/utilities/summary.txt b/basis/xml/utilities/summary.txt
deleted file mode 100644 (file)
index a671132..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Utilities for manipulating an XML DOM tree
diff --git a/basis/xml/utilities/tags.txt b/basis/xml/utilities/tags.txt
deleted file mode 100644 (file)
index 71c0ff7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-syntax
diff --git a/basis/xml/utilities/utilities-docs.factor b/basis/xml/utilities/utilities-docs.factor
deleted file mode 100644 (file)
index 161ca82..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-! Copyright (C) 2005, 2009 Daniel Ehrenberg
-! See http://factorcode.org/license.txt for BSD license.
-USING: help.markup help.syntax xml.data sequences strings ;
-IN: xml.utilities
-
-ABOUT: "xml.utilities"
-
-ARTICLE: "xml.utilities" "Utilities for processing XML"
-    "Getting parts of an XML document or tag:"
-    $nl
-    "Note: the difference between deep-tag-named and tag-named is that the former searches recursively among all children and children of children of the tag, while the latter only looks at the direct children, and is therefore more efficient."
-    { $subsection tag-named }
-    { $subsection tags-named }
-    { $subsection deep-tag-named }
-    { $subsection deep-tags-named }
-    { $subsection get-id }
-    "To get at the contents of a single tag, use"
-    { $subsection children>string }
-    { $subsection children-tags }
-    { $subsection first-child-tag }
-    { $subsection assert-tag } ;
-
-HELP: deep-tag-named
-{ $values { "tag" "an XML tag or document" } { "name/string" "an XML name or string representing a name" } { "matching-tag" tag } }
-{ $description "Finds an XML tag with a matching name, recursively searching children and children of children." }
-{ $see-also tags-named tag-named deep-tags-named } ;
-
-HELP: deep-tags-named
-{ $values { "tag" "an XML tag or document" } { "name/string" "an XML name or string representing a name" } { "tags-seq" "a sequence of tags" } }
-{ $description "Returns a sequence of all tags of a matching name, recursively searching children and children of children." }
-{ $see-also tag-named deep-tag-named tags-named } ;
-
-HELP: children>string
-{ $values { "tag" "an XML tag or document" } { "string" "a string" } }
-{ $description "Concatenates the children of the tag, throwing an exception when there is a non-string child." } ;
-
-HELP: children-tags
-{ $values { "tag" "an XML tag or document" } { "sequence" sequence } }
-{ $description "Gets the children of the tag that are themselves tags." }
-{ $see-also first-child-tag } ;
-
-HELP: first-child-tag
-{ $values { "tag" "an XML tag or document" } { "tag" tag } }
-{ $description "Returns the first child of the given tag that is a tag." }
-{ $see-also children-tags } ;
-
-HELP: tag-named
-{ $values { "tag" "an XML tag or document" }
-    { "name/string" "an XML name or string representing the name" }
-    { "matching-tag" tag } }
-{ $description "Finds the first tag with matching name which is the direct child of the given tag." }
-{ $see-also deep-tags-named deep-tag-named tags-named } ;
-
-HELP: tags-named
-{ $values { "tag" "an XML tag or document" }
-    { "name/string" "an XML name or string representing the name" }
-    { "tags-seq" "a sequence of tags" } }
-{ $description "Finds all tags with matching name that are the direct children of the given tag." }
-{ $see-also deep-tag-named deep-tags-named tag-named } ;
-
-HELP: get-id
-{ $values { "tag" "an XML tag or document" } { "id" "a string" } { "elem" "an XML element or f" } }
-{ $description "Finds the XML tag with the specified id, ignoring the namespace." } ;
diff --git a/basis/xml/utilities/utilities-tests.factor b/basis/xml/utilities/utilities-tests.factor
deleted file mode 100644 (file)
index 673bf47..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-! Copyright (C) 2005, 2009 Daniel Ehrenberg
-! See http://factorcode.org/license.txt for BSD license.
-USING: xml xml.utilities tools.test xml.data sequences ;
-IN: xml.utilities.tests
-
-[ "bar" ] [ "<foo>bar</foo>" string>xml children>string ] unit-test
-
-[ "" ] [ "<foo></foo>" string>xml children>string ] unit-test
-
-[ "" ] [ "<foo/>" string>xml children>string ] unit-test
-
-XML-NS: foo http://blah.com
-
-[ T{ name { main "bling" } { url "http://blah.com" } } ] [ "bling" foo ] unit-test
-
-[ "blah" ] [ "<foo attr='blah'/>" string>xml-chunk "foo" deep-tag-named "attr" attr ] unit-test
-
-[ { "blah" } ] [ "<foo attr='blah'/>" string>xml-chunk "foo" deep-tags-named [ "attr" attr ] map ] unit-test
-
-[ "blah" ] [ "<foo attr='blah'/>" string>xml "foo" deep-tag-named "attr" attr ] unit-test
-
-[ { "blah" } ] [ "<foo attr='blah'/>" string>xml "foo" deep-tags-named [ "attr" attr ] map ] unit-test
\ No newline at end of file
diff --git a/basis/xml/utilities/utilities.factor b/basis/xml/utilities/utilities.factor
deleted file mode 100755 (executable)
index 1249da8..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-! Copyright (C) 2005, 2009 Daniel Ehrenberg
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel namespaces sequences words io assocs
-quotations strings parser lexer arrays xml.data xml.writer debugger
-splitting vectors sequences.deep combinators fry memoize ;
-IN: xml.utilities
-
-: children>string ( tag -- string )
-    children>> {
-        { [ dup empty? ] [ drop "" ] }
-        {
-            [ dup [ string? not ] any? ]
-            [ "XML tag unexpectedly contains non-text children" throw ]
-        }
-        [ concat ]
-    } cond ;
-
-: children-tags ( tag -- sequence )
-    children>> [ tag? ] filter ;
-
-: first-child-tag ( tag -- tag )
-    children>> [ tag? ] find nip ;
-
-: tag-named? ( name elem -- ? )
-    dup tag? [ names-match? ] [ 2drop f ] if ;
-
-: tag-named ( tag name/string -- matching-tag )
-    assure-name '[ _ swap tag-named? ] find nip ;
-
-: tags-named ( tag name/string -- tags-seq )
-    assure-name '[ _ swap tag-named? ] filter { } like ;
-
-<PRIVATE
-
-: prepare-deep ( xml name/string -- tag name/string )
-    [ dup xml? [ body>> ] when ] [ assure-name ] bi* ;
-
-PRIVATE>
-
-: deep-tag-named ( tag name/string -- matching-tag )
-    prepare-deep '[ _ swap tag-named? ] deep-find ;
-
-: deep-tags-named ( tag name/string -- tags-seq )
-    prepare-deep '[ _ swap tag-named? ] deep-filter { } like ;
-
-: tag-with-attr? ( elem attr-value attr-name -- ? )
-    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 ;
-
-: tags-with-attr ( tag attr-value attr-name -- tags-seq )
-    assure-name '[ _ _ tag-with-attr? ] filter children>> ;
-
-: deep-tag-with-attr ( tag attr-value attr-name -- matching-tag )
-    assure-name '[ _ _ tag-with-attr? ] deep-find ;
-
-: deep-tags-with-attr ( tag attr-value attr-name -- tags-seq )
-    assure-name '[ _ _ tag-with-attr? ] deep-filter ;
-
-: get-id ( tag id -- elem )
-    "id" deep-tag-with-attr ;
-
-: deep-tags-named-with-attr ( tag tag-name attr-value attr-name -- tags )
-    [ deep-tags-named ] 2dip tags-with-attr ;
-
-: assert-tag ( name name -- )
-    names-match? [ "Unexpected XML tag found" throw ] unless ;
-
-: insert-children ( children tag -- )
-    dup children>> [ push-all ]
-    [ swap V{ } like >>children drop ] if ;
-
-: insert-child ( child tag -- )
-    [ 1vector ] dip insert-children ;
-
-: XML-NS:
-    CREATE-WORD (( string -- name )) over set-stack-effect
-    scan '[ f swap _ <name> ] define-memoized ; parsing
index cc45528cec7e8668b0c835937d357ad67fe26e9f..9971abcdf17509ac39d2c78362c61535b964c343 100644 (file)
@@ -41,7 +41,7 @@ HELP: pprint-xml
 
 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.literals xml.writer namespaces ;
+{ $example {" USING: xml.syntax xml.writer namespaces ;
 [XML <foo>bar</foo> XML] "%%%%" indenter [ pprint-xml ] with-variable "} {"
 <foo>
 %%%%bar
@@ -49,7 +49,7 @@ HELP: indenter
 
 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.literals xml.writer namespaces ;
+{ $example {" USING: xml.syntax xml.writer namespaces ;
 [XML <html> <head>   <title> something</title></head><body><pre>bing
 bang
    bong</pre></body></html> XML] { "pre" } sensitive-tags [ pprint-xml ] with-variable "} {"
index f414264e11123d653a1752f8b3c944deaf71bfe8..23fb7a50749870709603ca0ad7d53c745cf72496 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2009 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
 USING: xml.data xml.writer tools.test fry xml kernel multiline
-xml.writer.private io.streams.string xml.utilities sequences
+xml.writer.private io.streams.string xml.traversal sequences
 io.encodings.utf8 io.files accessors io.directories ;
 IN: xml.writer.tests
 
index 901fce2dd491e999bbe5d177155179d57efbc254..024b086ef9aff324df353ed0b3063fa7fcccdbb4 100644 (file)
@@ -93,7 +93,7 @@ ARTICLE: "xml" "XML parser"
     { $vocab-subsection "XML parsing errors" "xml.errors" }\r
     { $vocab-subsection "XML entities" "xml.entities" }\r
     { $vocab-subsection "XML data types" "xml.data" }\r
-    { $vocab-subsection "Utilities for processing XML" "xml.utilities" }\r
-    { $vocab-subsection "Dispatch on XML tag names" "xml.dispatch" } ;\r
+    { $vocab-subsection "Utilities for traversing XML" "xml.traversal" }\r
+    { $vocab-subsection "Syntax extensions for XML" "xml.syntax" } ;\r
 \r
 ABOUT: "xml"\r
index 2f35cd6d769acc5127efb580362690387cb89bdf..3fb5a532c9f8ec71e6fbb9bef468a84b0d0379f0 100644 (file)
@@ -1,6 +1,6 @@
 USING: xmode.tokens xmode.marker xmode.catalog kernel locals
 io io.files sequences words io.encodings.utf8
-namespaces xml.entities accessors xml.literals locals xml.writer ;
+namespaces xml.entities accessors xml.syntax locals xml.writer ;
 IN: xmode.code2html
 
 : htmlize-tokens ( tokens -- xml )
index b661f4eb3fb087e01244aad7b91b74fb02759965..70466913a09b8213eba7ba9a09c000b8df5801c9 100644 (file)
@@ -1,5 +1,5 @@
 USING: xmode.loader.syntax xmode.tokens xmode.rules
-xmode.keyword-map xml.data xml.utilities xml assocs kernel
+xmode.keyword-map xml.data xml.traversal xml assocs kernel
 combinators sequences math.parser namespaces parser
 xmode.utilities parser-combinators.regexp io.files accessors ;
 IN: xmode.loader
index b546969a37012c938b0ce0528c2eb4ca0bdbd00d..0e7293da976f54d16fe4222a658580a736cbe570 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors xmode.tokens xmode.rules xmode.keyword-map
-xml.data xml.utilities xml assocs kernel combinators sequences
+xml.data xml.traversal xml assocs kernel combinators sequences
 math.parser namespaces make parser lexer xmode.utilities
 parser-combinators.regexp io.files splitting arrays ;
 IN: xmode.loader.syntax
index d6407d818062deb9dedc212e17359d2203c1bf8d..2423fb0d861cbff37d0e8041a4436157747b8600 100644 (file)
@@ -1,5 +1,5 @@
 USING: accessors sequences assocs kernel quotations namespaces
-xml.data xml.utilities combinators macros parser lexer words fry ;
+xml.data xml.traversal combinators macros parser lexer words fry ;
 IN: xmode.utilities
 
 : implies ( x y -- z ) [ not ] dip or ; inline
index ecc8f778fa8f83706d27d4c1735b0dedb050643f..e85830de52073acb2e3eb4a0c89fc4b21e86430f 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Jeff Bigot\r
 ! See http://factorcode.org/license.txt for BSD license.\r
-USING: adsoda xml xml.utilities xml.dispatch accessors \r
+USING: adsoda xml xml.traversal xml.syntax accessors \r
 combinators sequences math.parser kernel splitting values \r
 continuations ;\r
 IN: 4DNav.space-file-decoder\r
index 855275efccac48e6fa3b400ead1217bdd026f15d..cab28c14ca71b7608d02a483224eabd87b4d0bf3 100644 (file)
@@ -1,4 +1,4 @@
-USING: io io.files sequences xml xml.utilities
+USING: io io.files sequences xml xml.traversal
 io.encodings.ascii kernel ;
 IN: msxml-to-csv
 
index 3a28310d711416808a9c7ed7722bd19b16004bce..0f0c349b8ea761c6b91b393e61172bfb23180f41 100644 (file)
@@ -1,6 +1,6 @@
 ! (c)2009 Joe Groff, see BSD license
 USING: accessors arrays literals math math.affine-transforms
-math.functions multiline sequences svg tools.test xml xml.utilities ;
+math.functions multiline sequences svg tools.test xml xml.traversal ;
 IN: svg.tests
 
 { 1.0 2.25 } { -3.0 4.0 } { 5.5 0.000001 } <affine-transform> 1array [
index 4d8a6e6a175cbbf453f8405e65a83ff2600e2bf0..2ed5d21707a84c0f1ec3aadaed21216686e38d06 100644 (file)
@@ -1,7 +1,7 @@
 ! (c)2009 Joe Groff, see BSD license
 USING: accessors arrays assocs fry kernel math math.affine-transforms math.constants
 math.functions math.parser math.vectors memoize peg.ebnf sequences sequences.squish
-splitting strings xml.data xml.utilities ;
+splitting strings xml.data xml.syntax ;
 IN: svg
 
 XML-NS: svg-name http://www.w3.org/2000/svg
index d163c8f1ac79132d6a682c07be5755fca880148e..b58a11747f00c61c08adeb1adee87f1ddfe564e2 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2006 Daniel Ehrenberg, Walton Chan
 ! See http://factorcode.org/license.txt for BSD license.
-USING: http.client xml xml.utilities kernel sequences
+USING: http.client xml xml.traversal kernel sequences
 math.parser urls accessors locals ;
 IN: yahoo