From 67c3618e593f88eb8177404475586735902d693f Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 25 Jan 2015 18:57:19 +0100 Subject: Restructures parser classes a little, removed Registry from ParserContext, gave a ResourceManager instance to the Project, using ResourceRequest when including or linking files, thought through how "including" and "linking" are handled --- src/plugins/css/CSSParser.cpp | 28 ++++++++++++++-------------- src/plugins/xml/XmlParser.cpp | 19 ++++--------------- 2 files changed, 18 insertions(+), 29 deletions(-) (limited to 'src/plugins') 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 CSSParser::doParse(CharReader &reader, ParserContext &ctx) CodeTokenizer tokenizer{reader, CSS_ROOT, CSS_DESCRIPTORS}; tokenizer.ignoreComments = true; tokenizer.ignoreLinebreaks = true; - Rooted root = {new SelectorNode{ctx.manager, "root"}}; + Rooted root = {new SelectorNode{ctx.getManager(), "root"}}; parseDocument(root, tokenizer, ctx); return root; } @@ -165,7 +165,7 @@ std::pair, Rooted> 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> 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 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 n{new SelectorNode(ctx.manager, name)}; + Rooted n{new SelectorNode(ctx.getManager(), name)}; return n; } @@ -219,7 +219,7 @@ Rooted CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, if (!expect(PAREN_OPEN, tokenizer, t, false, ctx)) { // if we don't have any, we return here. Rooted 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 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 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 CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, Variant::arrayType args{Variant(t.content.c_str())}; // and we return the finished Selector Rooted 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 CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, expect(BRACKET_CLOSE, tokenizer, t, true, ctx); // and then we can return the result. Rooted 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 CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, expect(BRACKET_CLOSE, tokenizer, t, true, ctx); // and then we can return the result. Rooted 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 n{new SelectorNode(ctx.manager, name)}; + Rooted n{new SelectorNode(ctx.getManager(), name)}; return n; } } @@ -296,7 +296,7 @@ Rooted CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, Rooted CSSParser::parseRuleSet(CodeTokenizer &tokenizer, ParserContext &ctx) { - Rooted ruleSet{new RuleSet(ctx.manager)}; + Rooted 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/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(XML_GetUserData(p)); - XMLParserUserData *ud = - static_cast(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 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 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); -- cgit v1.2.3