aboutsummaryrefslogtreecommitdiff
path: root/cutl/xml
diff options
context:
space:
mode:
Diffstat (limited to 'cutl/xml')
-rw-r--r--cutl/xml/parser.cxx74
-rw-r--r--cutl/xml/parser.hxx17
-rw-r--r--cutl/xml/parser.ixx21
3 files changed, 90 insertions, 22 deletions
diff --git a/cutl/xml/parser.cxx b/cutl/xml/parser.cxx
index ca20edd..08f08ff 100644
--- a/cutl/xml/parser.cxx
+++ b/cutl/xml/parser.cxx
@@ -58,6 +58,26 @@ namespace cutl
return what_.c_str ();
}
+ // parser::event_type
+ //
+ static const char* parser_event_str[] =
+ {
+ "start element",
+ "end element",
+ "start attribute",
+ "end attribute",
+ "characters",
+ "start namespace declaration",
+ "end namespace declaration",
+ "end of file"
+ };
+
+ ostream&
+ operator<< (ostream& os, parser::event_type e)
+ {
+ return os << parser_event_str[e];
+ }
+
// parser
//
parser::
@@ -117,9 +137,9 @@ namespace cutl
switch (content ())
{
case empty:
- throw parsing (iname_, line_, column_, "character in empty content");
+ throw parsing (*this, "character in empty content");
case complex:
- throw parsing (iname_, line_, column_, "character in complex content");
+ throw parsing (*this, "character in complex content");
default:
assert (false);
}
@@ -171,6 +191,34 @@ namespace cutl
istream::iostate old_state_;
};
+ void parser::
+ next_expect (event_type e)
+ {
+ if (next () != e)
+ throw parsing (*this, parser_event_str[e] + string (" expected"));
+ }
+
+ void parser::
+ next_expect (event_type e, const string& ns, const string& n)
+ {
+ if (next () != e || namespace_ () != ns || name () != n)
+ {
+ string m (parser_event_str[e]);
+ m += " '";
+
+ if (!ns.empty ())
+ {
+ m += ns;
+ m += '#';
+ }
+
+ m += n;
+ m += "' expected";
+
+ throw parsing (*this, m);
+ }
+ }
+
parser::event_type parser::
next_ ()
{
@@ -190,9 +238,9 @@ namespace cutl
switch (content ())
{
case empty:
- throw parsing (iname_, line_, column_, "element in empty content");
+ throw parsing (*this, "element in empty content");
case simple:
- throw parsing (iname_, line_, column_, "element in simple content");
+ throw parsing (*this, "element in simple content");
default:
break;
}
@@ -630,23 +678,5 @@ namespace cutl
p.end_ns_.push_back (qname_type ());
p.end_ns_.back ().prefix () = (prefix != 0 ? prefix : "");
}
-
- static const char* parser_event_str[] =
- {
- "start element",
- "end element",
- "start attribute",
- "end attribute",
- "characters",
- "start namespace declaration",
- "end namespace declaration",
- "end of file"
- };
-
- ostream&
- operator<< (ostream& os, parser::event_type e)
- {
- return os << parser_event_str[e];
- }
}
}
diff --git a/cutl/xml/parser.hxx b/cutl/xml/parser.hxx
index d7011af..5d1e9e5 100644
--- a/cutl/xml/parser.hxx
+++ b/cutl/xml/parser.hxx
@@ -131,6 +131,21 @@ namespace cutl
}
}
+ // Get the next event and make sure that it's what's expected. If it
+ // is not, then throw an appropriate parsing exception.
+ //
+ void
+ next_expect (event_type);
+
+ void
+ next_expect (event_type, const qname_type& qname);
+
+ void
+ next_expect (event_type, const std::string& name);
+
+ void
+ next_expect (event_type, const std::string& ns, const std::string& name);
+
event_type
peek ()
{
@@ -283,4 +298,6 @@ namespace cutl
}
}
+#include <cutl/xml/parser.ixx>
+
#endif // CUTL_XML_PARSER_HXX
diff --git a/cutl/xml/parser.ixx b/cutl/xml/parser.ixx
new file mode 100644
index 0000000..61bb05b
--- /dev/null
+++ b/cutl/xml/parser.ixx
@@ -0,0 +1,21 @@
+// file : cutl/xml/parser.ixx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+namespace cutl
+{
+ namespace xml
+ {
+ inline void parser::
+ next_expect (event_type e, const qname_type& qn)
+ {
+ return next_expect (e, qn.namespace_ (), qn.name ());
+ }
+
+ inline void parser::
+ next_expect (event_type e, const std::string& n)
+ {
+ return next_expect (e, std::string (), n);
+ }
+ }
+}