Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 05, 2012
@Whiteknight [Xml] Break parsing out into a new file. Fix a bug where not having w…
…hitespace at the end was causing errors
f68937d
@Whiteknight [Xml] Add in a rudimentary test file to prove that we can parse certa…
…in strings without parse errors. Doesn't test content, only shows that we don't error out
1092e15
@Whiteknight [Xml] use separate EndTag objects to mark the end of a tag. Use Docum…
…entRoot to keep track of document elements and simplify searching for the root tag. More error detection and tests
d6c1342
View
1  setup.winxed
@@ -403,6 +403,7 @@ function setup_experimental_libraries(var rosella)
"xml/Includes",
"xml/Xml",
"xml/Document",
+ "xml/Parser",
"xml/Tag",
"xml/Text"
);
View
2  src/include/Parsing.winxed
@@ -29,7 +29,7 @@ inline eat_whitespace(var s, var b)
int c = ASCII_SPACE;
while(have_more_chars(s, b) && codepoint_is_whitespace(c))
c = get_next(s, b);
- if (have_more_chars(s, b))
+ if (c != ASCII_NULL && !codepoint_is_whitespace(c))
unshift_int(s, c);
}
View
1  src/unstable/xml/Document.winxed
@@ -21,6 +21,7 @@ class Rosella.Xml.Document
function set_documentroot(var root)
{
+ // TODO: What do we do with the other children?
for (var child in root.children)
{
if (child instanceof Rosella.Xml.Tag) {
View
303 src/unstable/xml/Parser.winxed
@@ -0,0 +1,303 @@
+namespace Rosella.Xml.Parser
+{
+ function __parse_xml(string xml, var s, var b, int len, var document)
+ {
+ var tag_stack = [];
+ var current_tag = new Rosella.Xml.Tag.DocumentRoot();
+ var root = current_tag;
+
+ eat_whitespace(s, b);
+
+ Rosella.Xml.Parser.__parse_frontmatter(xml, s, b, len, document);
+
+ int c;
+ while(have_more_chars(s, b)) {
+ eat_whitespace(s, b);
+ if (!have_more_chars(s, b))
+ break;
+ c = get_next(s, b);
+ if (c == ASCII_LESS_THAN) {
+ :(var tag, int is_close, int contained, int is_comment) = Rosella.Xml.Parser.__parse_tag(xml, s, b, len);
+
+ if (is_comment) {
+ current_tag.add_child(tag);
+ continue;
+ }
+
+ // A self-contained tag: <foo />
+ if (contained) {
+ current_tag.add_child(tag);
+ continue;
+ }
+
+ // A closing tag: </foo>
+ if (is_close) {
+ if (tag.xmlns != current_tag.xmlns)
+ Rosella.Error.error("Syntax error, mismatched tags. Tag namespaces and/or names do not match");
+ if (tag.name != current_tag.name)
+ Rosella.Error.error("Syntax error, mismatched tags. Found closing tag '%s' but current tag is '%s'", tag.name, current_tag.name);
+ current_tag.set_end(tag);
+ current_tag = tag_stack.pop();
+ continue;
+ }
+
+ // An opening tag: <foo ...>
+ current_tag.add_child(tag);
+ push(tag_stack, current_tag);
+ current_tag = tag;
+ continue;
+ }
+ var sb = new 'StringBuilder';
+ while(have_more_chars(s, b) && c != ASCII_LESS_THAN) {
+ push(sb, chr(c));
+ c = get_next(s, b);
+ }
+
+ if (!have_more_chars(s, b))
+ break;
+
+ unshift_int(s, c);
+ string str = string(sb);
+ if (current_tag != null)
+ current_tag.add_child_text(str);
+ Rosella.IO.sayf("Done reading text after tag");
+ }
+ if (elements(tag_stack) > 0)
+ Rosella.Error.error("Syntax error, mismatched tags. There are %d unclosed tags", elements(tag_stack));
+ document.set_documentroot(root);
+ return document;
+ }
+
+ function __parse_frontmatter(string xml, var s, var b, int len, var document)
+ {
+ while(have_more_chars(s, b)) {
+ eat_whitespace(s, b);
+ int c = get_next(s, b);
+ if (c != ASCII_LESS_THAN)
+ Rosella.Xml.Parser.__error_unknown_char(c, "XML frontmatter");
+ c = get_next(s, b);
+ if (c == ASCII_QUESTION_MARK) {
+ Rosella.Xml.Parser.__parse_xml_header(xml, s, b, len, document);
+ continue;
+ }
+ if (c == ASCII_EXCLAMATION_POINT) {
+ c = peek_next(s, b);
+ if (c == ASCII_DASH) {
+ // TODO: We shouldn't just discard this
+ Rosella.Xml.Parser.__parse_comment(xml, s, b, len);
+ continue;
+ }
+ if (c == ASCII_D) {
+ Rosella.Xml.Parser.__parse_dtd_header(xml, s, b, len, document);
+ continue;
+ }
+ }
+
+ // If we don't have a <!-- comment, <?xml header or <!DOCTYPE, return and
+ // let the main loop parse it.
+ unshift_int(s, c);
+ unshift_int(s, ASCII_LESS_THAN);
+ return;
+ }
+ }
+
+ // TODO: If available, read the encoding attribute and compare to the
+ // encoding that the string is being read as.
+ function __parse_xml_header(string xml, var s, var b, int len, var document)
+ {
+ eat_whitespace(s, b);
+ string tag_name = Rosella.Xml.Parser.__parse_alphanumeric(xml, s, b, len);
+ if (tag_name != "xml")
+ Rosella.Error.error("Malformed XML header. Should start with '<?xml ... ?>'");
+
+ var header_tag = new Rosella.Xml.Tag.XmlHeader();
+ eat_whitespace(s, b);
+ Rosella.Xml.Parser.__parse_attributes(xml, s, b, len, header_tag);
+ eat_whitespace(s, b);
+ int c = get_next(s, b);
+ if (c == ASCII_QUESTION_MARK) {
+ c = get_next(s, b);
+ if (c == ASCII_GREATER_THAN) {
+ document.add_header(header_tag);
+ return;
+ }
+ unshift_int(s, c);
+ }
+ Rosella.Xml.Parser.__error_unknown_char(c, "XML Header");
+ }
+
+ function __parse_dtd_header(string xml, var s, var b, int len, var document)
+ {
+ string tagname = Rosella.Xml.Parser.__parse_alphanumeric(xml, s, b, len);
+ if (tagname != "DOCTYPE")
+ Rosella.Error.error("Invalid DOCTYPE tag");
+ eat_whitespace(s, b);
+
+ string doctype = Rosella.Xml.Parser.__parse_alphanumeric(xml, s, b, len);
+ eat_whitespace(s, b);
+
+ // Should be one of SYSTEM, PUBLIC, etc
+ string dtd_scope = Rosella.Xml.Parser.__parse_alphanumeric(xml, s, b, len);
+
+ var dtd_header = new Rosella.Xml.Tag.DtdHeader(doctype, dtd_scope);
+
+ eat_whitespace(s, b);
+ int c = get_next(s, b);
+ if (c == ASCII_SINGLE_QUOTE || c == ASCII_DOUBLE_QUOTE) {
+ string filename = Rosella.Xml.Parser.__parse_quoted(c, xml, s, b, len);
+ dtd_header.set_filename(filename);
+ } else if (c == ASCII_OPEN_BRACKET) {
+ // TODO: Parse the inline DTD definitions. Add each as a child to
+ // the dtd_header
+ Rosella.Error.not_implemented("Cannot parse inline DOCTYPE yet!");
+ }
+ eat_whitespace(s, b);
+ c = get_next(s, b);
+ if (c != ASCII_GREATER_THAN)
+ Rosella.Xml.Parser.__error_unknown_char(c, "DOCTYPE header");
+ document.add_header(dtd_header);
+ }
+
+ function __parse_tag(string xml, var s, var b, int len)
+ {
+ // TODO: Namespaces (<foo:bar ...> </foo:bar>)
+ eat_whitespace(s, b);
+ int c = get_next(s, b);
+ if (c == ASCII_EXCLAMATION_POINT)
+ return Rosella.Xml.Parser.__parse_comment(xml, s, b, len);
+ int is_close_tag = false;
+
+ if (c == ASCII_SLASH) {
+ c = get_next(s, b);
+ is_close_tag = true;
+ }
+ unshift_int(s, c);
+ string ns = "";
+ string tag_name = Rosella.Xml.Parser.__parse_alphanumeric(xml, s, b, len);
+
+ eat_whitespace(s, b);
+ if (peek_next(s, b) == ASCII_COLON) {
+ get_next(s, b);
+ eat_whitespace(s, b);
+ ns = tag_name;
+ tag_name = Rosella.Xml.Parser.__parse_alphanumeric(xml, s, b, len);
+ }
+
+ var xtag;
+ if (is_close_tag)
+ xtag = new Rosella.Xml.Tag.EndTag(ns, tag_name);
+ else
+ xtag = new Rosella.Xml.Tag(ns, tag_name);
+
+ eat_whitespace(s, b);
+ if (!is_close_tag)
+ Rosella.Xml.Parser.__parse_attributes(xml, s, b, len, xtag);
+
+ c = get_next(s, b);
+ if (c == ASCII_GREATER_THAN)
+ return xtag, is_close_tag, false, false;
+
+ if (c == ASCII_SLASH) {
+ int next = get_next(s, b);
+ if (next == ASCII_GREATER_THAN)
+ return xtag, false, true, false;
+ else
+ Rosella.Error.error("Syntax error in tag %s", tag_name);
+ }
+
+ Rosella.Xml.Parser.__error_unknown_char(c, "tag " + tag_name);
+ }
+
+ function __error_unknown_char(int c, string context)
+ {
+ if (c == ASCII_NULL)
+ Rosella.Error.error("Unexpected end of input while parsing %s", context);
+ Rosella.Error.error("Unexpected token '%s' in %s", chr(c), context);
+ }
+
+ function __parse_comment(string xml, var s, var b, int len)
+ {
+ if (get_next(s, b) != ASCII_DASH || get_next(s, b) != ASCII_DASH)
+ Rosella.Error.error("Malformed comment");
+
+ var sb = new 'StringBuilder';
+ while (have_more_chars(s, b)) {
+ int c = get_next(s, b);
+
+ if (c == ASCII_DASH) {
+ int d = get_next(s, b);
+ if (d == ASCII_DASH) {
+ int e = get_next(s, b);
+ if (e == ASCII_GREATER_THAN) {
+ string text = string(sb);
+ var comment = new Rosella.Xml.Tag.Comment(text);
+ return comment, true, true, true;
+ }
+ unshift_int(s, e);
+ }
+ unshift_int(s, d);
+ }
+ push(sb, chr(c));
+ }
+ Rosella.Error.error("Unterminated comment at end of document");
+ }
+
+ function __parse_attributes(string xml, var s, var b, int len, var xtag)
+ {
+ while (have_more_chars(s, b)) {
+ eat_whitespace(s, b);
+ int c = peek_next(s, b);
+ if (!is_name_char(c))
+ break;
+
+ string attr_name = Rosella.Xml.Parser.__parse_alphanumeric(xml, s, b, len);
+ eat_whitespace(s, b);
+
+ c = get_next(s, b);
+ if (c != ASCII_EQUALS) {
+ unshift_int(s, c);
+ xtag.add_attribute(attr_name, "true");
+ eat_whitespace(s, b);
+ continue;
+ }
+
+ c = get_next(s, b);
+ if (c == ASCII_SINGLE_QUOTE || c == ASCII_DOUBLE_QUOTE) {
+ string attr_value = Rosella.Xml.Parser.__parse_quoted(c, xml, s, b, len);
+ xtag.add_attribute(attr_name, attr_value);
+ } else {
+ unshift_int(s, c);
+ string attr_value = Rosella.Xml.Parser.__parse_alphanumeric(xml, s, b, len);
+ xtag.add_attribute(attr_name, attr_value);
+ }
+ }
+ }
+
+ function __parse_alphanumeric(string xml, var s, var b, int len)
+ {
+ var sb = new 'StringBuilder';
+ int c = get_next(s, b);
+ while(have_more_chars(s, b) && is_name_char(c)) {
+ push(sb, chr(c));
+ c = get_next(s, b);
+ }
+ unshift_int(s, c);
+ string result = string(sb);
+ return result;
+ }
+
+ function __parse_quoted(int q, string xml, var s, var b, int len)
+ {
+ var sb = new 'StringBuilder';
+ int c = get_next(s, b);
+ while (c != q) {
+ push(sb, chr(c));
+ if (c == ASCII_SLASH) {
+ c = get_next(s, b);
+ push(sb, chr(c));
+ }
+ c = get_next(s, b);
+ }
+ return sb;
+ }
+}
View
46 src/unstable/xml/Tag.winxed
@@ -8,8 +8,7 @@ class Rosella.Xml.Tag
function Tag(string xmlns, string name)
{
- if (xmlns != "")
- self.xmlns = xmlns;
+ self.xmlns = xmlns;
self.name = name;
self.attributes = {};
self.children = [];
@@ -58,8 +57,14 @@ class Rosella.Xml.Tag
self.__to_xml_sb_attrs(sb, indent);
push(sb, ">");
self.__to_xml_sb_children(sb, indent + 1);
+
push(sb, indent_str);
push(sb, "</");
+ if (self.xmlns != null) {
+ string xmlns = self.xmlns;
+ push(sb, xmlns);
+ push(sb, ":");
+ }
push(sb, self.name);
push(sb, ">");
}
@@ -83,6 +88,40 @@ class Rosella.Xml.Tag
}
}
+class Rosella.Xml.Tag.EndTag : Rosella.Xml.Tag
+{
+ var xmlns;
+ var name;
+
+ function EndTag(string xmlns, string name)
+ {
+ self.xmlns = xmlns;
+ self.name = name;
+ }
+
+ function add_attribute(string name, string value) { Rosella.Error.error("End tags do not have attributes"); }
+
+ function add_child(var child) { Rosella.Error.error("End tags do not have children"); }
+
+ function add_child_text(string text) { Rosella.Error.error("End tags do not contain text"); }
+
+ function set_end(var end_tag) { Rosella.Error.error("End tags do not have end tags"); }
+
+ function to_xml_sb(var sb, int indent)
+ {
+ string indent_str = indent_level(indent);
+ push(sb, indent_str);
+ push(sb, "</");
+ if (self.xmlns != null) {
+ string xmlns = self.xmlns;
+ push(sb, xmlns);
+ push(sb, ":");
+ }
+ push(sb, self.name);
+ push(sb, ">");
+ }
+}
+
class Rosella.Xml.Tag.XmlHeader : Rosella.Xml.Tag
{
function XmlHeader() { self.Tag("", "?xml"); }
@@ -179,5 +218,6 @@ class Rosella.Xml.Tag.Comment
class Rosella.Xml.Tag.DocumentRoot : Rosella.Xml.Tag
{
- function DocumentRoot() {}
+ function DocumentRoot() { self.children = []; }
+
}
View
306 src/unstable/xml/Xml.winxed
@@ -19,310 +19,6 @@ namespace Rosella.Xml
int len = length(xml);
var b = get_iterator(var(xml));
int s[] = [];
- return __parse_xml(xml, s, b, len, document);
- }
-
- function __parse_frontmatter(string xml, var s, var b, int len, var document)
- {
- while(have_more_chars(s, b)) {
- eat_whitespace(s, b);
- int c = get_next(s, b);
- if (c != ASCII_LESS_THAN)
- Rosella.Xml.__error_unknown_char(c, "XML frontmatter");
- c = get_next(s, b);
- if (c == ASCII_QUESTION_MARK) {
- Rosella.Xml.__parse_xml_header(xml, s, b, len, document);
- continue;
- }
- if (c == ASCII_EXCLAMATION_POINT) {
- c = peek_next(s, b);
- if (c == ASCII_DASH) {
- // TODO: We shouldn't just discard this
- Rosella.Xml.__parse_comment(xml, s, b, len);
- continue;
- }
- if (c == ASCII_D) {
- Rosella.Xml.__parse_dtd_header(xml, s, b, len, document);
- continue;
- }
- }
-
- // If we don't have a <!-- comment, <?xml header or <!DOCTYPE, return and
- // let the main loop parse it.
- unshift_int(s, c);
- unshift_int(s, ASCII_LESS_THAN);
- return;
- }
- }
-
- function __parse_xml(string xml, var s, var b, int len, var document)
- {
- var tag_stack = [];
- var current_tag = null;
-
- eat_whitespace(s, b);
-
- Rosella.Xml.__parse_frontmatter(xml, s, b, len, document);
-
- int c;
- while(have_more_chars(s, b)) {
- eat_whitespace(s, b);
- if (!have_more_chars(s, b))
- break;
- c = get_next(s, b);
- if (c == ASCII_LESS_THAN) {
- :(var tag, int is_close, int contained, int is_comment) = Rosella.Xml.__parse_tag(xml, s, b, len);
-
- if (is_comment) {
- // TODO: What do we do about comments appearing before and
- // after the root node?
- if (current_tag != null)
- current_tag.add_child(tag);
- continue;
- }
-
- // A self-contained tag: <foo />
- if (contained) {
- if (current_tag != null)
- current_tag.add_child(tag);
- else {
- current_tag = tag;
- document.set_root(tag);
- }
- continue;
- }
-
- // A closing tag: </foo>
- if (is_close) {
- if (current_tag == null)
- Rosella.Error.error("Syntax error. Found closing tag '%s' without corresponding open tag", tag.name);
- current_tag.set_end(tag);
- current_tag = tag_stack.pop();
- continue;
- }
-
- // An opening tag: <foo ...>
- if (current_tag != null)
- current_tag.add_child(tag);
- else
- document.set_root(tag);
- push(tag_stack, current_tag);
- current_tag = tag;
- continue;
- }
- var sb = new 'StringBuilder';
- while(have_more_chars(s, b) && c != ASCII_LESS_THAN) {
- push(sb, chr(c));
- c = get_next(s, b);
- }
-
- if (!have_more_chars(s, b))
- break;
-
- unshift_int(s, c);
- string str = string(sb);
- if (current_tag != null)
- current_tag.add_child_text(str);
- Rosella.IO.sayf("Done reading text after tag");
- }
- return document;
- }
-
- // TODO: If available, read the encoding attribute and compare to the
- // encoding that the string is being read as.
- function __parse_xml_header(string xml, var s, var b, int len, var document)
- {
- eat_whitespace(s, b);
- string tag_name = Rosella.Xml.__parse_alphanumeric(xml, s, b, len);
- if (tag_name != "xml")
- Rosella.Error.error("Malformed XML header. Should start with '<?xml ... ?>'");
-
- var header_tag = new Rosella.Xml.Tag.XmlHeader();
- eat_whitespace(s, b);
- Rosella.Xml.__parse_attributes(xml, s, b, len, header_tag);
- eat_whitespace(s, b);
- int c = get_next(s, b);
- if (c == ASCII_QUESTION_MARK) {
- c = get_next(s, b);
- if (c == ASCII_GREATER_THAN) {
- document.add_header(header_tag);
- return;
- }
- unshift_int(s, c);
- }
- Rosella.Xml.__error_unknown_char(c, "XML Header");
- }
-
- function __parse_dtd_header(string xml, var s, var b, int len, var document)
- {
- string tagname = Rosella.Xml.__parse_alphanumeric(xml, s, b, len);
- if (tagname != "DOCTYPE")
- Rosella.Error.error("Invalid DOCTYPE tag");
- eat_whitespace(s, b);
-
- string doctype = Rosella.Xml.__parse_alphanumeric(xml, s, b, len);
- eat_whitespace(s, b);
-
- // Should be one of SYSTEM, PUBLIC, etc
- string dtd_scope = Rosella.Xml.__parse_alphanumeric(xml, s, b, len);
-
- var dtd_header = new Rosella.Xml.Tag.DtdHeader(doctype, dtd_scope);
-
- eat_whitespace(s, b);
- int c = get_next(s, b);
- if (c == ASCII_SINGLE_QUOTE || c == ASCII_DOUBLE_QUOTE) {
- string filename = Rosella.Xml.__parse_quoted(c, xml, s, b, len);
- dtd_header.set_filename(filename);
- } else if (c == ASCII_OPEN_BRACKET) {
- // TODO: Parse the inline DTD definitions. Add each as a child to
- // the dtd_header
- Rosella.Error.not_implemented("Cannot parse inline DOCTYPE yet!");
- }
- eat_whitespace(s, b);
- c = get_next(s, b);
- if (c != ASCII_GREATER_THAN)
- Rosella.Xml.__error_unknown_char(c, "DOCTYPE header");
- document.add_header(dtd_header);
- }
-
- function __parse_tag(string xml, var s, var b, int len)
- {
- // TODO: Namespaces (<foo:bar ...> </foo:bar>)
- eat_whitespace(s, b);
- int c = get_next(s, b);
- if (c == ASCII_EXCLAMATION_POINT)
- return Rosella.Xml.__parse_comment(xml, s, b, len);
- int is_close_tag = false;
-
- if (c == ASCII_SLASH) {
- c = get_next(s, b);
- is_close_tag = true;
- }
- unshift_int(s, c);
- string ns = "";
- string tag_name = Rosella.Xml.__parse_alphanumeric(xml, s, b, len);
- eat_whitespace(s, b);
- c = peek_next(s, b);
- if (c == ASCII_COLON) {
- get_next(s, b);
- eat_whitespace(s, b);
- ns = tag_name;
- tag_name = Rosella.Xml.__parse_alphanumeric(xml, s, b, len);
- }
-
- //if (is_close_tag)
- //tag_name = "/" + tag_name;
- var xtag = new Rosella.Xml.Tag(ns, tag_name);
-
- eat_whitespace(s, b);
- if (!is_close_tag)
- Rosella.Xml.__parse_attributes(xml, s, b, len, xtag);
-
- c = get_next(s, b);
- if (c == ASCII_GREATER_THAN)
- return xtag, is_close_tag, false, false;
-
- if (c == ASCII_SLASH) {
- int next = get_next(s, b);
- if (next == ASCII_GREATER_THAN)
- return xtag, false, true, false;
- else
- Rosella.Error.error("Syntax error in tag %s", tag_name);
- }
-
- Rosella.Xml.__error_unknown_char(c, "tag " + tag_name);
- }
-
- function __error_unknown_char(int c, string context)
- {
- if (c == ASCII_NULL)
- Rosella.Error.error("Unexpected end of input while parsing %s", context);
- Rosella.Error.error("Unexpected token '%s' in %s", chr(c), context);
- }
-
- function __parse_comment(string xml, var s, var b, int len)
- {
- if (get_next(s, b) != ASCII_DASH || get_next(s, b) != ASCII_DASH)
- Rosella.Error.error("Malformed comment");
-
- var sb = new 'StringBuilder';
- while (have_more_chars(s, b)) {
- int c = get_next(s, b);
-
- if (c == ASCII_DASH) {
- int d = get_next(s, b);
- if (d == ASCII_DASH) {
- int e = get_next(s, b);
- if (e == ASCII_GREATER_THAN) {
- string text = string(sb);
- var comment = new Rosella.Xml.Tag.Comment(text);
- return comment, true, true, true;
- }
- unshift_int(s, e);
- }
- unshift_int(s, d);
- }
- push(sb, chr(c));
- }
- Rosella.Error.error("Unterminated comment at end of document");
- }
-
- function __parse_attributes(string xml, var s, var b, int len, var xtag)
- {
- while (have_more_chars(s, b)) {
- eat_whitespace(s, b);
- int c = peek_next(s, b);
- if (!is_name_char(c))
- break;
-
- string attr_name = Rosella.Xml.__parse_alphanumeric(xml, s, b, len);
- eat_whitespace(s, b);
-
- c = get_next(s, b);
- if (c != ASCII_EQUALS) {
- unshift_int(s, c);
- xtag.add_attribute(attr_name, "true");
- eat_whitespace(s, b);
- continue;
- }
-
- c = get_next(s, b);
- if (c == ASCII_SINGLE_QUOTE || c == ASCII_DOUBLE_QUOTE) {
- string attr_value = Rosella.Xml.__parse_quoted(c, xml, s, b, len);
- xtag.add_attribute(attr_name, attr_value);
- } else {
- unshift_int(s, c);
- string attr_value = Rosella.Xml.__parse_alphanumeric(xml, s, b, len);
- xtag.add_attribute(attr_name, attr_value);
- }
- }
- }
-
- function __parse_alphanumeric(string xml, var s, var b, int len)
- {
- var sb = new 'StringBuilder';
- int c = get_next(s, b);
- while(have_more_chars(s, b) && is_name_char(c)) {
- push(sb, chr(c));
- c = get_next(s, b);
- }
- unshift_int(s, c);
- string result = string(sb);
- return result;
- }
-
- function __parse_quoted(int q, string xml, var s, var b, int len)
- {
- var sb = new 'StringBuilder';
- int c = get_next(s, b);
- while (c != q) {
- push(sb, chr(c));
- if (c == ASCII_SLASH) {
- c = get_next(s, b);
- push(sb, chr(c));
- }
- c = get_next(s, b);
- }
- return sb;
+ return Rosella.Xml.Parser.__parse_xml(xml, s, b, len, document);
}
}
View
34 t/xml/Parsing.t
@@ -0,0 +1,34 @@
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test", "xml");
+ Rosella.Test.test_vector(
+ function(var self, string data) {
+ var doc = Rosella.Xml.read_string(data);
+ self.assert.not_null(doc);
+ self.assert.instance_of(doc, class Rosella.Xml.Document);
+ }, __test_data()
+ );
+}
+
+function __test_data() { return {
+ "Basic" : "<foo><bar><baz></baz></bar></foo>",
+ "contained tag" : "<foo><bar><baz/></bar></foo>",
+ "one tag" : "<foo></foo>",
+ "one contained tag" : "<foo/>",
+ "xml header" : "<?xml version='1.0'?><foo></foo>",
+ "dtd header" : "<!DOCTYPE foo SYSTEM 'foo.dtd'><foo></foo>",
+ "two headers" : "<?xml version='1.0'?><!DOCTYPE foo SYSTEM 'foo.dtd'><foo></foo>",
+ "comments between headers" : "<!--test--><?xml version='1.0'?><!--test2--><!DOCTYPE foo SYSTEM 'foo.dtd'><!--test3--><foo></foo>",
+ "whitespace" : <<:
+<foo>
+ < bar>
+ < baz />
+ </bar >
+</foo >
+
+
+:>>
+,
+ "namespaces" : "<foo:bar></foo:bar>"
+};}

No commit comments for this range

Something went wrong with that request. Please try again.