Merge branch 'master' of git://github.com/slavapestov/factor

db4
John Benediktsson 2011-01-29 07:33:17 -08:00
commit 1cc5aef4d1
23 changed files with 243 additions and 222 deletions

View File

@ -23,7 +23,7 @@ HELP: equate
HELP: assoc>disjoint-set HELP: assoc>disjoint-set
{ $values { "assoc" assoc } { "disjoint-set" disjoint-set } } { $values { "assoc" assoc } { "disjoint-set" disjoint-set } }
{ $description "Given an assoc representation of a graph where the keys are vertices and key/value pairs are edges, creates a disjoint set whose elements are the keys of assoc, and two keys are equvalent if they belong to the same connected component of the graph." } { $description "Given an assoc representation of a graph where the keys are vertices and key/value pairs are edges, creates a disjoint set whose elements are the keys of assoc, and two keys are equivalent if they belong to the same connected component of the graph." }
{ $examples { $examples
{ $example { $example
"USING: disjoint-sets kernel prettyprint ;" "USING: disjoint-sets kernel prettyprint ;"

View File

@ -102,7 +102,7 @@ $nl
"For example, we'd like it to identify the following as a palindrome:" "For example, we'd like it to identify the following as a palindrome:"
{ $code "\"A man, a plan, a canal: Panama.\"" } { $code "\"A man, a plan, a canal: Panama.\"" }
"However, right now, the simplistic algorithm we use says this is not a palindrome:" "However, right now, the simplistic algorithm we use says this is not a palindrome:"
{ $unchecked-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" } ":" "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" } { $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:" "If you now run unit tests, you will see a unit test failure:"

View File

@ -184,23 +184,23 @@ HELP: interval-max
HELP: interval-mod HELP: interval-mod
{ $values { "i1" interval } { "i2" interval } { "i3" interval } } { $values { "i1" interval } { "i2" interval } { "i3" interval } }
{ $description "Outputs an interval containing all possible values obtained by aplying " { $link mod } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ; { $description "Outputs an interval containing all possible values obtained by applying " { $link mod } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ;
HELP: interval-rem HELP: interval-rem
{ $values { "i1" interval } { "i2" interval } { "i3" interval } } { $values { "i1" interval } { "i2" interval } { "i3" interval } }
{ $description "Outputs an interval containing all possible values obtained by aplying " { $link rem } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ; { $description "Outputs an interval containing all possible values obtained by applying " { $link rem } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ;
HELP: interval-bitand HELP: interval-bitand
{ $values { "i1" interval } { "i2" interval } { "i3" interval } } { $values { "i1" interval } { "i2" interval } { "i3" interval } }
{ $description "Outputs an interval containing all possible values obtained by aplying " { $link bitand } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ; { $description "Outputs an interval containing all possible values obtained by applying " { $link bitand } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ;
HELP: interval-bitor HELP: interval-bitor
{ $values { "i1" interval } { "i2" interval } { "i3" interval } } { $values { "i1" interval } { "i2" interval } { "i3" interval } }
{ $description "Outputs an interval containing all possible values obtained by aplying " { $link bitor } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ; { $description "Outputs an interval containing all possible values obtained by applying " { $link bitor } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ;
HELP: interval-bitxor HELP: interval-bitxor
{ $values { "i1" interval } { "i2" interval } { "i3" interval } } { $values { "i1" interval } { "i2" interval } { "i3" interval } }
{ $description "Outputs an interval containing all possible values obtained by aplying " { $link bitxor } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ; { $description "Outputs an interval containing all possible values obtained by applying " { $link bitxor } " to elements of " { $snippet "i1" } " and " { $snippet "i2" } "." } ;
HELP: interval-min HELP: interval-min
{ $values { "i1" interval } { "i2" interval } { "i3" interval } } { $values { "i1" interval } { "i2" interval } { "i3" interval } }

View File

@ -62,7 +62,7 @@ HELP: n*p
HELP: pextend-conv HELP: pextend-conv
{ $values { "p" "a polynomial" } { "q" "a polynomial" } { "p'" "a polynomial" } { "q'" "a polynomial" } } { $values { "p" "a polynomial" } { "q" "a polynomial" } { "p'" "a polynomial" } { "q'" "a polynomial" } }
{ $description "Convulution, extending to " { $snippet "p_m + q_n - 1" } "." } { $description "Convolution, extending to " { $snippet "p_m + q_n - 1" } "." }
{ $examples { $example "USING: kernel math.polynomials prettyprint ;" "{ 1 0 1 } { 0 1 } pextend-conv [ . ] bi@" "{ 1 0 1 0 }\n{ 0 1 0 0 }" } } ; { $examples { $example "USING: kernel math.polynomials prettyprint ;" "{ 1 0 1 } { 0 1 } pextend-conv [ . ] bi@" "{ 1 0 1 0 }\n{ 0 1 0 0 }" } } ;
HELP: p* HELP: p*

View File

@ -34,7 +34,7 @@ HELP: range
{ $description "Computes the difference of the maximum and minimum values in " { $snippet "seq" } "." } { $description "Computes the difference of the maximum and minimum values in " { $snippet "seq" } "." }
{ $examples { $examples
{ $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } range ." "2" } { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } range ." "2" }
{ $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } range ." "3" } } ; { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } range ." "3" } } ;
HELP: minmax HELP: minmax
{ $values { "seq" sequence } { "min" real } { "max" real } } { $values { "seq" sequence } { "min" real } { "max" real } }
@ -75,34 +75,34 @@ HELP: histogram
{ "seq" sequence } { "seq" sequence }
{ "hashtable" hashtable } { "hashtable" hashtable }
} }
{ $examples { $description "Returns a hashtable where the keys are the elements of the sequence and the values are the number of times they appeared in that sequence." }
{ $examples
{ $example "! Count the number of times an element appears in a sequence." { $example "! Count the number of times an element appears in a sequence."
"USING: prettyprint math.statistics ;" "USING: prettyprint math.statistics ;"
"\"aaabc\" histogram ." "\"aaabc\" histogram ."
"H{ { 97 3 } { 98 1 } { 99 1 } }" "H{ { 97 3 } { 98 1 } { 99 1 } }"
} }
} } ;
{ $description "Returns a hashtable where the keys are the elements of the sequence and the values are the number of times they appeared in that sequence." } ;
HELP: histogram! HELP: histogram!
{ $values { $values
{ "hashtable" hashtable } { "seq" sequence } { "hashtable" hashtable } { "seq" sequence }
} }
{ $examples { $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurrences of each element." }
{ $examples
{ $example "! Count the number of times the elements of two sequences appear." { $example "! Count the number of times the elements of two sequences appear."
"USING: prettyprint math.statistics ;" "USING: prettyprint math.statistics ;"
"\"aaabc\" histogram \"aaaaaabc\" histogram! ." "\"aaabc\" histogram \"aaaaaabc\" histogram! ."
"H{ { 97 9 } { 98 2 } { 99 2 } }" "H{ { 97 9 } { 98 2 } { 99 2 } }"
} }
} } ;
{ $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;
HELP: sorted-histogram HELP: sorted-histogram
{ $values { $values
{ "seq" sequence } { "seq" sequence }
{ "alist" "an array of key/value pairs" } { "alist" "an array of key/value pairs" }
} }
{ $description "Outputs a " { $link histogram } " of a sequence sorted by number of occurences from lowest to highest." } { $description "Outputs a " { $link histogram } " of a sequence sorted by number of occurrences from lowest to highest." }
{ $examples { $examples
{ $example "USING: prettyprint math.statistics ;" { $example "USING: prettyprint math.statistics ;"
""""abababbbbbbc" sorted-histogram .""" """"abababbbbbbc" sorted-histogram ."""
@ -115,41 +115,41 @@ HELP: sequence>assoc
{ "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" } { "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }
{ "assoc" assoc } { "assoc" assoc }
} }
{ $examples { $description "Iterates over a sequence, allowing elements of the sequence to be added to a newly created " { $snippet "assoc" } " according to the passed quotation." }
{ $examples
{ $example "! Iterate over a sequence and increment the count at each element" { $example "! Iterate over a sequence and increment the count at each element"
"USING: assocs prettyprint math.statistics ;" "USING: assocs prettyprint math.statistics ;"
"\"aaabc\" [ inc-at ] H{ } sequence>assoc ." "\"aaabc\" [ inc-at ] H{ } sequence>assoc ."
"H{ { 97 3 } { 98 1 } { 99 1 } }" "H{ { 97 3 } { 98 1 } { 99 1 } }"
} }
} } ;
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to a newly created " { $snippet "assoc" } " according to the passed quotation." } ;
HELP: sequence>assoc! HELP: sequence>assoc!
{ $values { $values
{ "assoc" assoc } { "seq" sequence } { "quot" quotation } { "assoc" assoc } { "seq" sequence } { "quot" quotation }
} }
{ $examples { $description "Iterates over a sequence, allowing elements of the sequence to be added to an existing " { $snippet "assoc" } " according to the passed quotation." }
{ $examples
{ $example "! Iterate over a sequence and add the counts to an existing assoc" { $example "! Iterate over a sequence and add the counts to an existing assoc"
"USING: assocs prettyprint math.statistics kernel ;" "USING: assocs prettyprint math.statistics kernel ;"
"H{ { 97 2 } { 98 1 } } clone \"aaabc\" [ inc-at ] sequence>assoc! ." "H{ { 97 2 } { 98 1 } } clone \"aaabc\" [ inc-at ] sequence>assoc! ."
"H{ { 97 5 } { 98 2 } { 99 1 } }" "H{ { 97 5 } { 98 2 } { 99 1 } }"
} }
} } ;
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to an existing " { $snippet "assoc" } " according to the passed quotation." } ;
HELP: sequence>hashtable HELP: sequence>hashtable
{ $values { $values
{ "seq" sequence } { "quot" quotation } { "seq" sequence } { "quot" quotation }
{ "hashtable" hashtable } { "hashtable" hashtable }
} }
{ $examples { $description "Iterates over a sequence, allowing elements of the sequence to be added to a hashtable according to the passed quotation." }
{ $examples
{ $example "! Count the number of times an element occurs in a sequence" { $example "! Count the number of times an element occurs in a sequence"
"USING: assocs prettyprint math.statistics ;" "USING: assocs prettyprint math.statistics ;"
"\"aaabc\" [ inc-at ] sequence>hashtable ." "\"aaabc\" [ inc-at ] sequence>hashtable ."
"H{ { 97 3 } { 98 1 } { 99 1 } }" "H{ { 97 3 } { 98 1 } { 99 1 } }"
} }
} } ;
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to a hashtable according to the passed quotation." } ;
ARTICLE: "histogram" "Computing histograms" ARTICLE: "histogram" "Computing histograms"
"Counting elements in a sequence:" "Counting elements in a sequence:"

View File

@ -22,7 +22,8 @@ HELP: define-memoized
{ $description "Defines the given word at run time as one which memoizes its outputs given a particular input." } ; { $description "Defines the given word at run time as one which memoizes its outputs given a particular input." } ;
HELP: MEMO: HELP: MEMO:
{ $syntax "MEMO: word ( stack -- effect ) definition ;" } { $syntax "MEMO: word ( stack -- effect ) definition... ;" }
{ $values { "word" "a new word to define" } { "definition" "a word definition" } }
{ $description "Defines the given word at parse time as one which memoizes its output given a particular input. The stack effect is mandatory." } ; { $description "Defines the given word at parse time as one which memoizes its output given a particular input. The stack effect is mandatory." } ;
{ define-memoized POSTPONE: MEMO: } related-words { define-memoized POSTPONE: MEMO: } related-words

View File

@ -274,7 +274,7 @@ ARTICLE: "peg.ebnf.variable" "Variable"
; ;
ARTICLE: "peg.ebnf.foreign-rules" "Foreign Rules" ARTICLE: "peg.ebnf.foreign-rules" "Foreign Rules"
"Rules can call outto other peg.ebnf defined parsers. The result of " "Rules can call out to other peg.ebnf defined parsers. The result of "
"the foreign call then becomes the AST of the successful parse. Foreign rules " "the foreign call then becomes the AST of the successful parse. Foreign rules "
"are invoked using '<foreign word-name>' or '<foreign word-name rule>'. The " "are invoked using '<foreign word-name>' or '<foreign word-name rule>'. The "
"latter allows calling a specific rule in a previously designed peg.ebnf parser. " "latter allows calling a specific rule in a previously designed peg.ebnf parser. "

View File

@ -91,9 +91,10 @@ $nl
"However a small change can be made:" "However a small change can be made:"
{ $example ": good ( ? quot: ( ? -- ) -- ) [ good ] 2keep [ not ] dip call ; inline recursive" "[ [ drop ] good ] infer." "( x -- )" } { $example ": good ( ? quot: ( ? -- ) -- ) [ good ] 2keep [ not ] dip call ; inline recursive" "[ [ drop ] good ] infer." "( x -- )" }
"An inline recursive word must have a fixed stack effect in its base case. The following will not infer:" "An inline recursive word must have a fixed stack effect in its base case. The following will not infer:"
{ $code { $example
": foo ( quot ? -- ) [ f foo ] [ call ] if ; inline" ": foo ( quot ? -- ) [ f foo ] [ call ] if ; inline"
"[ [ 5 ] t foo ] infer." "[ [ 5 ] t foo ] infer."
"The inline recursive word “foo” must be declared recursive\nword foo"
} ; } ;
ARTICLE: "tools.inference" "Stack effect tools" ARTICLE: "tools.inference" "Stack effect tools"

View File

@ -135,4 +135,11 @@ os macosx? [
[ ] [ "tools.deploy.test.19" shake-and-bake run-temp-image ] unit-test [ ] [ "tools.deploy.test.19" shake-and-bake run-temp-image ] unit-test
[ ] [ "tools.deploy.test.20" shake-and-bake ] unit-test
[ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>Factor</foo>\n" ]
[ deploy-test-command ascii [ contents ] with-process-reader ] unit-test
[ ] [ 800000 small-enough? ] unit-test
[ ] [ "benchmark.ui-panes" shake-and-bake run-temp-image ] unit-test [ ] [ "benchmark.ui-panes" shake-and-bake run-temp-image ] unit-test

View File

@ -0,0 +1,10 @@
USING: io xml.syntax xml.writer ;
IN: tools.deploy.test.20
: test-xml ( str -- str' )
<XML <foo><-></foo> XML> xml>string ;
: main ( -- )
"Factor" test-xml print ;
MAIN: main

View File

@ -0,0 +1,14 @@
USING: tools.deploy.config ;
H{
{ deploy-name "tools.deploy.test.20" }
{ deploy-ui? f }
{ deploy-c-types? f }
{ deploy-console? t }
{ deploy-unicode? f }
{ deploy-io 2 }
{ deploy-reflection 1 }
{ deploy-word-props? f }
{ deploy-math? f }
{ deploy-threads? f }
{ deploy-word-defs? f }
}

View File

@ -139,7 +139,7 @@ HELP: closer
{ $class-description "Describes a closing tag, like " { $snippet "</a>" } ". Contains one slot, " { $snippet "name" } ", containing the closer's name." } ; { $class-description "Describes a closing tag, like " { $snippet "</a>" } ". Contains one slot, " { $snippet "name" } ", containing the closer's name." } ;
HELP: contained HELP: contained
{ $class-description "Represents a self-closing tag, like " { $snippet "<a/>" } ". Contains two slots," { $snippet "name" } " and " { $snippet "attrs" } " containing, respectively, the name of the tag and its attributes." } ; { $class-description "Represents a self-closing tag, like " { $snippet "<a/>" } ". Contains two slots, " { $snippet "name" } " and " { $snippet "attrs" } " containing, respectively, the name of the tag and its attributes." } ;
{ opener closer contained } related-words { opener closer contained } related-words

View File

@ -0,0 +1 @@
Daniel Ehrenberg

View File

@ -0,0 +1,150 @@
! Copyright (C) 2005, 2006 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: accessors debugger io kernel prettyprint sequences
xml.errors xml.writer ;
IN: xml.errors.debugger
M: xml-error-at error.
"XML parsing error" print
"Line: " write dup line>> .
"Column: " write column>> . ;
M: expected error.
dup call-next-method
"Token expected: " write dup should-be>> print
"Token present: " write was>> print ;
M: unexpected-end error.
call-next-method
"File unexpectedly ended." print ;
M: missing-close error.
call-next-method
"Missing closing token." print ;
M: disallowed-char error.
dup call-next-method
"Disallowed character in XML document: " write
char>> write1 nl ;
M: multitags error.
drop "XML document contains multiple main tags" print ;
M: pre/post-content error.
"The text string:" print
dup string>> .
"was used " write
pre?>> "before" "after" ? write
" the main tag." print ;
M: no-entity error.
dup call-next-method
"Entity does not exist: &" write thing>> write ";" print ;
M: mismatched error.
dup call-next-method
"Mismatched tags" print
"Opening tag: <" write dup open>> print-name ">" print
"Closing tag: </" write close>> print-name ">" print ;
M: unclosed error.
dup call-next-method
"Unclosed tags" print
"Tags: " print
tags>> [ " <" write print-name ">" print ] each ;
M: bad-uri error.
dup call-next-method
"Bad URI:" print string>> . ;
M: nonexist-ns error.
dup call-next-method
"Namespace " write name>> write " has not been declared" print ;
M: unopened error.
call-next-method
"Closed an unopened tag" print ;
M: not-yes/no error.
dup call-next-method
"standalone must be either yes or no, not \"" write
text>> write "\"." print ;
M: extra-attrs error.
dup call-next-method
"Extra attributes included in xml version declaration:" print
attrs>> . ;
M: bad-version error.
"XML version must be \"1.0\" or \"1.1\". Version here was " write
num>> . ;
M: notags error.
drop "XML document lacks a main tag" print ;
M: bad-prolog error.
dup call-next-method
"Misplaced XML prolog" print
prolog>> write-xml nl ;
M: capitalized-prolog error.
dup call-next-method
"XML prolog name was partially or totally capitalized, using" print
"<?" write name>> write "...?>" write
" instead of <?xml...?>" print ;
M: versionless-prolog error.
call-next-method
"XML prolog lacks a version declaration" print ;
M: bad-directive error.
dup call-next-method
"Unknown directive:" print
dir>> print ;
M: bad-decl error.
call-next-method "Extra content in directive" print ;
M: bad-external-id error.
call-next-method "Bad external ID" print ;
M: misplaced-directive error.
dup call-next-method
"Misplaced directive:" print
dir>> write-xml nl ;
M: bad-name error.
dup call-next-method
"Invalid name: " write name>> print ;
M: unclosed-quote error.
call-next-method
"XML document ends with quote still open" print ;
M: quoteless-attr error.
call-next-method "Attribute lacks quotes around value" print ;
M: attr-w/< error.
call-next-method
"Attribute value contains literal <" print ;
M: text-w/]]> error.
call-next-method
"Text node contains ']]>'" print ;
M: duplicate-attr error.
call-next-method "Duplicate attribute" print ;
M: bad-cdata error.
call-next-method "CDATA occurs before or after main tag" print ;
M: not-enough-characters error.
call-next-method
"Not enough characters" print ;
M: bad-doctype error.
call-next-method "DTD contains invalid object" print ;
M: bad-encoding error.
call-next-method
"Encoding in XML document does not exist" print ;

View File

@ -1,8 +1,7 @@
! Copyright (C) 2005, 2006 Daniel Ehrenberg ! Copyright (C) 2005, 2006 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: xml.data xml.writer kernel generic io prettyprint math USING: accessors kernel namespaces sequences vocabs.loader
debugger sequences xml.state accessors summary xml.state ;
namespaces io.streams.string ;
IN: xml.errors IN: xml.errors
TUPLE: xml-error-at line column ; TUPLE: xml-error-at line column ;
@ -11,91 +10,41 @@ TUPLE: xml-error-at line column ;
new new
get-line >>line get-line >>line
get-column >>column ; get-column >>column ;
M: xml-error-at summary ( obj -- str )
[
"XML parsing error" print
"Line: " write dup line>> .
"Column: " write column>> .
] with-string-writer ;
TUPLE: expected < xml-error-at should-be was ; TUPLE: expected < xml-error-at should-be was ;
: expected ( should-be was -- * ) : expected ( should-be was -- * )
\ expected xml-error-at \ expected xml-error-at
swap >>was swap >>was
swap >>should-be throw ; swap >>should-be throw ;
M: expected summary ( obj -- str )
[
dup call-next-method write
"Token expected: " write dup should-be>> print
"Token present: " write was>> print
] with-string-writer ;
TUPLE: unexpected-end < xml-error-at ; TUPLE: unexpected-end < xml-error-at ;
: unexpected-end ( -- * ) \ unexpected-end xml-error-at throw ; : unexpected-end ( -- * ) \ unexpected-end xml-error-at throw ;
M: unexpected-end summary ( obj -- str )
[
call-next-method write
"File unexpectedly ended." print
] with-string-writer ;
TUPLE: missing-close < xml-error-at ; TUPLE: missing-close < xml-error-at ;
: missing-close ( -- * ) \ missing-close xml-error-at throw ; : missing-close ( -- * ) \ missing-close xml-error-at throw ;
M: missing-close summary ( obj -- str )
[
call-next-method write
"Missing closing token." print
] with-string-writer ;
TUPLE: disallowed-char < xml-error-at char ; TUPLE: disallowed-char < xml-error-at char ;
: disallowed-char ( char -- * ) : disallowed-char ( char -- * )
\ disallowed-char xml-error-at swap >>char throw ; \ disallowed-char xml-error-at swap >>char throw ;
M: disallowed-char summary
[ call-next-method ]
[ char>> "Disallowed character in XML document: " swap suffix ] bi
append ;
ERROR: multitags ; ERROR: multitags ;
M: multitags summary ( obj -- str )
drop "XML document contains multiple main tags" ;
ERROR: pre/post-content string pre? ; ERROR: pre/post-content string pre? ;
M: pre/post-content summary ( obj -- str )
[
"The text string:" print
dup string>> .
"was used " write
pre?>> "before" "after" ? write
" the main tag." print
] with-string-writer ;
TUPLE: no-entity < xml-error-at thing ; TUPLE: no-entity < xml-error-at thing ;
: no-entity ( string -- * ) : no-entity ( string -- * )
\ no-entity xml-error-at swap >>thing throw ; \ no-entity xml-error-at swap >>thing throw ;
M: no-entity summary ( obj -- str )
[
dup call-next-method write
"Entity does not exist: &" write thing>> write ";" print
] with-string-writer ;
TUPLE: mismatched < xml-error-at open close ; TUPLE: mismatched < xml-error-at open close ;
: mismatched ( open close -- * ) : mismatched ( open close -- * )
\ mismatched xml-error-at swap >>close swap >>open throw ; \ mismatched xml-error-at swap >>close swap >>open throw ;
M: mismatched summary ( obj -- str )
[
dup call-next-method write
"Mismatched tags" print
"Opening tag: <" write dup open>> print-name ">" print
"Closing tag: </" write close>> print-name ">" print
] with-string-writer ;
TUPLE: unclosed < xml-error-at tags ; TUPLE: unclosed < xml-error-at tags ;
: unclosed ( -- * ) : unclosed ( -- * )
@ -103,249 +52,129 @@ TUPLE: unclosed < xml-error-at tags ;
xml-stack get rest-slice [ first name>> ] map >>tags xml-stack get rest-slice [ first name>> ] map >>tags
throw ; throw ;
M: unclosed summary ( obj -- str )
[
dup call-next-method write
"Unclosed tags" print
"Tags: " print
tags>> [ " <" write print-name ">" print ] each
] with-string-writer ;
TUPLE: bad-uri < xml-error-at string ; TUPLE: bad-uri < xml-error-at string ;
: bad-uri ( string -- * ) : bad-uri ( string -- * )
\ bad-uri xml-error-at swap >>string throw ; \ bad-uri xml-error-at swap >>string throw ;
M: bad-uri summary ( obj -- str )
[
dup call-next-method write
"Bad URI:" print string>> .
] with-string-writer ;
TUPLE: nonexist-ns < xml-error-at name ; TUPLE: nonexist-ns < xml-error-at name ;
: nonexist-ns ( name-string -- * ) : nonexist-ns ( name-string -- * )
\ nonexist-ns xml-error-at swap >>name throw ; \ nonexist-ns xml-error-at swap >>name throw ;
M: nonexist-ns summary ( obj -- str ) ! this should give which tag was unopened
[ TUPLE: unopened < xml-error-at ;
dup call-next-method write
"Namespace " write name>> write " has not been declared" print
] with-string-writer ;
TUPLE: unopened < xml-error-at ; ! this should give which tag was unopened
: unopened ( -- * ) : unopened ( -- * )
\ unopened xml-error-at throw ; \ unopened xml-error-at throw ;
M: unopened summary ( obj -- str )
[
call-next-method write
"Closed an unopened tag" print
] with-string-writer ;
TUPLE: not-yes/no < xml-error-at text ; TUPLE: not-yes/no < xml-error-at text ;
: not-yes/no ( text -- * ) : not-yes/no ( text -- * )
\ not-yes/no xml-error-at swap >>text throw ; \ not-yes/no xml-error-at swap >>text throw ;
M: not-yes/no summary ( obj -- str )
[
dup call-next-method write
"standalone must be either yes or no, not \"" write
text>> write "\"." print
] with-string-writer ;
! this should actually print the names ! this should actually print the names
TUPLE: extra-attrs < xml-error-at attrs ; TUPLE: extra-attrs < xml-error-at attrs ;
: extra-attrs ( attrs -- * ) : extra-attrs ( attrs -- * )
\ extra-attrs xml-error-at swap >>attrs throw ; \ extra-attrs xml-error-at swap >>attrs throw ;
M: extra-attrs summary ( obj -- str )
[
dup call-next-method write
"Extra attributes included in xml version declaration:" print
attrs>> .
] with-string-writer ;
TUPLE: bad-version < xml-error-at num ; TUPLE: bad-version < xml-error-at num ;
: bad-version ( num -- * ) : bad-version ( num -- * )
\ bad-version xml-error-at swap >>num throw ; \ bad-version xml-error-at swap >>num throw ;
M: bad-version summary ( obj -- str )
[
"XML version must be \"1.0\" or \"1.1\". Version here was " write
num>> .
] with-string-writer ;
ERROR: notags ; ERROR: notags ;
M: notags summary ( obj -- str )
drop "XML document lacks a main tag" ;
TUPLE: bad-prolog < xml-error-at prolog ; TUPLE: bad-prolog < xml-error-at prolog ;
: bad-prolog ( prolog -- * ) : bad-prolog ( prolog -- * )
\ bad-prolog xml-error-at swap >>prolog throw ; \ bad-prolog xml-error-at swap >>prolog throw ;
M: bad-prolog summary ( obj -- str )
[
dup call-next-method write
"Misplaced XML prolog" print
prolog>> write-xml nl
] with-string-writer ;
TUPLE: capitalized-prolog < xml-error-at name ; TUPLE: capitalized-prolog < xml-error-at name ;
: capitalized-prolog ( name -- capitalized-prolog ) : capitalized-prolog ( name -- capitalized-prolog )
\ capitalized-prolog xml-error-at swap >>name throw ; \ capitalized-prolog xml-error-at swap >>name throw ;
M: capitalized-prolog summary ( obj -- str )
[
dup call-next-method write
"XML prolog name was partially or totally capitalized, using" print
"<?" write name>> write "...?>" write
" instead of <?xml...?>" print
] with-string-writer ;
TUPLE: versionless-prolog < xml-error-at ; TUPLE: versionless-prolog < xml-error-at ;
: versionless-prolog ( -- * ) : versionless-prolog ( -- * )
\ versionless-prolog xml-error-at throw ; \ versionless-prolog xml-error-at throw ;
M: versionless-prolog summary ( obj -- str )
[
call-next-method write
"XML prolog lacks a version declaration" print
] with-string-writer ;
TUPLE: bad-directive < xml-error-at dir ; TUPLE: bad-directive < xml-error-at dir ;
: bad-directive ( directive -- * ) : bad-directive ( directive -- * )
\ bad-directive xml-error-at swap >>dir throw ; \ bad-directive xml-error-at swap >>dir throw ;
M: bad-directive summary ( obj -- str )
[
dup call-next-method write
"Unknown directive:" print
dir>> write
] with-string-writer ;
TUPLE: bad-decl < xml-error-at ; TUPLE: bad-decl < xml-error-at ;
: bad-decl ( -- * ) : bad-decl ( -- * )
\ bad-decl xml-error-at throw ; \ bad-decl xml-error-at throw ;
M: bad-decl summary ( obj -- str )
call-next-method "\nExtra content in directive" append ;
TUPLE: bad-external-id < xml-error-at ; TUPLE: bad-external-id < xml-error-at ;
: bad-external-id ( -- * ) : bad-external-id ( -- * )
\ bad-external-id xml-error-at throw ; \ bad-external-id xml-error-at throw ;
M: bad-external-id summary ( obj -- str )
call-next-method "\nBad external ID" append ;
TUPLE: misplaced-directive < xml-error-at dir ; TUPLE: misplaced-directive < xml-error-at dir ;
: misplaced-directive ( directive -- * ) : misplaced-directive ( directive -- * )
\ misplaced-directive xml-error-at swap >>dir throw ; \ misplaced-directive xml-error-at swap >>dir throw ;
M: misplaced-directive summary ( obj -- str )
[
dup call-next-method write
"Misplaced directive:" print
dir>> write-xml nl
] with-string-writer ;
TUPLE: bad-name < xml-error-at name ; TUPLE: bad-name < xml-error-at name ;
: bad-name ( name -- * ) : bad-name ( name -- * )
\ bad-name xml-error-at swap >>name throw ; \ bad-name xml-error-at swap >>name throw ;
M: bad-name summary ( obj -- str )
[ call-next-method ]
[ "Invalid name: " swap name>> "\n" 3append ]
bi append ;
TUPLE: unclosed-quote < xml-error-at ; TUPLE: unclosed-quote < xml-error-at ;
: unclosed-quote ( -- * ) : unclosed-quote ( -- * )
\ unclosed-quote xml-error-at throw ; \ unclosed-quote xml-error-at throw ;
M: unclosed-quote summary
call-next-method
"XML document ends with quote still open\n" append ;
TUPLE: quoteless-attr < xml-error-at ; TUPLE: quoteless-attr < xml-error-at ;
: quoteless-attr ( -- * ) : quoteless-attr ( -- * )
\ quoteless-attr xml-error-at throw ; \ quoteless-attr xml-error-at throw ;
M: quoteless-attr summary
call-next-method "Attribute lacks quotes around value\n" append ;
TUPLE: attr-w/< < xml-error-at ; TUPLE: attr-w/< < xml-error-at ;
: attr-w/< ( -- * ) : attr-w/< ( -- * )
\ attr-w/< xml-error-at throw ; \ attr-w/< xml-error-at throw ;
M: attr-w/< summary
call-next-method
"Attribute value contains literal <" append ;
TUPLE: text-w/]]> < xml-error-at ; TUPLE: text-w/]]> < xml-error-at ;
: text-w/]]> ( -- * ) : text-w/]]> ( -- * )
\ text-w/]]> xml-error-at throw ; \ text-w/]]> xml-error-at throw ;
M: text-w/]]> summary
call-next-method
"Text node contains ']]>'" append ;
TUPLE: duplicate-attr < xml-error-at key values ; TUPLE: duplicate-attr < xml-error-at key values ;
: duplicate-attr ( key values -- * ) : duplicate-attr ( key values -- * )
\ duplicate-attr xml-error-at \ duplicate-attr xml-error-at
swap >>values swap >>key throw ; swap >>values swap >>key throw ;
M: duplicate-attr summary
call-next-method "\nDuplicate attribute" append ;
TUPLE: bad-cdata < xml-error-at ; TUPLE: bad-cdata < xml-error-at ;
: bad-cdata ( -- * ) : bad-cdata ( -- * )
\ bad-cdata xml-error-at throw ; \ bad-cdata xml-error-at throw ;
M: bad-cdata summary
call-next-method "\nCDATA occurs before or after main tag" append ;
TUPLE: not-enough-characters < xml-error-at ; TUPLE: not-enough-characters < xml-error-at ;
: not-enough-characters ( -- * ) : not-enough-characters ( -- * )
\ not-enough-characters xml-error-at throw ; \ not-enough-characters xml-error-at throw ;
M: not-enough-characters summary ( obj -- str )
[
call-next-method write
"Not enough characters" print
] with-string-writer ;
TUPLE: bad-doctype < xml-error-at contents ; TUPLE: bad-doctype < xml-error-at contents ;
: bad-doctype ( contents -- * ) : bad-doctype ( contents -- * )
\ bad-doctype xml-error-at swap >>contents throw ; \ bad-doctype xml-error-at swap >>contents throw ;
M: bad-doctype summary
call-next-method "\nDTD contains invalid object" append ;
TUPLE: bad-encoding < xml-error-at encoding ; TUPLE: bad-encoding < xml-error-at encoding ;
: bad-encoding ( encoding -- * ) : bad-encoding ( encoding -- * )
\ bad-encoding xml-error-at \ bad-encoding xml-error-at
swap >>encoding swap >>encoding
throw ; throw ;
M: bad-encoding summary
call-next-method
"\nEncoding in XML document does not exist" append ;
UNION: xml-error UNION: xml-error
multitags notags pre/post-content xml-error-at ; multitags notags pre/post-content xml-error-at ;
{ "xml.errors" "debugger" } "xml.errors.debugger" require-when

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2009 Daniel Ehrenberg ! Copyright (C) 2005, 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel namespaces sequences words io assocs USING: accessors kernel namespaces sequences words io assocs
quotations strings parser lexer arrays xml.data xml.writer debugger quotations strings parser lexer arrays xml.data xml.writer
splitting vectors sequences.deep combinators fry memoize ; splitting vectors sequences.deep combinators fry memoize ;
IN: xml.traversal IN: xml.traversal

View File

@ -444,7 +444,7 @@ HELP: boa
{ $values { "slots..." "slot values" } { "class" tuple-class } { "tuple" tuple } } { $values { "slots..." "slot values" } { "class" tuple-class } { "tuple" tuple } }
{ $description "Creates a new instance of " { $snippet "class" } " and fill in the slots from the stack, with the top-most stack element being stored in the right-most slot." } { $description "Creates a new instance of " { $snippet "class" } " and fill in the slots from the stack, with the top-most stack element being stored in the right-most slot." }
{ $notes "The name " { $snippet "boa" } " is shorthand for “by order of arguments”, and “BOA constructor” is a pun on “boa constrictor”." } { $notes "The name " { $snippet "boa" } " is shorthand for “by order of arguments”, and “BOA constructor” is a pun on “boa constrictor”." }
{ $errors "Throws an error if the slot values do not match class declarations on slots (see" { $link "tuple-declarations" } ")." } ; { $errors "Throws an error if the slot values do not match class declarations on slots (see " { $link "tuple-declarations" } ")." } ;
HELP: bad-superclass HELP: bad-superclass
{ $error-description "Thrown if an attempt is made to subclass a class that is not a tuple class, or a tuple class declared " { $link POSTPONE: final } "." } ; { $error-description "Thrown if an attempt is made to subclass a class that is not a tuple class, or a tuple class declared " { $link POSTPONE: final } "." } ;

View File

@ -143,4 +143,4 @@ HELP: effect>string
HELP: stack-effect HELP: stack-effect
{ $values { "word" word } { "effect/f" { $maybe effect } } } { $values { "word" word } { "effect/f" { $maybe effect } } }
{ $description "Outputs the stack effect of a word; either a stack effect declared with " { $link POSTPONE: ( } ", or an inferred stack effect (see " { $link "inference" } "." } ; { $description "Outputs the stack effect of a word; either a stack effect declared with " { $link POSTPONE: ( } ", or an inferred stack effect (see " { $link "inference" } ")." } ;

View File

@ -83,10 +83,12 @@ HELP: empty?
HELP: if-empty HELP: if-empty
{ $values { "seq" sequence } { "quot1" quotation } { "quot2" quotation } } { $values { "seq" sequence } { "quot1" quotation } { "quot2" quotation } }
{ $description "Makes an implicit check if the sequence is empty. An empty sequence is dropped and " { $snippet "quot1" } " is called. Otherwise, if the sequence has any elements, " { $snippet "quot2" } " is called on it." } { $description "Makes an implicit check if the sequence is empty. An empty sequence is dropped and " { $snippet "quot1" } " is called. Otherwise, if the sequence has any elements, " { $snippet "quot2" } " is called on it." }
{ $example { $examples
"USING: kernel prettyprint sequences ;" { $example
"{ 1 2 3 } [ \"empty sequence\" ] [ sum ] if-empty ." "USING: kernel prettyprint sequences ;"
"6" "{ 1 2 3 } [ \"empty sequence\" ] [ sum ] if-empty ."
"6"
}
} ; } ;
HELP: when-empty HELP: when-empty

View File

@ -255,6 +255,8 @@ unit-test
[ { "a" "b" "c" "d" } ] [ { 0 1 2 3 } { "a" "b" "c" "d" } nths ] unit-test [ { "a" "b" "c" "d" } ] [ { 0 1 2 3 } { "a" "b" "c" "d" } nths ] unit-test
[ { "d" "c" "b" "a" } ] [ { 3 2 1 0 } { "a" "b" "c" "d" } nths ] unit-test [ { "d" "c" "b" "a" } ] [ { 3 2 1 0 } { "a" "b" "c" "d" } nths ] unit-test
[ { "d" "a" "b" "c" } ] [ { 3 0 1 2 } { "a" "b" "c" "d" } nths ] unit-test [ { "d" "a" "b" "c" } ] [ { 3 0 1 2 } { "a" "b" "c" "d" } nths ] unit-test
[ "dac" ] [ { 3 0 2 } "abcd" nths ] unit-test
TUPLE: bogus-hashcode ; TUPLE: bogus-hashcode ;

View File

@ -1,4 +1,4 @@
! Copyright (C) 2005, 2010 Slava Pestov, Daniel Ehrenberg. ! Copyright (C) 2005, 2011 Slava Pestov, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel kernel.private slots.private math USING: accessors kernel kernel.private slots.private math
math.private math.order ; math.private math.order ;
@ -559,7 +559,7 @@ PRIVATE>
[ [ (indices) ] 2curry each-index ] keep ; [ [ (indices) ] 2curry each-index ] keep ;
: nths ( indices seq -- seq' ) : nths ( indices seq -- seq' )
[ nth ] curry map ; [ [ nth ] curry ] keep map-as ;
: any? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? ) : any? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )
find drop >boolean ; inline find drop >boolean ; inline

View File

@ -190,3 +190,7 @@ HELP: null?
HELP: cardinality HELP: cardinality
{ $values { "set" set } { "n" "a non-negative integer" } } { $values { "set" set } { "n" "a non-negative integer" } }
{ $description "Returns the number of elements in the set. All sets support this operation." } ; { $description "Returns the number of elements in the set. All sets support this operation." } ;
HELP: combine
{ $values { "sets" "a sequence of sets" } { "set" set } }
{ $description "Outputs the union of a sequence of sets, or " { $link f } " if the sequence is empty." } ;

View File

@ -109,7 +109,7 @@ M: sequence null?
M: sequence cardinality M: sequence cardinality
length ; length ;
: combine ( sets -- set/f ) : combine ( sets -- set )
[ f ] [ f ]
[ [ [ members ] map concat ] [ first ] bi set-like ] [ [ [ members ] map concat ] [ first ] bi set-like ]
if-empty ; if-empty ;