factor/basis/xml/errors/errors.factor

343 lines
8.9 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2005, 2006 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: xml.data xml.writer kernel generic io prettyprint math
2009-01-21 00:54:33 -05:00
debugger sequences xml.state accessors summary
2009-01-22 18:19:02 -05:00
namespaces io.streams.string ;
2007-09-20 18:09:08 -04:00
IN: xml.errors
2009-01-26 17:11:30 -05:00
TUPLE: xml-error-at line column ;
2009-01-21 00:54:33 -05:00
2009-01-26 17:11:30 -05:00
: xml-error-at ( class -- obj )
2009-01-21 00:54:33 -05:00
new
get-line >>line
get-column >>column ;
2009-01-26 17:11:30 -05:00
M: xml-error-at summary ( obj -- str )
2009-01-21 00:54:33 -05:00
[
2009-01-26 17:11:30 -05:00
"XML parsing error" print
2009-01-21 00:54:33 -05:00
"Line: " write dup line>> .
"Column: " write column>> .
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: expected < xml-error-at should-be was ;
2009-01-21 00:54:33 -05:00
: expected ( should-be was -- * )
2009-01-26 17:11:30 -05:00
\ expected xml-error-at
2009-01-21 00:54:33 -05:00
swap >>was
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 ;
2009-01-26 17:11:30 -05:00
TUPLE: unexpected-end < xml-error-at ;
: unexpected-end ( -- * ) \ unexpected-end xml-error-at throw ;
2009-01-21 00:54:33 -05:00
M: unexpected-end summary ( obj -- str )
[
call-next-method write
"File unexpectedly ended." print
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: missing-close < xml-error-at ;
: missing-close ( -- * ) \ missing-close xml-error-at throw ;
2009-01-21 00:54:33 -05:00
M: missing-close summary ( obj -- str )
[
call-next-method write
"Missing closing token." print
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: disallowed-char < xml-error-at char ;
2009-01-21 00:54:33 -05:00
: disallowed-char ( char -- * )
2009-01-26 17:11:30 -05:00
\ disallowed-char xml-error-at swap >>char throw ;
2009-01-21 00:54:33 -05:00
M: disallowed-char summary
[ call-next-method ]
[ char>> "Disallowed character in XML document: " swap suffix ] bi
append ;
ERROR: multitags ;
2008-05-02 18:12:09 -04:00
M: multitags summary ( obj -- str )
drop "XML document contains multiple main tags" ;
2007-09-20 18:09:08 -04:00
ERROR: pre/post-content string pre? ;
2008-05-02 18:12:09 -04:00
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 ;
2009-01-26 17:11:30 -05:00
TUPLE: no-entity < xml-error-at thing ;
: no-entity ( string -- * )
2009-01-26 17:11:30 -05:00
\ no-entity xml-error-at swap >>thing throw ;
2008-05-02 18:12:09 -04:00
M: no-entity summary ( obj -- str )
[
dup call-next-method write
"Entity does not exist: &" write thing>> write ";" print
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: mismatched < xml-error-at open close ;
: mismatched ( open close -- * )
2009-01-26 17:11:30 -05:00
\ mismatched xml-error-at swap >>close swap >>open throw ;
2008-05-02 18:12:09 -04:00
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 ;
2009-01-26 17:11:30 -05:00
TUPLE: unclosed < xml-error-at tags ;
: unclosed ( -- * )
2009-01-26 17:11:30 -05:00
\ unclosed xml-error-at
xml-stack get rest-slice [ first name>> ] map >>tags
throw ;
2008-05-02 18:12:09 -04:00
M: unclosed summary ( obj -- str )
[
dup call-next-method write
"Unclosed tags" print
"Tags: " print
tags>> [ " <" write print-name ">" print ] each
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: bad-uri < xml-error-at string ;
: bad-uri ( string -- * )
2009-01-26 17:11:30 -05:00
\ bad-uri xml-error-at swap >>string throw ;
2008-05-02 18:12:09 -04:00
M: bad-uri summary ( obj -- str )
[
dup call-next-method write
"Bad URI:" print string>> .
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: nonexist-ns < xml-error-at name ;
: nonexist-ns ( name-string -- * )
2009-01-26 17:11:30 -05:00
\ nonexist-ns xml-error-at swap >>name throw ;
2008-05-02 18:12:09 -04:00
M: nonexist-ns summary ( obj -- str )
[
dup call-next-method write
"Namespace " write name>> write " has not been declared" print
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: unopened < xml-error-at ; ! this should give which tag was unopened
: unopened ( -- * )
2009-01-26 17:11:30 -05:00
\ unopened xml-error-at throw ;
2008-05-02 18:12:09 -04:00
M: unopened summary ( obj -- str )
[
call-next-method write
"Closed an unopened tag" print
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: not-yes/no < xml-error-at text ;
: not-yes/no ( text -- * )
2009-01-26 17:11:30 -05:00
\ not-yes/no xml-error-at swap >>text throw ;
2008-05-02 18:12:09 -04:00
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
2009-01-26 17:11:30 -05:00
TUPLE: extra-attrs < xml-error-at attrs ;
: extra-attrs ( attrs -- * )
2009-01-26 17:11:30 -05:00
\ extra-attrs xml-error-at swap >>attrs throw ;
2008-05-02 18:12:09 -04:00
M: extra-attrs summary ( obj -- str )
[
dup call-next-method write
"Extra attributes included in xml version declaration:" print
attrs>> .
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: bad-version < xml-error-at num ;
: bad-version ( num -- * )
2009-01-26 17:11:30 -05:00
\ bad-version xml-error-at swap >>num throw ;
2008-05-02 18:12:09 -04:00
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 ;
2008-05-02 18:12:09 -04:00
M: notags summary ( obj -- str )
drop "XML document lacks a main tag" ;
2009-01-26 17:11:30 -05:00
TUPLE: bad-prolog < xml-error-at prolog ;
: bad-prolog ( prolog -- * )
2009-01-26 17:11:30 -05:00
\ bad-prolog xml-error-at swap >>prolog throw ;
2008-05-02 18:12:09 -04:00
M: bad-prolog summary ( obj -- str )
[
dup call-next-method write
"Misplaced XML prolog" print
2009-01-29 14:33:04 -05:00
prolog>> write-xml nl
2008-05-02 18:12:09 -04:00
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: capitalized-prolog < xml-error-at name ;
: capitalized-prolog ( name -- capitalized-prolog )
2009-01-26 17:11:30 -05:00
\ capitalized-prolog xml-error-at swap >>name throw ;
2008-05-02 18:12:09 -04:00
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 ;
2009-01-26 17:11:30 -05:00
TUPLE: versionless-prolog < xml-error-at ;
: versionless-prolog ( -- * )
2009-01-26 17:11:30 -05:00
\ versionless-prolog xml-error-at throw ;
2008-05-02 18:12:09 -04:00
M: versionless-prolog summary ( obj -- str )
[
call-next-method write
"XML prolog lacks a version declaration" print
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: bad-directive < xml-error-at dir ;
: bad-directive ( directive -- * )
2009-01-26 17:11:30 -05:00
\ bad-directive xml-error-at swap >>dir throw ;
2008-05-02 18:12:09 -04:00
M: bad-directive summary ( obj -- str )
[
dup call-next-method write
"Unknown directive:" print
dir>> write
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: bad-decl < xml-error-at ;
2009-01-19 23:25:15 -05:00
: bad-decl ( -- * )
2009-01-26 17:11:30 -05:00
\ bad-decl xml-error-at throw ;
2009-01-19 23:25:15 -05:00
M: bad-decl summary ( obj -- str )
call-next-method "\nExtra content in directive" append ;
2009-01-26 17:11:30 -05:00
TUPLE: bad-external-id < xml-error-at ;
: bad-external-id ( -- * )
2009-01-26 17:11:30 -05:00
\ bad-external-id xml-error-at throw ;
M: bad-external-id summary ( obj -- str )
call-next-method "\nBad external ID" append ;
2009-01-26 17:11:30 -05:00
TUPLE: misplaced-directive < xml-error-at dir ;
: misplaced-directive ( directive -- * )
2009-01-26 17:11:30 -05:00
\ misplaced-directive xml-error-at swap >>dir throw ;
M: misplaced-directive summary ( obj -- str )
2008-05-02 18:12:09 -04:00
[
dup call-next-method write
"Misplaced directive:" print
2009-01-29 14:33:04 -05:00
dir>> write-xml nl
2008-05-02 18:12:09 -04:00
] with-string-writer ;
2007-09-20 18:09:08 -04:00
2009-01-26 17:11:30 -05:00
TUPLE: bad-name < xml-error-at name ;
2009-01-15 17:35:55 -05:00
: bad-name ( name -- * )
2009-01-26 17:11:30 -05:00
\ bad-name xml-error-at swap >>name throw ;
2009-01-15 17:35:55 -05:00
M: bad-name summary ( obj -- str )
[ call-next-method ]
[ "Invalid name: " swap name>> "\n" 3append ]
bi append ;
2009-01-26 17:11:30 -05:00
TUPLE: unclosed-quote < xml-error-at ;
2009-01-15 17:35:55 -05:00
: unclosed-quote ( -- * )
2009-01-26 17:11:30 -05:00
\ unclosed-quote xml-error-at throw ;
2009-01-15 17:35:55 -05:00
M: unclosed-quote summary
call-next-method
"XML document ends with quote still open\n" append ;
2009-01-26 17:11:30 -05:00
TUPLE: quoteless-attr < xml-error-at ;
2009-01-15 17:35:55 -05:00
: quoteless-attr ( -- * )
2009-01-26 17:11:30 -05:00
\ quoteless-attr xml-error-at throw ;
2009-01-15 17:35:55 -05:00
M: quoteless-attr summary
call-next-method "Attribute lacks quotes around value\n" append ;
2009-01-26 17:11:30 -05:00
TUPLE: attr-w/< < xml-error-at ;
2009-01-19 23:25:15 -05:00
: attr-w/< ( -- * )
2009-01-26 17:11:30 -05:00
\ attr-w/< xml-error-at throw ;
2009-01-19 23:25:15 -05:00
M: attr-w/< summary
call-next-method
"Attribute value contains literal <" append ;
2009-01-26 17:11:30 -05:00
TUPLE: text-w/]]> < xml-error-at ;
2009-01-19 23:25:15 -05:00
: text-w/]]> ( -- * )
2009-01-26 17:11:30 -05:00
\ text-w/]]> xml-error-at throw ;
2009-01-19 23:25:15 -05:00
M: text-w/]]> summary
call-next-method
"Text node contains ']]>'" append ;
2009-01-26 17:11:30 -05:00
TUPLE: duplicate-attr < xml-error-at key values ;
2009-01-19 23:25:15 -05:00
: duplicate-attr ( key values -- * )
2009-01-26 17:11:30 -05:00
\ duplicate-attr xml-error-at
2009-01-19 23:25:15 -05:00
swap >>values swap >>key throw ;
M: duplicate-attr summary
call-next-method "\nDuplicate attribute" append ;
2009-01-26 17:11:30 -05:00
TUPLE: bad-cdata < xml-error-at ;
2009-01-20 16:37:21 -05:00
: bad-cdata ( -- * )
2009-01-26 17:11:30 -05:00
\ bad-cdata xml-error-at throw ;
2009-01-20 16:37:21 -05:00
M: bad-cdata summary
call-next-method "\nCDATA occurs before or after main tag" append ;
2009-01-26 17:11:30 -05:00
TUPLE: not-enough-characters < xml-error-at ;
2009-01-21 00:54:33 -05:00
: not-enough-characters ( -- * )
2009-01-26 17:11:30 -05:00
\ not-enough-characters xml-error-at throw ;
2009-01-21 00:54:33 -05:00
M: not-enough-characters summary ( obj -- str )
[
call-next-method write
"Not enough characters" print
] with-string-writer ;
2009-01-26 17:11:30 -05:00
TUPLE: bad-doctype < xml-error-at contents ;
2009-01-21 19:16:51 -05:00
: bad-doctype ( contents -- * )
2009-01-26 17:11:30 -05:00
\ bad-doctype xml-error-at swap >>contents throw ;
2009-01-21 19:16:51 -05:00
M: bad-doctype summary
call-next-method "\nDTD contains invalid object" append ;
2009-01-26 17:11:30 -05:00
UNION: xml-error
multitags notags pre/post-content xml-error-at ;