diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/css/CSSParser.cpp | 28 | ||||
-rw-r--r-- | src/plugins/html/DemoOutput.cpp | 36 | ||||
-rw-r--r-- | src/plugins/html/DemoOutput.hpp | 10 | ||||
-rw-r--r-- | src/plugins/xml/XmlParser.cpp | 19 |
4 files changed, 41 insertions, 52 deletions
diff --git a/src/plugins/css/CSSParser.cpp b/src/plugins/css/CSSParser.cpp index 8cb41ea..cf92d32 100644 --- a/src/plugins/css/CSSParser.cpp +++ b/src/plugins/css/CSSParser.cpp @@ -79,7 +79,7 @@ Rooted<Node> CSSParser::doParse(CharReader &reader, ParserContext &ctx) CodeTokenizer tokenizer{reader, CSS_ROOT, CSS_DESCRIPTORS}; tokenizer.ignoreComments = true; tokenizer.ignoreLinebreaks = true; - Rooted<SelectorNode> root = {new SelectorNode{ctx.manager, "root"}}; + Rooted<SelectorNode> root = {new SelectorNode{ctx.getManager(), "root"}}; parseDocument(root, tokenizer, ctx); return root; } @@ -165,7 +165,7 @@ std::pair<Rooted<SelectorNode>, Rooted<SelectorNode>> CSSParser::parseSelector( auto tuple = parseSelector(tokenizer, ctx); // then we establish the DESCENDANT relationship s->getEdges().push_back( - new SelectorNode::SelectorEdge(ctx.manager, tuple.first)); + new SelectorNode::SelectorEdge(ctx.getManager(), tuple.first)); // and we return this node as well as the leaf. return std::make_pair(s, tuple.second); } @@ -177,7 +177,7 @@ std::pair<Rooted<SelectorNode>, Rooted<SelectorNode>> CSSParser::parseSelector( auto tuple = parseSelector(tokenizer, ctx); // then we establish the DESCENDANT relationship s->getEdges().push_back(new SelectorNode::SelectorEdge( - ctx.manager, tuple.first, + ctx.getManager(), tuple.first, SelectionOperator::DIRECT_DESCENDANT)); // and we return this node as well as the leaf. return std::make_pair(s, tuple.second); @@ -198,7 +198,7 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, const std::string name = t.content; if (!tokenizer.peek(t)) { // if we are at the end, we just return this selector with its name. - Rooted<SelectorNode> n{new SelectorNode(ctx.manager, name)}; + Rooted<SelectorNode> n{new SelectorNode(ctx.getManager(), name)}; return n; } @@ -219,7 +219,7 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, if (!expect(PAREN_OPEN, tokenizer, t, false, ctx)) { // if we don't have any, we return here. Rooted<SelectorNode> n{new SelectorNode( - ctx.manager, name, {pseudo_select_name, isGenerative})}; + ctx.getManager(), name, {pseudo_select_name, isGenerative})}; return n; } // parse the argument list. @@ -227,18 +227,18 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, // we require at least one argument, if parantheses are used // XXX args.push_back(VariantReader::parseGeneric(tokenizer.getInput(), - ctx.logger, + ctx.getLogger(), {',', ')'}).second); while (expect(COMMA, tokenizer, t, false, ctx)) { // as long as we find commas we expect new arguments. args.push_back( VariantReader::parseGeneric( - tokenizer.getInput(), ctx.logger, {',', ')'}).second); + tokenizer.getInput(), ctx.getLogger(), {',', ')'}).second); } expect(PAREN_CLOSE, tokenizer, t, true, ctx); // and we return with the finished Selector. Rooted<SelectorNode> n{new SelectorNode( - ctx.manager, name, {pseudo_select_name, args, isGenerative})}; + ctx.getManager(), name, {pseudo_select_name, args, isGenerative})}; return n; } case HASH: { @@ -250,7 +250,7 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, Variant::arrayType args{Variant(t.content.c_str())}; // and we return the finished Selector Rooted<SelectorNode> n{ - new SelectorNode(ctx.manager, name, {"has_id", args, false})}; + new SelectorNode(ctx.getManager(), name, {"has_id", args, false})}; return n; } case BRACKET_OPEN: { @@ -270,7 +270,7 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, expect(BRACKET_CLOSE, tokenizer, t, true, ctx); // and then we can return the result. Rooted<SelectorNode> n{new SelectorNode( - ctx.manager, name, {"has_attribute", args, false})}; + ctx.getManager(), name, {"has_attribute", args, false})}; return n; } else { // with an equals sign we have a has_value PseudoSelector and @@ -281,14 +281,14 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, expect(BRACKET_CLOSE, tokenizer, t, true, ctx); // and then we can return the result. Rooted<SelectorNode> n{new SelectorNode( - ctx.manager, name, {"has_value", args, false})}; + ctx.getManager(), name, {"has_value", args, false})}; return n; } } default: // everything else is not part of the Selector anymore. tokenizer.resetPeek(); - Rooted<SelectorNode> n{new SelectorNode(ctx.manager, name)}; + Rooted<SelectorNode> n{new SelectorNode(ctx.getManager(), name)}; return n; } } @@ -296,7 +296,7 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, Rooted<RuleSet> CSSParser::parseRuleSet(CodeTokenizer &tokenizer, ParserContext &ctx) { - Rooted<RuleSet> ruleSet{new RuleSet(ctx.manager)}; + Rooted<RuleSet> ruleSet{new RuleSet(ctx.getManager())}; // if we have no ruleset content, we return an empty ruleset. Token t; if (!expect(CURLY_OPEN, tokenizer, t, false, ctx)) { @@ -332,7 +332,7 @@ bool CSSParser::parseRule(CodeTokenizer &tokenizer, ParserContext &ctx, expect(COLON, tokenizer, t, true, ctx); // then the value // TODO: Resolve key for appropriate parsing function here. - value = VariantReader::parseGeneric(tokenizer.getInput(), ctx.logger, + value = VariantReader::parseGeneric(tokenizer.getInput(), ctx.getLogger(), {';'}).second; // and a ; expect(SEMICOLON, tokenizer, t, true, ctx); diff --git a/src/plugins/html/DemoOutput.cpp b/src/plugins/html/DemoOutput.cpp index a3d1b84..503c104 100644 --- a/src/plugins/html/DemoOutput.cpp +++ b/src/plugins/html/DemoOutput.cpp @@ -27,7 +27,7 @@ namespace ousia { namespace html { -void DemoHTMLTransformer::writeHTML(Handle<model::Document> doc, +void DemoHTMLTransformer::writeHTML(Handle<Document> doc, std::ostream &out, bool pretty) { Manager &mgr = doc->getManager(); @@ -66,7 +66,7 @@ void DemoHTMLTransformer::writeHTML(Handle<model::Document> doc, } // extract the book root node. - Rooted<model::StructuredEntity> root = doc->getRoot(); + Rooted<StructuredEntity> root = doc->getRoot(); if (root->getDescriptor()->getName() != "book") { throw OusiaException("The given documents root is no book node!"); } @@ -98,7 +98,7 @@ SectionType getSectionType(const std::string &name) } Rooted<xml::Element> DemoHTMLTransformer::transformSection( - Handle<xml::Element> parent, Handle<model::StructuredEntity> section, + Handle<xml::Element> parent, Handle<StructuredEntity> section, AnnoMap &startMap, AnnoMap &endMap) { Manager &mgr = section->getManager(); @@ -115,8 +115,8 @@ Rooted<xml::Element> DemoHTMLTransformer::transformSection( // check if we have a heading. if (section->hasField("heading") && section->getField("heading").size() > 0) { - Handle<model::StructuredEntity> heading = - section->getField("heading")[0].cast<model::StructuredEntity>(); + Handle<StructuredEntity> heading = + section->getField("heading")[0].cast<StructuredEntity>(); std::string headingclass; switch (type) { case SectionType::BOOK: @@ -149,7 +149,7 @@ Rooted<xml::Element> DemoHTMLTransformer::transformSection( if (!n->isa(RttiTypes::StructuredEntity)) { continue; } - Handle<model::StructuredEntity> s = n.cast<model::StructuredEntity>(); + Handle<StructuredEntity> s = n.cast<StructuredEntity>(); /* * Strictly speaking this is the wrong mechanism, because we would have * to make an "isa" call here because we can not rely on our knowledge @@ -174,7 +174,7 @@ Rooted<xml::Element> DemoHTMLTransformer::transformSection( } Rooted<xml::Element> DemoHTMLTransformer::transformList( - Handle<xml::Element> parent, Handle<model::StructuredEntity> list, + Handle<xml::Element> parent, Handle<StructuredEntity> list, AnnoMap &startMap, AnnoMap &endMap) { Manager &mgr = list->getManager(); @@ -183,8 +183,8 @@ Rooted<xml::Element> DemoHTMLTransformer::transformList( Rooted<xml::Element> l{new xml::Element{mgr, parent, listclass}}; // iterate through list items. for (auto &it : list->getField()) { - Handle<model::StructuredEntity> item = - it.cast<model::StructuredEntity>(); + Handle<StructuredEntity> item = + it.cast<StructuredEntity>(); std::string itDescrName = item->getDescriptor()->getName(); if (itDescrName == "item") { // create the list item. @@ -203,10 +203,10 @@ Rooted<xml::Element> DemoHTMLTransformer::transformList( return l; } -typedef std::stack<Rooted<model::AnnotationEntity>> AnnoStack; +typedef std::stack<Rooted<AnnotationEntity>> AnnoStack; static Rooted<xml::Element> openAnnotation( - Manager &mgr, AnnoStack &opened, Handle<model::AnnotationEntity> entity, + Manager &mgr, AnnoStack &opened, Handle<AnnotationEntity> entity, Handle<xml::Element> current) { // we push the newly opened entity on top of the stack. @@ -225,7 +225,7 @@ static Rooted<xml::Element> openAnnotation( } Rooted<xml::Element> DemoHTMLTransformer::transformParagraph( - Handle<xml::Element> parent, Handle<model::StructuredEntity> par, + Handle<xml::Element> parent, Handle<StructuredEntity> par, AnnoMap &startMap, AnnoMap &endMap) { Manager &mgr = par->getManager(); @@ -234,8 +234,8 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph( // check if we have a heading. if (par->hasField("heading") && par->getField("heading").size() > 0) { - Handle<model::StructuredEntity> heading = - par->getField("heading")[0].cast<model::StructuredEntity>(); + Handle<StructuredEntity> heading = + par->getField("heading")[0].cast<StructuredEntity>(); // put the heading in a strong xml::Element. Rooted<xml::Element> strong{new xml::Element{mgr, p, "strong"}}; p->addChild(strong); @@ -281,7 +281,7 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph( * be re-opened. */ AnnoStack tmp; - Rooted<model::AnnotationEntity> closed = opened.top(); + Rooted<AnnotationEntity> closed = opened.top(); current = current->getParent(); opened.pop(); while (closed->getEnd()->getName() != n->getName()) { @@ -313,12 +313,12 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph( if (!n->isa(RttiTypes::StructuredEntity)) { continue; } - Handle<model::StructuredEntity> t = n.cast<model::StructuredEntity>(); + Handle<StructuredEntity> t = n.cast<StructuredEntity>(); std::string childDescriptorName = t->getDescriptor()->getName(); if (childDescriptorName == "text") { - Handle<model::DocumentPrimitive> primitive = - t->getField()[0].cast<model::DocumentPrimitive>(); + Handle<DocumentPrimitive> primitive = + t->getField()[0].cast<DocumentPrimitive>(); if (primitive.isNull()) { throw OusiaException("Text field is not primitive!"); } diff --git a/src/plugins/html/DemoOutput.hpp b/src/plugins/html/DemoOutput.hpp index b755aac..67b7494 100644 --- a/src/plugins/html/DemoOutput.hpp +++ b/src/plugins/html/DemoOutput.hpp @@ -39,7 +39,7 @@ namespace ousia { namespace html { -typedef std::map<std::string, Rooted<model::AnnotationEntity>> AnnoMap; +typedef std::map<std::string, Rooted<AnnotationEntity>> AnnoMap; class DemoHTMLTransformer { private: @@ -50,14 +50,14 @@ private: * called recursively. */ Rooted<xml::Element> transformSection(Handle<xml::Element> parent, - Handle<model::StructuredEntity> sec, + Handle<StructuredEntity> sec, AnnoMap &startMap, AnnoMap &endMap); /** * This transforms a list entity, namely ul and ol to an XHTML element. * For each item, the transformParagraph function is called. */ Rooted<xml::Element> transformList(Handle<xml::Element> parent, - Handle<model::StructuredEntity> list, + Handle<StructuredEntity> list, AnnoMap &startMap, AnnoMap &endMap); /** * This transforms a paragraph-like entity, namely heading, item and @@ -65,7 +65,7 @@ private: * contained. For anchor handling we require the AnnoMaps. */ Rooted<xml::Element> transformParagraph(Handle<xml::Element> parent, - Handle<model::StructuredEntity> par, + Handle<StructuredEntity> par, AnnoMap &startMap, AnnoMap &endMap); public: @@ -89,7 +89,7 @@ public: * @param pretty is a flag that manipulates whether newlines and tabs are * used. */ - void writeHTML(Handle<model::Document> doc, std::ostream &out, + void writeHTML(Handle<Document> doc, std::ostream &out, bool pretty = true); }; } diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index 78d9df8..17bc470 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -32,8 +32,6 @@ namespace ousia { -using namespace ousia::model; - /* Document structure */ static const State STATE_DOCUMENT = 0; static const State STATE_HEAD = 1; @@ -235,24 +233,18 @@ public: /* Adapter Expat -> ParserStack */ -struct XMLParserUserData { - SourceId sourceId; -}; - static SourceLocation syncLoggerPosition(XML_Parser p) { // Fetch the parser stack and the associated user data ParserStack *stack = static_cast<ParserStack *>(XML_GetUserData(p)); - XMLParserUserData *ud = - static_cast<XMLParserUserData *>(stack->getUserData()); // Fetch the current location in the XML file size_t offs = XML_GetCurrentByteIndex(p); // Build the source location and update the default location of the current // logger instance - SourceLocation loc{ud->sourceId, offs}; - stack->getContext().logger.setDefaultLocation(loc); + SourceLocation loc{stack->getContext().getSourceId(), offs}; + stack->getContext().getLogger().setDefaultLocation(loc); return loc; } @@ -269,7 +261,7 @@ static void xmlStartElementHandler(void *p, const XML_Char *name, while (*attr) { const std::string key{*(attr++)}; std::pair<bool, Variant> value = VariantReader::parseGenericString( - *(attr++), stack->getContext().logger); + *(attr++), stack->getContext().getLogger()); args.emplace(std::make_pair(key, value.second)); } stack->start(std::string(name), args, loc); @@ -305,10 +297,7 @@ Rooted<Node> XmlParser::doParse(CharReader &reader, ParserContext &ctx) // Create the parser stack instance and pass the reference to the state // machine descriptor - XMLParserUserData data; - data.sourceId = reader.getSourceId(); - - ParserStack stack{ctx, XML_HANDLERS, &data}; + ParserStack stack{ctx, XML_HANDLERS}; XML_SetUserData(&p, &stack); XML_UseParserAsHandlerArg(&p); |