diff --git a/basis/concurrency/messaging/messaging-docs.factor b/basis/concurrency/messaging/messaging-docs.factor index 3bd2d330c3..41beedb6dc 100644 --- a/basis/concurrency/messaging/messaging-docs.factor +++ b/basis/concurrency/messaging/messaging-docs.factor @@ -53,7 +53,8 @@ ARTICLE: { "concurrency" "synchronous-sends" } "Synchronous sends" { $subsection reply-synchronous } "An example:" { $example - "USING: concurrency.messaging kernel threads ;" + "USING: concurrency.messaging kernel prettyprint threads ;" + "IN: scratchpad" ": pong-server ( -- )" " receive [ \"pong\" ] dip reply-synchronous ;" "[ pong-server t ] \"pong-server\" spawn-server" diff --git a/basis/eval/eval-docs.factor b/basis/eval/eval-docs.factor index 057d291b7f..b53c3bae6b 100644 --- a/basis/eval/eval-docs.factor +++ b/basis/eval/eval-docs.factor @@ -11,7 +11,7 @@ HELP: eval>string { $description "Evaluates the Factor code in " { $snippet "str" } " with " { $link output-stream } " rebound to a string output stream, then outputs the resulting string." } ; ARTICLE: "eval" "Evaluating strings at runtime" -"Evaluating strings at runtime:" +"The " { $vocab-link "eval" } " vocabulary implements support for evaluating strings at runtime." { $subsection eval } { $subsection eval>string } ; diff --git a/basis/eval/eval-tests.factor b/basis/eval/eval-tests.factor new file mode 100644 index 0000000000..db4b95acdc --- /dev/null +++ b/basis/eval/eval-tests.factor @@ -0,0 +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 diff --git a/basis/eval/eval.factor b/basis/eval/eval.factor index 5b22fec159..dfa9baf418 100644 --- a/basis/eval/eval.factor +++ b/basis/eval/eval.factor @@ -1,14 +1,24 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: splitting parser compiler.units kernel namespaces -debugger io.streams.string ; +debugger io.streams.string fry ; IN: eval +: parse-string ( str -- ) + [ string-lines parse-lines ] with-compilation-unit ; + +: (eval) ( str -- ) + parse-string call ; + : eval ( str -- ) - [ string-lines parse-fresh ] with-compilation-unit call ; + [ (eval) ] with-file-vocabs ; + +: (eval>string) ( str -- output ) + [ + "quiet" on + parser-notes off + '[ _ (eval) ] try + ] with-string-writer ; : eval>string ( str -- output ) - [ - parser-notes off - [ [ eval ] keep ] try drop - ] with-string-writer ; + [ (eval>string) ] with-file-vocabs ; \ No newline at end of file diff --git a/basis/farkup/farkup-tests.factor b/basis/farkup/farkup-tests.factor index aa9345e1d0..ee09486a03 100644 --- a/basis/farkup/farkup-tests.factor +++ b/basis/farkup/farkup-tests.factor @@ -92,22 +92,22 @@ link-no-follow? off [ "

=

foo

" ] [ "===foo==" convert-farkup ] unit-test [ "

foo

=

" ] [ "=foo==" convert-farkup ] unit-test -[ "
int main()\n
" ] +[ "
int main()
" ] [ "[c{int main()}]" convert-farkup ] unit-test -[ "

" ] [ "[[image:lol.jpg]]" convert-farkup ] unit-test -[ "

teh lol

" ] [ "[[image:lol.jpg|teh lol]]" convert-farkup ] unit-test -[ "

http://lol.com

" ] [ "[[http://lol.com]]" convert-farkup ] unit-test -[ "

haha

" ] [ "[[http://lol.com|haha]]" convert-farkup ] unit-test -[ "

Bar

" ] [ "[[Foo/Bar]]" convert-farkup ] unit-test +[ "

" ] [ "[[image:lol.jpg]]" convert-farkup ] unit-test +[ "

\"teh

" ] [ "[[image:lol.jpg|teh lol]]" convert-farkup ] unit-test +[ "

http://lol.com

" ] [ "[[http://lol.com]]" convert-farkup ] unit-test +[ "

haha

" ] [ "[[http://lol.com|haha]]" convert-farkup ] unit-test +[ "

Bar

" ] [ "[[Foo/Bar]]" convert-farkup ] unit-test "/wiki/view/" relative-link-prefix [ - [ "

Bar

" ] [ "[[Foo/Bar]]" convert-farkup ] unit-test + [ "

Bar

" ] [ "[[Foo/Bar]]" convert-farkup ] unit-test ] with-variable [ ] [ "[{}]" convert-farkup drop ] unit-test -[ "
hello\n
" ] [ "[{hello}]" convert-farkup ] unit-test +[ "
hello
" ] [ "[{hello}]" convert-farkup ] unit-test [ "

Feature comparison:\n
aFactorJavaLisp
CoolnessYesNoNo
BadassYesNoNo
EnterpriseYesYesNo
KosherYesNoYes

" @@ -118,15 +118,15 @@ link-no-follow? off ] [ "Feature comparison:\n\n|a|Factor|Java|Lisp|\n|Coolness|Yes|No|No|\n|Badass|Yes|No|No|\n|Enterprise|Yes|Yes|No|\n|Kosher|Yes|No|Yes|\n" convert-farkup ] unit-test [ - "

This wiki is written in Factor and is hosted on a http://linode.com virtual server.

" + "

This wiki is written in Factor and is hosted on a http://linode.com virtual server.

" ] [ "This wiki is written in [[Factor]] and is hosted on a [[http://linode.com|http://linode.com]] virtual server." convert-farkup ] unit-test -[ "

a c

" ] [ "[[a]] [[b|c]]" convert-farkup ] unit-test +[ "

a c

" ] [ "[[a]] [[b|c]]" convert-farkup ] unit-test -[ "

C++

" ] [ "[[C++]]" convert-farkup ] unit-test +[ "

C++

" ] [ "[[C++]]" convert-farkup ] unit-test [ "

<foo>

" ] [ "" convert-farkup ] unit-test @@ -138,10 +138,10 @@ link-no-follow? off [ "
" ] [ "___" convert-farkup ] unit-test [ "
\n" ] [ "___\n" convert-farkup ] unit-test -[ "

before:\n

{ 1 2 3 } 1 tail\n

" ] +[ "

before:\n

{ 1 2 3 } 1 tail

" ] [ "before:\n[factor{{ 1 2 3 } 1 tail}]" convert-farkup ] unit-test -[ "

Factor-rific!

" ] +[ "

Factor-rific!

" ] [ "[[Factor]]-rific!" convert-farkup ] unit-test [ "

[ factor { 1 2 3 }]

" ] @@ -163,7 +163,7 @@ link-no-follow? off convert-farkup string>xml-chunk "a" deep-tag-named "href" swap at url-decode ; -[ "Trader Joe's" ] [ "[[Trader Joe's]]" check-link-escaping ] unit-test +[ "Trader Joe\"s" ] [ "[[Trader Joe\"s]]" check-link-escaping ] unit-test [ "" ] [ "[[]]" check-link-escaping ] unit-test [ "&blah;" ] [ "[[&blah;]]" check-link-escaping ] unit-test -[ "C++" ] [ "[[C++]]" check-link-escaping ] unit-test \ No newline at end of file +[ "C++" ] [ "[[C++]]" check-link-escaping ] unit-test diff --git a/basis/farkup/farkup.factor b/basis/farkup/farkup.factor index 1bfd420dd3..ccd12b83f2 100644 --- a/basis/farkup/farkup.factor +++ b/basis/farkup/farkup.factor @@ -2,8 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays combinators html.elements io io.streams.string kernel math namespaces peg peg.ebnf -sequences sequences.deep strings xml.entities -vectors splitting xmode.code2html urls.encoding ; +sequences sequences.deep strings xml.entities xml.interpolate +vectors splitting xmode.code2html urls.encoding xml.data +xml.writer ; IN: farkup SYMBOL: relative-link-prefix @@ -74,6 +75,7 @@ inline-code = "%" (!("%" | nl).)+ "%" => [[ second >string inline-code boa ]] link-content = (!("|"|"]").)+ + => [[ >string ]] image-link = "[[image:" link-content "|" link-content "]]" => [[ [ second >string ] [ fourth >string ] bi image boa ]] @@ -146,7 +148,7 @@ named-code simple-code = "[{" (!("}]").)+ "}]" - => [[ second f swap code boa ]] + => [[ second >string f swap code boa ]] code = named-code | simple-code @@ -163,66 +165,78 @@ stand-alone { [ dup [ 127 > ] contains? ] [ drop invalid-url ] } { [ dup first "/\\" member? ] [ drop invalid-url ] } { [ CHAR: : over member? ] [ dup absolute-url? [ drop invalid-url ] unless ] } - [ relative-link-prefix get prepend ] - } cond ; + [ relative-link-prefix get prepend "" like ] + } cond url-encode ; -: escape-link ( href text -- href-esc text-esc ) - [ check-url ] dip escape-string ; +: write-link ( href text -- xml ) + [ check-url link-no-follow? get "true" and ] dip + [XML nofollow=<->><-> XML] ; -: write-link ( href text -- ) - escape-link - [ ] - [ write ] - bi* ; - -: write-image-link ( href text -- ) +: write-image-link ( href text -- xml ) disable-images? get [ 2drop - "Images are not allowed" write + [XML Images are not allowed XML] ] [ - escape-link - [ ] bi* + [ check-url ] [ f like ] bi* + [XML alt=<->/> XML] ] if ; -: render-code ( string mode -- string' ) - [ string-lines ] dip - [ -
-            htmlize-lines
-        
- ] with-string-writer write ; +: render-code ( string mode -- xml ) + [ string-lines ] dip htmlize-lines + [XML
<->
XML] ; -GENERIC: (write-farkup) ( farkup -- ) -: ( string -- ) write ; -: ( string -- )
write ; -: in-tag. ( obj quot string -- ) [ call ] keep ; inline -M: heading1 (write-farkup) [ child>> (write-farkup) ] "h1" in-tag. ; -M: heading2 (write-farkup) [ child>> (write-farkup) ] "h2" in-tag. ; -M: heading3 (write-farkup) [ child>> (write-farkup) ] "h3" in-tag. ; -M: heading4 (write-farkup) [ child>> (write-farkup) ] "h4" in-tag. ; -M: strong (write-farkup) [ child>> (write-farkup) ] "strong" in-tag. ; -M: emphasis (write-farkup) [ child>> (write-farkup) ] "em" in-tag. ; -M: superscript (write-farkup) [ child>> (write-farkup) ] "sup" in-tag. ; -M: subscript (write-farkup) [ child>> (write-farkup) ] "sub" in-tag. ; -M: inline-code (write-farkup) [ child>> (write-farkup) ] "code" in-tag. ; -M: list-item (write-farkup) [ child>> (write-farkup) ] "li" in-tag. ; -M: unordered-list (write-farkup) [ child>> (write-farkup) ] "ul" in-tag. ; -M: ordered-list (write-farkup) [ child>> (write-farkup) ] "ol" in-tag. ; -M: paragraph (write-farkup) [ child>> (write-farkup) ] "p" in-tag. ; -M: link (write-farkup) [ href>> ] [ text>> ] bi write-link ; -M: image (write-farkup) [ href>> ] [ text>> ] bi write-image-link ; -M: code (write-farkup) [ string>> ] [ mode>> ] bi render-code ; -M: line (write-farkup) drop
; -M: line-break (write-farkup) drop
nl ; -M: table-row (write-farkup) ( obj -- ) - child>> [ [ [ (write-farkup) ] "td" in-tag. ] each ] "tr" in-tag. ; -M: table (write-farkup) [ child>> (write-farkup) ] "table" in-tag. ; -M: string (write-farkup) escape-string write ; -M: vector (write-farkup) [ (write-farkup) ] each ; -M: f (write-farkup) drop ; +GENERIC: (write-farkup) ( farkup -- xml ) -: write-farkup ( string -- ) +: farkup-inside ( farkup name -- xml ) + swap T{ attrs } swap + child>> (write-farkup) 1array ; + +M: heading1 (write-farkup) "h1" farkup-inside ; +M: heading2 (write-farkup) "h2" farkup-inside ; +M: heading3 (write-farkup) "h3" farkup-inside ; +M: heading4 (write-farkup) "h4" farkup-inside ; +M: strong (write-farkup) "strong" farkup-inside ; +M: emphasis (write-farkup) "em" farkup-inside ; +M: superscript (write-farkup) "sup" farkup-inside ; +M: subscript (write-farkup) "sub" farkup-inside ; +M: inline-code (write-farkup) "code" farkup-inside ; +M: list-item (write-farkup) "li" farkup-inside ; +M: unordered-list (write-farkup) "ul" farkup-inside ; +M: ordered-list (write-farkup) "ol" farkup-inside ; +M: paragraph (write-farkup) "p" farkup-inside ; +M: table (write-farkup) "table" farkup-inside ; + +M: link (write-farkup) + [ href>> ] [ text>> ] bi write-link ; + +M: image (write-farkup) + [ href>> ] [ text>> ] bi write-image-link ; + +M: code (write-farkup) + [ string>> ] [ mode>> ] bi render-code ; + +M: line (write-farkup) + drop [XML
XML] ; + +M: line-break (write-farkup) + drop [XML
XML] ; + +M: table-row (write-farkup) + child>> + [ (write-farkup) [XML <-> XML] ] map + [XML <-> XML] ; + +M: string (write-farkup) ; + +M: vector (write-farkup) [ (write-farkup) ] map ; + +M: f (write-farkup) ; + +: farkup>xml ( string -- xml ) parse-farkup (write-farkup) ; +: write-farkup ( string -- ) + farkup>xml write-xml-chunk ; + : convert-farkup ( string -- string' ) - parse-farkup [ (write-farkup) ] with-string-writer ; + [ write-farkup ] with-string-writer ; diff --git a/basis/help/lint/lint.factor b/basis/help/lint/lint.factor index 2f61d05a61..30d5ef49df 100644 --- a/basis/help/lint/lint.factor +++ b/basis/help/lint/lint.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2006, 2008 Slava Pestov. +! Copyright (C) 2006, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: fry accessors sequences parser kernel help help.markup help.topics words strings classes tools.vocabs namespaces make @@ -6,21 +6,24 @@ io io.streams.string prettyprint definitions arrays vectors combinators combinators.short-circuit splitting debugger hashtables sorting effects vocabs vocabs.loader assocs editors continuations classes.predicate macros math sets eval -vocabs.parser words.symbol values ; +vocabs.parser words.symbol values grouping unicode.categories +sequences.deep ; IN: help.lint -: check-example ( element -- ) - rest [ - but-last "\n" join 1vector - [ - use [ clone ] change - [ eval>string ] with-datastack - ] with-scope peek "\n" ?tail drop - ] keep - peek assert= ; +SYMBOL: vocabs-quot -: check-examples ( word element -- ) - nip \ $example swap elements [ check-example ] each ; +: check-example ( element -- ) + [ + rest [ + but-last "\n" join 1vector + [ (eval>string) ] with-datastack + peek "\n" ?tail drop + ] keep + peek assert= + ] vocabs-quot get call ; + +: check-examples ( element -- ) + \ $example swap elements [ check-example ] each ; : extract-values ( element -- seq ) \ $values swap elements dup empty? [ @@ -64,8 +67,13 @@ IN: help.lint ] } 2|| [ "$values don't match stack effect" throw ] unless ; -: check-see-also ( word element -- ) - nip \ $see-also swap elements [ +: check-nulls ( element -- ) + \ $values swap elements + null swap deep-member? + [ "$values should not contain null" throw ] when ; + +: check-see-also ( element -- ) + \ $see-also swap elements [ rest dup prune [ length ] bi@ assert= ] each ; @@ -79,43 +87,78 @@ IN: help.lint ] each ; : check-rendering ( element -- ) - [ print-topic ] with-string-writer drop ; + [ print-content ] with-string-writer drop ; + +: check-strings ( str -- ) + [ + "\n\t" intersects? + [ "Paragraph text should not contain \\n or \\t" throw ] when + ] [ + " " swap subseq? + [ "Paragraph text should not contain double spaces" throw ] when + ] bi ; + +: check-whitespace ( str1 str2 -- ) + [ " " tail? ] [ " " head? ] bi* or + [ "Missing whitespace between strings" throw ] unless ; + +: check-bogus-nl ( element -- ) + { { $nl } { { $nl } } } [ head? ] with contains? + [ "Simple element should not begin with a paragraph break" throw ] when ; + +: check-elements ( element -- ) + { + [ check-bogus-nl ] + [ [ string? ] filter [ check-strings ] each ] + [ [ simple-element? ] filter [ check-elements ] each ] + [ 2 [ [ string? ] all? ] filter [ first2 check-whitespace ] each ] + } cleave ; + +: check-markup ( element -- ) + { + [ check-elements ] + [ check-rendering ] + [ check-examples ] + [ check-modules ] + } cleave ; : all-word-help ( words -- seq ) [ word-help ] filter ; -TUPLE: help-error topic error ; +TUPLE: help-error error topic ; C: help-error M: help-error error. - "In " write dup topic>> pprint nl - error>> error. ; + [ "In " write topic>> pprint nl ] + [ error>> error. ] + bi ; : check-something ( obj quot -- ) - flush [ , ] recover ; inline + flush '[ _ assert-depth ] swap '[ _ , ] recover ; inline : check-word ( word -- ) + [ with-file-vocabs ] vocabs-quot set dup word-help [ - [ - dup word-help '[ - _ _ { - [ check-examples ] - [ check-values ] - [ check-see-also ] - [ [ check-rendering ] [ check-modules ] bi* ] - } 2cleave - ] assert-depth + dup '[ + _ dup word-help + [ check-values ] + [ nip [ check-nulls ] [ check-see-also ] [ check-markup ] tri ] 2bi ] check-something ] [ drop ] if ; : check-words ( words -- ) [ check-word ] each ; +: check-article-title ( article -- ) + article-title first LETTER? + [ "Article title must begin with a capital letter" throw ] unless ; + : check-article ( article -- ) - [ - dup article-content - '[ _ check-rendering _ check-modules ] - assert-depth + [ with-interactive-vocabs ] vocabs-quot set + dup '[ + _ + [ check-article-title ] + [ article-content check-markup ] bi ] check-something ; : files>vocabs ( -- assoc ) @@ -135,7 +178,7 @@ M: help-error error. ] keep ; : check-about ( vocab -- ) - [ vocab-help [ article drop ] when* ] check-something ; + dup '[ _ vocab-help [ article drop ] when* ] check-something ; : check-vocab ( vocab -- seq ) "Checking " write dup write "..." print diff --git a/basis/help/tutorial/tutorial.factor b/basis/help/tutorial/tutorial.factor index 813eef4ea2..0a6765e10e 100644 --- a/basis/help/tutorial/tutorial.factor +++ b/basis/help/tutorial/tutorial.factor @@ -94,7 +94,7 @@ $nl "For example, we'd like it to identify the following as a palindrome:" { $code "\"A man, a plan, a canal: Panama.\"" } "However, right now, the simplistic algorithm we use says this is not a palindrome:" -{ $example "\"A man, a plan, a canal: Panama.\" palindrome?" "f" } +{ $unchecked-example "\"A man, a plan, a canal: Panama.\" palindrome?" "f" } "We would like it to output " { $link t } " there. We can encode this requirement with a unit test that we add to " { $snippet "palindrome-tests.factor" } ":" { $code "[ t ] [ \"A man, a plan, a canal: Panama.\" palindrome? ] unit-test" } "If you now run unit tests, you will see a unit test failure:" @@ -106,12 +106,12 @@ $nl "Start by pushing a character on the stack; notice that characters are really just integers:" { $code "CHAR: a" } "Now, use the " { $link Letter? } " word to test if it is an alphabetical character, upper or lower case:" -{ $example "Letter? ." "t" } +{ $unchecked-example "Letter? ." "t" } "This gives the expected result." $nl "Now try with a non-alphabetical character:" { $code "CHAR: #" } -{ $example "Letter? ." "f" } +{ $unchecked-example "Letter? ." "f" } "What we want to do is given a string, remove all characters which do not match the " { $link Letter? } " predicate. Let's push a string on the stack:" { $code "\"A man, a plan, a canal: Panama.\"" } "Now, place a quotation containing " { $link Letter? } " on the stack; quoting code places it on the stack instead of executing it immediately:" diff --git a/basis/html/components/components-tests.factor b/basis/html/components/components-tests.factor index b4247e6e30..09bb5860ad 100644 --- a/basis/html/components/components-tests.factor +++ b/basis/html/components/components-tests.factor @@ -31,7 +31,7 @@ TUPLE: color red green blue ; ] with-string-writer ] unit-test -[ "" ] [ +[ "\" name=\"red\" type=\"hidden\"/>" ] [ [ "red" hidden render ] with-string-writer @@ -39,13 +39,13 @@ TUPLE: color red green blue ; [ ] [ "'jimmy'" "red" set-value ] unit-test -[ "" ] [ +[ "" ] [ [ "red" 5 >>size render ] with-string-writer ] unit-test -[ "" ] [ +[ "" ] [ [ "red" 5 >>size render ] with-string-writer @@ -105,7 +105,7 @@ TUPLE: color red green blue ; [ ] [ t "delivery" set-value ] unit-test -[ "Delivery" ] [ +[ "Delivery" ] [ [ "delivery" @@ -116,7 +116,7 @@ TUPLE: color red green blue ; [ ] [ f "delivery" set-value ] unit-test -[ "Delivery" ] [ +[ "Delivery" ] [ [ "delivery" @@ -133,7 +133,7 @@ M: link-test link-href drop "http://www.apple.com/foo&bar" ; [ ] [ link-test "link" set-value ] unit-test -[ "<Link Title>" ] [ +[ "<Link Title>" ] [ [ "link" link new render ] with-string-writer ] unit-test @@ -149,7 +149,7 @@ M: link-test link-href drop "http://www.apple.com/foo&bar" ; [ ] [ "java" "mode" set-value ] unit-test -[ "int x = 4;\n" ] [ +[ "int x = 4;" ] [ [ "code" "mode" >>mode render ] with-string-writer ] unit-test @@ -163,6 +163,8 @@ M: link-test link-href drop "http://www.apple.com/foo&bar" ; [ t ] [ [ "object" inspector render ] with-string-writer + USING: splitting sequences ; + "\"" split "'" join ! replace " with ' for now [ "object" value [ describe ] with-html-writer ] with-string-writer = ] unit-test diff --git a/basis/html/components/components.factor b/basis/html/components/components.factor index 6f35ba5d97..c8a4b20ca7 100644 --- a/basis/html/components/components.factor +++ b/basis/html/components/components.factor @@ -4,12 +4,12 @@ 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 -validators urls present -xmode.code2html lcs.diff2html farkup +validators urls present xml.writer xml.interpolate xml +xmode.code2html lcs.diff2html farkup io.streams.string html.elements html.streams html.forms ; IN: html.components -GENERIC: render* ( value name renderer -- ) +GENERIC: render* ( value name renderer -- xml ) : render ( name renderer -- ) prepare-value @@ -19,38 +19,36 @@ GENERIC: render* ( value name renderer -- ) [ f swap ] if ] 2dip - render* + render* write-xml-chunk [ render-error ] when* ; ; +: render-input ( value name type -- xml ) + [XML name=<-> type=<->/> XML] ; PRIVATE> SINGLETON: label -M: label render* 2drop present escape-string write ; +M: label render* + 2drop present ; SINGLETON: hidden -M: hidden render* drop "hidden" render-input ; +M: hidden render* + drop "hidden" render-input ; -: render-field ( value name size type -- ) - ; +: render-field ( value name size type -- xml ) + [XML name=<-> size=<-> type=<->/> XML] ; TUPLE: field size ; : ( -- field ) field new ; -M: field render* size>> "text" render-field ; +M: field render* + size>> "text" render-field ; TUPLE: password size ; @@ -67,14 +65,12 @@ TUPLE: textarea rows cols ; : ; +M: textarea render* ( value name area -- xml ) + rot [ [ rows>> ] [ cols>> ] bi ] dip + [XML XML] ; ! Choice TUPLE: choice size multiple choices ; @@ -82,24 +78,23 @@ TUPLE: choice size multiple choices ; : ( -- choice ) choice new ; -: render-option ( text selected? -- ) - ; +: render-option ( text selected? -- xml ) + "selected" and swap + [XML XML] ; -: render-options ( options selected -- ) - '[ dup _ member? render-option ] each ; +: render-options ( value choice -- xml ) + [ choices>> value ] [ multiple>> ] bi + [ swap ] [ swap 1array ] if + '[ dup _ member? render-option ] map ; -M: choice render* - ; +M:: choice render* ( value name choice -- xml ) + choice size>> :> size + choice multiple>> "true" and :> multiple + value choice render-options :> contents + [XML XML] ; ! Checkboxes TUPLE: checkbox label ; @@ -108,13 +103,10 @@ TUPLE: checkbox label ; checkbox new ; M: checkbox render* - - label>> escape-string write - ; + [ "true" and ] [ ] [ label>> ] tri* + [XML name=<->><-> XML] ; ! Link components GENERIC: link-title ( obj -- string ) @@ -129,10 +121,9 @@ M: url link-href ; TUPLE: link target ; M: link render* - nip - > [ =target ] when* dup link-href =href a> - link-title present escape-string write - ; + nip swap + [ target>> ] [ [ link-href ] [ link-title ] bi ] bi* + [XML href=<->><-> XML] ; ! XMode code component TUPLE: code mode ; @@ -161,7 +152,7 @@ M: farkup render* nip [ no-follow>> [ string>boolean link-no-follow? set ] when* ] [ disable-images>> [ string>boolean disable-images? set ] when* ] - [ parsed>> string>boolean [ (write-farkup) ] [ write-farkup ] if ] + [ parsed>> string>boolean [ (write-farkup) ] [ farkup>xml ] if ] tri ] with-scope ; @@ -169,7 +160,8 @@ M: farkup render* SINGLETON: inspector M: inspector render* - 2drop [ describe ] with-html-writer ; + 2drop [ [ describe ] with-html-writer ] with-string-writer + string>xml-chunk ; ! Diff component SINGLETON: comparison @@ -180,4 +172,4 @@ M: comparison render* ! HTML component SINGLETON: html -M: html render* 2drop write ; +M: html render* 2drop string>xml-chunk ; diff --git a/basis/io/backend/windows/windows.factor b/basis/io/backend/windows/windows.factor index bf01f1d621..6ecbc49f2a 100755 --- a/basis/io/backend/windows/windows.factor +++ b/basis/io/backend/windows/windows.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2004, 2008 Mackenzie Straight, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: alien alien.c-types arrays destructors io io.backend io.buffers -io.files io.ports io.binary io.timeouts io.encodings.8-bit +USING: alien alien.c-types arrays destructors io io.backend +io.buffers io.files io.ports io.binary io.timeouts windows.errors strings kernel math namespaces sequences windows windows.kernel32 windows.shell32 windows.types windows.winsock splitting continuations math.bitwise system accessors ; @@ -51,6 +51,4 @@ HOOK: add-completion io-backend ( port -- ) : default-security-attributes ( -- obj ) "SECURITY_ATTRIBUTES" "SECURITY_ATTRIBUTES" heap-size - over set-SECURITY_ATTRIBUTES-nLength ; - -M: windows console-encoding windows-1252 ; \ No newline at end of file + over set-SECURITY_ATTRIBUTES-nLength ; \ No newline at end of file diff --git a/basis/lcs/diff2html/diff2html.factor b/basis/lcs/diff2html/diff2html.factor index ebbb0f3786..ee303cc5a5 100644 --- a/basis/lcs/diff2html/diff2html.factor +++ b/basis/lcs/diff2html/diff2html.factor @@ -1,44 +1,42 @@ ! Copyright (C) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. -USING: lcs html.elements kernel ; +USING: lcs xml.interpolate xml.writer kernel strings ; FROM: accessors => item>> ; FROM: io => write ; -FROM: sequences => each if-empty ; -FROM: xml.entities => escape-string ; +FROM: sequences => each if-empty when-empty map ; IN: lcs.diff2html -GENERIC: diff-line ( obj -- ) +GENERIC: diff-line ( obj -- xml ) -: write-item ( item -- ) - item>> [ " " ] [ escape-string ] if-empty write ; +: item-string ( item -- string ) + item>> [ CHAR: no-break-space 1string ] when-empty ; M: retain diff-line - - dup [ - - write-item - - ] bi@ - ; + item-string + [XML <-> XML] + dup [XML <-><-> XML] ; M: insert diff-line - - - - write-item - - ; + item-string [XML + + + <-> + + XML] ; M: delete diff-line - - - write-item - - - ; + item-string [XML + + <-> + + + XML] ; -: htmlize-diff ( diff -- ) - - - [ diff-line ] each -
"Old" write "New" write
; +: htmlize-diff ( diff -- xml ) + [ diff-line ] map + [XML + + + <-> +
OldNew
+ XML] ; diff --git a/basis/locals/locals-docs.factor b/basis/locals/locals-docs.factor index 8092d11e4a..efaad748cf 100644 --- a/basis/locals/locals-docs.factor +++ b/basis/locals/locals-docs.factor @@ -134,6 +134,7 @@ $nl } "In a word with locals, literals expand into code which constructs the literal, and so every invocation pushes a new object:" { $example + "USE: locals" "IN: scratchpad" "TUPLE: person first-name last-name ;" ":: ordinary-word-test ( -- tuple )" diff --git a/basis/math/complex/complex-docs.factor b/basis/math/complex/complex-docs.factor index bed3a655b1..1fcc1ead13 100644 --- a/basis/math/complex/complex-docs.factor +++ b/basis/math/complex/complex-docs.factor @@ -6,7 +6,7 @@ ARTICLE: "complex-numbers-zero" "Embedding of real numbers in complex numbers" "Constructing a complex number with an imaginary component equal to an integer zero simply returns the real number corresponding to the real component:" { $example "USING: math prettyprint ;" "C{ 1 2 } C{ 3 -2 } + ." "4" } "Constructing a complex number with an imaginary component equal to floating point zero will still output a new complex number, however:" -{ $example "USING: math prettyprint ;" "C{ 0.0 2.0 } C{ 0.0 1.0 } * ." "C{ 2.0 0.0 }" } +{ $example "USING: math prettyprint ;" "C{ 0.0 2.0 } C{ 0.0 1.0 } * ." "C{ -2.0 0.0 }" } "Unlike math, where all real numbers are also complex numbers, Factor only considers a number to be a complex number if its imaginary part is non-zero. However, complex number operations are fully supported for real numbers; they are treated as having an imaginary part of zero." ; ARTICLE: "complex-numbers" "Complex numbers" diff --git a/basis/math/libm/libm-docs.factor b/basis/math/libm/libm-docs.factor index 1fe565ee00..72c114487b 100644 --- a/basis/math/libm/libm-docs.factor +++ b/basis/math/libm/libm-docs.factor @@ -5,8 +5,8 @@ ARTICLE: "math.libm" "C standard library math functions" "The words in the " { $vocab-link "math.libm" } " vocabulary call C standard library math functions. They are used to implement words in the " { $vocab-link "math.functions" } " vocabulary." $nl "They can be called directly, however there is little reason to do so, since they only implement real-valued functions, and in some cases place restrictions on the domain:" -{ $example "2 acos ." "C{ 0.0 1.316957896924817 }" } -{ $example "2 facos ." "0.0/0.0" } +{ $example "USE: math.functions" "2 acos ." "C{ 0.0 1.316957896924817 }" } +{ $example "USE: math.libm" "2 facos ." "0.0/0.0" } "Trigonometric functions:" { $subsection fcos } { $subsection fsin } diff --git a/basis/stack-checker/stack-checker-docs.factor b/basis/stack-checker/stack-checker-docs.factor index f208178b10..5b67cd9adc 100644 --- a/basis/stack-checker/stack-checker-docs.factor +++ b/basis/stack-checker/stack-checker-docs.factor @@ -21,7 +21,7 @@ $nl ARTICLE: "inference-combinators" "Combinator stack effects" "Without further information, one cannot say what the stack effect of " { $link call } " is; it depends on the given quotation. If the inferencer encounters a " { $link call } " without further information, a " { $link literal-expected } " error is raised." -{ $example "[ dup call ] infer." "... an error ..." } +{ $example "[ dup call ] infer." "Literal value expected\n\nType :help for debugging help." } "On the other hand, the stack effect of applying " { $link call } " to a literal quotation or a " { $link curry } " of a literal quotation is easy to compute; it behaves as if the quotation was substituted at that point:" { $example "[ [ 2 + ] call ] infer." "( object -- object )" } "Consider a combinator such as " { $link keep } ". The combinator itself does not have a stack effect, because it applies " { $link call } " to a potentially arbitrary quotation. However, since the combinator is declared " { $link POSTPONE: inline } ", a given usage of it can have a stack effect:" @@ -35,7 +35,15 @@ $nl "Here is an example where the stack effect cannot be inferred:" { $code ": foo 0 [ + ] ;" "[ foo reduce ] infer." } "However if " { $snippet "foo" } " was declared " { $link POSTPONE: inline } ", everything would work, since the " { $link reduce } " combinator is also " { $link POSTPONE: inline } ", and the inferencer can see the literal quotation value at the point it is passed to " { $link call } ":" -{ $example ": foo 0 [ + ] ; inline" "[ foo reduce ] infer." "( object -- object )" } ; +{ $example ": foo 0 [ + ] ; inline" "[ foo reduce ] infer." "( object -- object )" } +"Passing a literal quotation on the data stack through an inlined recursive combinator nullifies its literal status. For example, the following will not infer:" +{ $example + "[ [ reverse ] swap [ reverse ] map swap call ] infer." "Literal value expected\n\nType :help for debugging help." +} +"To make this work, pass the quotation on the retain stack instead:" +{ $example + "[ [ reverse ] [ [ reverse ] map ] dip call ] infer." "( object -- object )" +} ; ARTICLE: "inference-branches" "Branch stack effects" "Conditionals such as " { $link if } " and combinators built on " { $link if } " present a problem, in that if the two branches leave the stack at a different height, it is not clear what the stack effect should be. In this case, inference throws a " { $link unbalanced-branches-error } "." @@ -58,12 +66,14 @@ $nl $nl "If a recursive word takes quotation parameters from the stack and calls them, it must be declared " { $link POSTPONE: inline } " (as documented in " { $link "inference-combinators" } ") as well as " { $link POSTPONE: recursive } "." $nl -"Furthermore, the input parameters which are quotations must be annotated in the stack effect. For example," -{ $see loop } -"An inline recursive word cannot pass a quotation through the recursive call. For example, the following will not infer:" -{ $code ": foo ( a b c -- d e f ) [ f foo drop ] when 2dup call ; inline" "[ 1 [ 1+ ] foo ] infer." } +"Furthermore, the input parameters which are quotations must be annotated in the stack effect. For example, the following will not infer:" +{ $example ": bad ( quot -- ) [ call ] keep foo ; inline recursive" "[ [ ] bad ] infer." "Literal value expected\n\nType :help for debugging help." } +"The following is correct:" +{ $example ": good ( quot: ( -- ) -- ) [ call ] keep good ; inline recursive" "[ [ ] good ] infer." "( -- )" } +"An inline recursive word cannot pass a quotation on the data stack through the recursive call. For example, the following will not infer:" +{ $example ": bad ( ? quot: ( ? -- ) -- ) 2dup [ not ] dip bad call ; inline recursive" "[ [ drop ] bad ] infer." "Literal value expected\n\nType :help for debugging help." } "However a small change can be made:" -{ $example ": foo ( a b c -- d ) [ 2dup f foo drop ] when call ; inline" "[ 1 [ 1+ ] t foo ] infer." "( -- object )" } +{ $example ": good ( ? quot: ( ? -- ) -- ) [ good ] 2keep [ not ] dip call ; inline recursive" "[ [ drop ] good ] infer." "( object -- )" } "An inline recursive word must have a fixed stack effect in its base case. The following will not infer:" { $code ": foo ( quot ? -- ) [ f foo ] [ call ] if ; inline" diff --git a/basis/xml-rpc/xml-rpc.factor b/basis/xml-rpc/xml-rpc.factor index 602fb90172..d2fd111b39 100644 --- a/basis/xml-rpc/xml-rpc.factor +++ b/basis/xml-rpc/xml-rpc.factor @@ -3,7 +3,7 @@ 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 ; +debugger calendar.format math.order xml.interpolate ; IN: xml-rpc ! * Sending RPC requests @@ -15,56 +15,70 @@ GENERIC: item>xml ( object -- xml ) M: integer item>xml dup 31 2^ neg 31 2^ 1 - between? [ "Integers must fit in 32 bits" throw ] unless - number>string "i4" build-tag ; + number>string [XML <-> XML] ; UNION: boolean t POSTPONE: f ; M: boolean item>xml - "1" "0" ? "boolean" build-tag ; + "1" "0" ? [XML <-> XML] ; M: float item>xml - number>string "double" build-tag ; + number>string [XML <-> XML] ; -M: string item>xml ! This should change < and & - "string" build-tag ; +M: string item>xml + [XML <-> XML] ; : struct-member ( name value -- tag ) - swap dup string? - [ "Struct member name must be string" throw ] unless - "name" build-tag swap - item>xml "value" build-tag - 2array "member" build-tag* ; + over string? [ "Struct member name must be string" throw ] unless + item>xml + [XML + + <-> + <-> + + XML] ; M: hashtable item>xml [ struct-member ] { } assoc>map - "struct" build-tag* ; + [XML <-> XML] ; M: array item>xml - [ item>xml "value" build-tag ] map - "data" build-tag* "array" build-tag ; + [ item>xml [XML <-> XML] ] map + [XML <-> XML] ; TUPLE: base64 string ; C: base64 M: base64 item>xml - string>> >base64 "base64" build-tag ; + string>> >base64 + [XML <-> XML] ; : params ( seq -- xml ) - [ item>xml "value" build-tag "param" build-tag ] map - "params" build-tag* ; + [ item>xml [XML <-> XML] ] map + [XML <-> XML] ; : method-call ( name seq -- xml ) - params [ "methodName" build-tag ] dip - 2array "methodCall" build-tag* build-xml ; + params + + <-> + <-> + + XML> ; : return-params ( seq -- xml ) - params "methodResponse" build-tag build-xml ; + params <-> XML> ; : return-fault ( fault-code fault-string -- xml ) [ "faultString" set "faultCode" set ] H{ } make-assoc item>xml - "value" build-tag "fault" build-tag "methodResponse" build-tag - build-xml ; + + + <-> + + + XML> ; TUPLE: rpc-method name params ; diff --git a/basis/xml/data/data-docs.factor b/basis/xml/data/data-docs.factor index 9a8c535f91..52394ccc5c 100644 --- a/basis/xml/data/data-docs.factor +++ b/basis/xml/data/data-docs.factor @@ -4,7 +4,7 @@ IN: xml.data ABOUT: "xml.data" ARTICLE: "xml.data" "XML data types" -{ $vocab-link "xml.data" } " defines a simple document object model for XML. Everything is simply a tuple and can be manipulated as such." +"The " { $vocab-link "xml.data" } " vocabulary defines a simple document object model for XML. Everything is simply a tuple and can be manipulated as such." { $subsection { "xml.data" "classes" } } { $subsection { "xml.data" "constructors" } } "Simple words for manipulating names:" @@ -49,7 +49,7 @@ ARTICLE: { "xml.data" "constructors" } "XML data constructors" { $subsection } ; HELP: tag -{ $class-description "tuple representing an XML tag, delegating to a " { $link +{ $class-description "Tuple representing an XML tag, delegating to a " { $link name } ", containing the slots attrs (an alist of names to strings) and children (a sequence). Tags implement the sequence protocol by acting like a sequence of its chidren, and the assoc protocol by acting like its attributes." } { $see-also name contained-tag xml } ; @@ -58,32 +58,32 @@ HELP: { "attrs" "an alist of names to strings" } { "children" sequence } { "tag" tag } } -{ $description "constructs an XML " { $link tag } " with the name (not a string) and tag attributes specified in attrs and children specified" } +{ $description "Constructs an XML " { $link tag } " with the name (not a string) and tag attributes specified in attrs and children specified." } { $see-also tag } ; HELP: name -{ $class-description "represents an XML name, with the fields space (a string representing the namespace, as written in the document, tag (a string of the actual name of the tag) and url (a string of the URL that the namespace points to)" } +{ $class-description "Represents an XML name, with the fields space (a string representing the namespace, as written in the document, tag (a string of the actual name of the tag) and url (a string of the URL that the namespace points to)." } { $see-also tag } ; HELP: { $values { "space" "a string" } { "main" "a string" } { "url" "a string" } { "name" "an XML tag name" } } -{ $description "creates a name tuple with the name-space space and the tag-name tag and the tag-url url." } +{ $description "Creates a name tuple with the namespace prefix space, the the given main part of the name, and the namespace URL given by url." } { $see-also name } ; HELP: contained-tag -{ $class-description "delegates to tag representing a tag like with no contents. The tag attributes are accessed with tag-attrs" } +{ $class-description "This is a subclass of " { $link tag } " consisting of tags with no body, like " { $snippet "" } "." } { $see-also tag } ; HELP: { $values { "name" "an XML tag name" } { "attrs" "an alist from names to strings" } { "tag" tag } } -{ $description "creates an empty tag (like ) with the specified name and tag attributes. This delegates to tag" } +{ $description "Creates an empty tag (like " { $snippet "" } ") with the specified name and tag attributes." } { $see-also contained-tag } ; HELP: xml -{ $class-description "tuple representing an XML document, delegating to the main tag, containing the fields prolog (the header ), before (whatever comes between the prolog and the main tag) and after (whatever comes after the main tag)" } +{ $class-description "Tuple representing an XML document, delegating to the main tag, containing the fields prolog (the header " { $snippet "" } "), before (whatever comes between the prolog and the main tag) and after (whatever comes after the main tag)." } { $see-also tag prolog } ; HELP: @@ -159,35 +159,35 @@ HELP: { $description "Creates an element declaration object, of the class " { $link element-decl } } ; HELP: attlist-decl -{ $class-description "Describes the class of element declarations, like ." } ; +{ $class-description "Describes the class of element declarations, like " { $snippet "" } "." } ; HELP: { $values { "name" name } { "att-defs" string } { "attlist-decl" attlist-decl } } { $description "Creates an element declaration object, of the class " { $link attlist-decl } } ; HELP: entity-decl -{ $class-description "Describes the class of element declarations, like ." } ; +{ $class-description "Describes the class of element declarations, like " { $snippet "" } "." } ; HELP: { $values { "name" name } { "def" string } { "pe?" "t or f" } { "entity-decl" entity-decl } } -{ $description "Creates an entity declaration object, of the class " { $link entity-decl } ". The pe? slot should be t if the object is a DTD-internal entity, like and f if the object is like , that is, it can be used outside of the DTD." } ; +{ $description "Creates an entity declaration object, of the class " { $link entity-decl } ". The pe? slot should be t if the object is a DTD-internal entity, like " { $snippet "" } " and f if the object is like " { $snippet "" } ", that is, it can be used outside of the DTD." } ; HELP: system-id -{ $class-description "Describes the class of system identifiers within an XML DTD directive, such as " } ; +{ $class-description "Describes the class of system identifiers within an XML DTD directive, such as " { $snippet "" } } ; HELP: { $values { "system-literal" string } { "system-id" system-id } } { $description "Constructs a " { $link system-id } " tuple." } ; HELP: public-id -{ $class-description "Describes the class of public identifiers within an XML DTD directive, such as " } ; +{ $class-description "Describes the class of public identifiers within an XML DTD directive, such as " { $snippet "" } } ; HELP: { $values { "pubid-literal" string } { "system-literal" string } { "public-id" public-id } } { $description "Constructs a " { $link system-id } " tuple." } ; HELP: notation-decl -{ $class-description "Describes the class of element declarations, like ." } ; +{ $class-description "Describes the class of element declarations, like " { $snippet "" } "." } ; HELP: { $values { "name" string } { "id" id } { "notation-decl" notation-decl } } diff --git a/basis/xml/data/data.factor b/basis/xml/data/data.factor index b014a96180..c44250035a 100644 --- a/basis/xml/data/data.factor +++ b/basis/xml/data/data.factor @@ -216,3 +216,6 @@ M: xml like PREDICATE: contained-tag < tag children>> not ; PREDICATE: open-tag < tag children>> ; + +UNION: xml-data + tag comment string directive instruction ; diff --git a/basis/xml/elements/elements.factor b/basis/xml/elements/elements.factor index b2280bacb4..57e91cc24e 100644 --- a/basis/xml/elements/elements.factor +++ b/basis/xml/elements/elements.factor @@ -3,16 +3,15 @@ USING: kernel namespaces xml.tokenize xml.state xml.name xml.data accessors arrays make xml.char-classes fry assocs sequences math xml.errors sets combinators io.encodings io.encodings.iana -unicode.case xml.dtd strings xml.entities ; +unicode.case xml.dtd strings xml.entities unicode.categories ; IN: xml.elements : take-interpolated ( quot -- interpolated ) interpolating? get [ drop get-char CHAR: > = - [ next f ] [ - pass-blank " \t\r\n-" take-to - pass-blank "->" expect - ] if + [ next f ] + [ "->" take-string [ blank? ] trim ] + if ] [ call ] if ; inline : interpolate-quote ( -- interpolated ) diff --git a/basis/xml/entities/entities.factor b/basis/xml/entities/entities.factor index a730474f20..3e768b1b88 100644 --- a/basis/xml/entities/entities.factor +++ b/basis/xml/entities/entities.factor @@ -16,6 +16,7 @@ IN: xml.entities { CHAR: & "&" } { CHAR: ' "'" } { CHAR: " """ } + { CHAR: < "<" } } ; : escape-string-by ( str table -- escaped ) diff --git a/basis/xml/errors/errors-docs.factor b/basis/xml/errors/errors-docs.factor index b95aecc47a..46c4fbe466 100644 --- a/basis/xml/errors/errors-docs.factor +++ b/basis/xml/errors/errors-docs.factor @@ -10,44 +10,68 @@ HELP: notags { $class-description "XML parsing error describing the case where an XML document contains no main tag, or any tags at all" } ; HELP: extra-attrs -{ $class-description "XML parsing error describing the case where the XML prolog () contains attributes other than the three allowed ones, standalone, version and encoding. Contains one slot, attrs, which is a hashtable of all the extra attributes' names. Delegates to " { $link parsing-error } "." } ; +{ $class-description "XML parsing error describing the case where the XML prolog (" { $snippet "" } ") contains attributes other than the three allowed ones, standalone, version and encoding. Contains one slot, attrs, which is a hashtable of all the extra attributes' names. Delegates to " { $link xml-error-at } "." } ; HELP: nonexist-ns -{ $class-description "XML parsing error describing the case where a namespace doesn't exist but it is used in a tag. Contains one slot, name, which contains the name of the undeclared namespace, and delegates to " { $link parsing-error } "." } ; +{ $class-description "XML parsing error describing the case where a namespace doesn't exist but it is used in a tag. Contains one slot, name, which contains the name of the undeclared namespace, and delegates to " { $link xml-error-at } "." } ; HELP: not-yes/no -{ $class-description "XML parsing error used to describe the case where standalone is set in the XML prolog to something other than 'yes' or 'no'. Delegates to " { $link parsing-error } " and contains one slot, text, which contains offending value." } ; +{ $class-description "XML parsing error used to describe the case where standalone is set in the XML prolog to something other than 'yes' or 'no'. Delegates to " { $link xml-error-at } " and contains one slot, text, which contains offending value." } ; HELP: unclosed { $class-description "XML parsing error used to describe the case where the XML document contains classes which are not closed by the end of the document. Contains one slot, tags, a sequence of names." } ; HELP: mismatched -{ $class-description "XML parsing error describing mismatched tags, eg . Contains two slots: open is the name of the opening tag and close is the name of the closing tag. Delegates to " { $link parsing-error } " showing the location of the closing tag" } ; +{ $class-description "XML parsing error describing mismatched tags, eg " { $snippet "" } ". Contains two slots: open is the name of the opening tag and close is the name of the closing tag. Delegates to " { $link xml-error-at } " showing the location of the closing tag" } ; HELP: expected -{ $class-description "XML parsing error describing when an expected token was not present. Delegates to " { $link parsing-error } ". Contains two slots, should-be, which has the expected string, and was, which has the actual string." } ; +{ $class-description "XML parsing error describing when an expected token was not present. Delegates to " { $link xml-error-at } ". Contains two slots, should-be, which has the expected string, and was, which has the actual string." } ; HELP: no-entity -{ $class-description "XML parsing error describing the use of an undefined entity in a case where standalone is marked yes. Delegates to " { $link parsing-error } ". Contains one slot, thing, containing a string representing the entity." } ; +{ $class-description "XML parsing error describing the use of an undefined entity in a case where standalone is marked yes. Delegates to " { $link xml-error-at } ". Contains one slot, thing, containing a string representing the entity." } ; HELP: pre/post-content -{ $class-description "describes the error where a non-whitespace string is used before or after the main tag in an XML document. Contains two slots: string contains the offending string, and pre? is t if it occured before the main tag and f if it occured after" } ; +{ $class-description "Describes the error where a non-whitespace string is used before or after the main tag in an XML document. Contains two slots: string contains the offending string, and pre? is t if it occured before the main tag and f if it occured after" } ; HELP: unclosed-quote -{ $class-description "describes the error where a quotation for an attribute value is opened but not closed before the end of the document." } ; +{ $class-description "Describes the error where a quotation for an attribute value is opened but not closed before the end of the document." } ; HELP: bad-name -{ $class-description "describes the error where a name is used, for example in an XML tag or attribute key, which is invalid." } ; +{ $class-description "Describes the error where a name is used, for example in an XML tag or attribute key, which is invalid." } ; HELP: quoteless-attr -{ $class-description "describes the error where an attribute of an XML tag is missing quotes around a value." } ; +{ $class-description "Describes the error where an attribute of an XML tag is missing quotes around a value." } ; -HELP: xml-parse-error -{ $class-description "the exception class that all parsing errors in XML documents are in." } ; +HELP: disallowed-char +{ $class-description "Describes the error where a disallowed character occurs in an XML document." } ; + +HELP: missing-close +{ $class-description "Describes the error where a particular closing token is missing." } ; + +HELP: unexpected-end +{ $class-description "Describes the error where a document unexpectedly ends, and the XML parser expected it to continue." } ; + +HELP: duplicate-attr +{ $class-description "Describes the error where there is more than one attribute of the same key." } ; + +HELP: bad-cdata +{ $class-description "Describes the error where CDATA is used outside of the main tag of an XML document." } ; + +HELP: text-w/]]> +{ $class-description "Describes the error where a text node contains the literal string " { $snippet "]]>" } " which is disallowed." } ; + +HELP: attr-w/< +{ $class-description "Describes the error where an attribute value contains the literal character " { $snippet "<" } " which is disallowed." } ; + +HELP: misplaced-directive +{ $class-description "Describes the error where an internal DTD directive is used outside of a DOCTYPE or DTD file, or where a DOCTYPE occurs somewhere other than before the main tag of an XML document." } ; + +HELP: xml-error +{ $class-description "The exception class that all parsing errors in XML documents are in." } ; ARTICLE: "xml.errors" "XML parsing errors" - { $vocab-link "xml.errors" } " provides a rich and highly inspectable set of parsing errors. All XML errors are described by the union class " { $link xml-parse-error } " but there are many classes contained in that:" +"The " { $vocab-link "xml.errors" } " vocabulary provides a rich and highly inspectable set of parsing errors. All XML errors are described by the union class " { $link xml-error } " but there are many classes contained in that:" { $subsection multitags } { $subsection notags } { $subsection extra-attrs } @@ -61,7 +85,15 @@ ARTICLE: "xml.errors" "XML parsing errors" { $subsection unclosed-quote } { $subsection bad-name } { $subsection quoteless-attr } - "Additionally, most of these errors are a kind of " { $link parsing-error } " which provides more information" + { $subsection disallowed-char } + { $subsection missing-close } + { $subsection unexpected-end } + { $subsection duplicate-attr } + { $subsection bad-cdata } + { $subsection text-w/]]> } + { $subsection attr-w/< } + { $subsection misplaced-directive } + "Additionally, most of these errors are a kind of " { $link xml-error-at } " which provides more information" $nl "Note that, in parsing an XML document, only the first error is reported." ; diff --git a/basis/xml/errors/errors-tests.factor b/basis/xml/errors/errors-tests.factor index bf02f4b6ca..4204979941 100644 --- a/basis/xml/errors/errors-tests.factor +++ b/basis/xml/errors/errors-tests.factor @@ -27,12 +27,16 @@ T{ pre/post-content f "x" t } "x" xml-error-test T{ versionless-prolog f 1 8 } "" xml-error-test T{ unclosed-quote f 1 13 } "" xml-error-test T{ text-w/]]> f 1 6 } "]]>" xml-error-test T{ duplicate-attr f 1 21 T{ name { space "" } { main "this" } } V{ "a" "b" } } "" xml-error-test T{ bad-cdata f 1 3 } "" xml-error-test T{ bad-cdata f 1 7 } "" xml-error-test -T{ pre/post-content f "&" t } "&32;" xml-error-test +T{ pre/post-content f "&" t } " " xml-error-test T{ bad-doctype f 1 17 "a" } "" xml-error-test T{ bad-doctype f 1 22 T{ opener { name T{ name f "" "foo" "" } } { attrs T{ attrs } } } } " ]>" xml-error-test +T{ disallowed-char f 1 3 1 } "\u000001" xml-error-test +T{ missing-close f 1 9 } "