static TDictionary::Entry undefinedEntry;
void
-TDictionary::load(const char* uri)
+TDictionary::load(const std::string& uri)
{
+ logger.debug("Dictionary: loading `" + uri + "'");
+
DOM::DOMImplementation di;
+ DOM::Document doc = di.createDocumentFromURI(uri.c_str());
+ assert(doc);
+ load(doc);
+}
- DOM::Document doc = di.createDocumentFromURI(uri);
+void
+TDictionary::load(const DOM::Document& doc)
+{
assert(doc);
DOM::Element root = doc.get_documentElement();
TTokenizer tokenizer(logger);
for (DOM::Node p = root.get_firstChild(); p; p = p.get_nextSibling())
- if (p.get_nodeType() == DOM::Node::ELEMENT_NODE && p.get_nodeName() == "entry")
+ if (p.get_nodeType() == DOM::Node::ELEMENT_NODE && p.get_nodeName() == "include")
+ {
+ DOM::Element el = p;
+ assert(el);
+ if (el.hasAttribute("href"))
+ // WARNING: this may result into an infinite loop!
+ load(std::string(el.getAttribute("href")));
+ else
+ logger.warning("Dictionary: include statement with no href attribute (ignored)");
+ }
+ else if (p.get_nodeType() == DOM::Node::ELEMENT_NODE && p.get_nodeName() == "entry")
{
DOM::Element el = p;
assert(el);
std::string name = el.getAttribute("name");
if (entries.find(name) != entries.end())
- cerr << "WARNING: entry `" << name << "' is being redefined" << endl;
+ logger.info("Dictionary: `" + name + "' is being redefined");
Entry entry;
{
entry.value = el.getAttribute("val");
if (entry.cls == MACRO)
- cerr << "WARNING: `" << name << "' has a specified value, but is classified as macro" << endl;
+ logger.warning("Dictionary: `" + name + "' has a specified value, but is classified as macro");
}
if (el.hasAttribute("pattern"))
{
if (entry.cls != MACRO)
- cerr << "WARNING: `" << name << "' has a specified pattern, but is not classified as macro" << endl;
+ logger.warning("Dictionary: `" + name + "' has a specified pattern, but is not classified as macro");
std::string pattern = el.getAttribute("pattern");
if (pattern == "{}")
entry.pattern = tokenizer.tokenize(pattern);
}
+#if 0
if (el.hasAttribute("infix"))
{
std::istringstream is(el.getAttribute("infix"));
if (!el.hasAttribute("prefix")) entry.prefix = postfix;
}
}
+#endif
if (el.hasAttribute("limits"))
{
if (el.hasAttribute("delimiter"))
{
if (entry.cls != OPERATOR && !entry.embellishment)
- cerr << "WARNING: `" << name << "' delimiter ignored for non-operator" << endl;
+ logger.warning("Dictionary: `" + name + "' delimiter ignored for non-operator");
std::istringstream is(el.getAttribute("delimiter"));
unsigned delimiter;
if (el.hasAttribute("table"))
{
if (entry.cls != MACRO)
- cerr << "WARNING: `" << name << "' table ignored for non-macro" << endl;
+ logger.warning("Dictionary: `" + name + "' table ignored for non-macro");
std::istringstream is(el.getAttribute("table"));
unsigned table;