From d98fc013878ab28cb062a4f25a45199b9ee9574a Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 5 Dec 2014 12:18:02 +0100 Subject: Made the CSSParser a valid subclass of Parser. --- src/core/CSSParser.hpp | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/core/CSSParser.hpp') diff --git a/src/core/CSSParser.hpp b/src/core/CSSParser.hpp index 7dfc872..870ce37 100644 --- a/src/core/CSSParser.hpp +++ b/src/core/CSSParser.hpp @@ -22,12 +22,16 @@ #include #include +#include + #include "BufferedCharReader.hpp" #include "CodeTokenizer.hpp" #include "CSS.hpp" #include "Exceptions.hpp" namespace ousia { +namespace parser { +namespace css { /** * This is a context free, recursive parser for a subset of the CSS3 language @@ -57,32 +61,35 @@ namespace ousia { * * @author Benjamin Paassen - bpaassen@techfak.uni-bielefeld.de */ -class CSSParser { +class CSSParser : public Parser { private: /** * Implements the DOC Nonterminal */ - void parseDocument(Rooted root, CodeTokenizer &tokenizer); + void parseDocument(Rooted root, CodeTokenizer &tokenizer, + ParserContext &ctx); /** * Implements the SELECTORS Nonterminal and adds all leaf nodes of the * resulting SelectorTree to the input leafList so that a parsed RuleSet can * be inserted there. */ void parseSelectors(Rooted root, CodeTokenizer &tokenizer, - std::vector> &leafList); + std::vector> &leafList, + ParserContext &ctx); /** * Implements the SELECT Nonterminal, which in effect parses a SelectorPath * of the SelectorTree and returns the beginning node of the path as first * element as well as the leaf of the path as second tuple element. */ std::tuple, Rooted> parseSelector( - CodeTokenizer &tokenizer); + CodeTokenizer &tokenizer, ParserContext &ctx); /** * Implements the SELECT' Nonterminal, which parses a single Selector with * its PseudoSelector and returns it. */ - Rooted parsePrimitiveSelector(CodeTokenizer &tokenizer); + Rooted parsePrimitiveSelector(CodeTokenizer &tokenizer, + ParserContext &ctx); // TODO: Add RuleSet parsing methods. @@ -101,7 +108,7 @@ private: * @return true iff a token of the expected type was found. */ bool expect(int expectedType, CodeTokenizer &tokenizer, Token &t, - bool force); + bool force, ParserContext &ctx); public: /** @@ -110,9 +117,26 @@ public: * SelectorTree. * TODO: The RuleSet at the respective node at the tree lists all CSS Style * rules that apply. + * + * @param is is a reference to the input stream that should be parsed. + * @param ctx is a reference to the context that should be used while + * parsing the document. + * @return returns the root node of the resulting SelectorTree. For more + * information on the return conventions consult the Parser.hpp. */ - Rooted parse(BufferedCharReader &input); + Rooted parse(std::istream &is, ParserContext &ctx) override; + + /** + * As befits a class called CSSParser, this Parser parses CSS. + */ + std::set mimetypes() + { + std::set out{"text/css"}; + return out; + } }; } +} +} #endif -- cgit v1.2.3