summaryrefslogtreecommitdiff
path: root/src/core/utils/CSSParser.hpp
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2014-11-14 00:13:40 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2014-11-14 00:13:40 +0100
commit8ae1ca37ae7b3e5443221908e7ca2a38a70c96ed (patch)
tree0e0b964958facbd291b0fb0c13515c4b14b67381 /src/core/utils/CSSParser.hpp
parentbc4d1cb7dcbbab9bca7f75e2e0c70d54493aae0b (diff)
added .gitignore file and finished building the rough class structure for CSS parsing. This, however, is very likely to be very wrong at this current state. Shivering with fear I await my liegelords justice.
Diffstat (limited to 'src/core/utils/CSSParser.hpp')
-rw-r--r--src/core/utils/CSSParser.hpp119
1 files changed, 108 insertions, 11 deletions
diff --git a/src/core/utils/CSSParser.hpp b/src/core/utils/CSSParser.hpp
index 4e82371..8db5cdd 100644
--- a/src/core/utils/CSSParser.hpp
+++ b/src/core/utils/CSSParser.hpp
@@ -20,8 +20,12 @@
#define _OUSIA_UTILS_CSS_PARSER_HPP_
#include <istream>
+#include <map>
+#include <vector>
#include <tuple>
+#include "BufferedCharReader.hpp"
+
namespace ousia {
namespace utils {
@@ -36,29 +40,122 @@ namespace utils {
* local style definitions for single nodes.
*/
struct Specificity {
+ int b;
+ int c;
+ int d;
-int b;
-int c;
-int d;
-
-Specificity(int b, int c, int d): b(b), c(c), d(d) {}
-
+ Specificity(int b, int c, int d) : b(b), c(c), d(d) {}
};
-
-bool operator< (const Specificity &x, const Specificity &y){
+bool operator<(const Specificity &x, const Specificity &y)
+{
return std::tie(x.b, x.c, x.d) < std::tie(y.b, y.c, y.d);
}
-bool operator> (const Specificity &x, const Specificity &y){
+bool operator>(const Specificity &x, const Specificity &y)
+{
return std::tie(x.b, x.c, x.d) > std::tie(y.b, y.c, y.d);
}
-bool operator== (const Specificity &x, const Specificity &y){
+bool operator==(const Specificity &x, const Specificity &y)
+{
return std::tie(x.b, x.c, x.d) == std::tie(y.b, y.c, y.d);
}
+class RuleSet {
+private:
+ const std::map<std::string, std::string> values;
+ const Specificity specificity;
+
+public:
+ RuleSet(std::map<std::string, std::string> values, Specificity specificity)
+ : values(values), specificity(specificity)
+ {
+ }
+
+ const std::map<std::string, std::string> &getValues() const
+ {
+ return values;
+ }
+
+ const Specificity &getSpecificity() const { return specificity; }
+};
+
+class PseudoSelector {
+private:
+ const std::string name;
+ const std::vector<std::string> args;
+ const bool generative;
+
+public:
+ PseudoSelector(std::string name, std::vector<std::string> args,
+ bool generative)
+ : name(name), args(args), generative(generative)
+ {
+ }
+
+ const std::string &getName() const { return name; }
+
+ const std::vector<std::string> &getArgs() const { return args; }
+
+ const bool &isGenerative() const { return generative; }
+};
+
+enum class SelectionOperator { DESCENDANT, DIRECT_DESCENDANT };
+
+// TODO: Subclass of Andreas' Node class
+class StyleEdge {
+private:
+ // TODO: This is wrong! Here we want to have a managed pointer as Andreas
+ // mentioned!
+ // const StyleNode target;
+ const SelectionOperator selectionOperator;
+
+public:
+ StyleEdge(/*StyleNode target,*/ SelectionOperator selectionOperator)
+ : /*target(target),*/ selectionOperator(selectionOperator)
+ {
+ }
+
+ // const StyleNode &getTarget() const { return target; }
+
+ const SelectionOperator &getSelectionOperator() const
+ {
+ return selectionOperator;
+ }
+};
+
+// TODO: Subclass of Andreas' Node class
+class StyleNode {
+private:
+ const std::string className;
+ const PseudoSelector pseudoSelector;
+ const std::vector<StyleEdge> edges;
+ const std::vector<RuleSet> ruleSets;
+
+public:
+ StyleNode(std::string className, PseudoSelector pseudoSelector,
+ std::vector<StyleEdge> edges, std::vector<RuleSet> ruleSets)
+ : className(className),
+ pseudoSelector(pseudoSelector),
+ edges(edges),
+ ruleSets(ruleSets)
+ {
+ }
+
+ const std::string &getClassName() const { return className; }
+
+ const PseudoSelector &getPseudoSelector() const { return pseudoSelector; }
+
+ const std::vector<StyleEdge> &getEdges() const { return edges; }
+
+ const std::vector<RuleSet> &getRuleSets() const { return ruleSets; }
+};
+
+class CSSParser {
+public:
+ StyleNode parse(BufferedCharReader &input);
+};
}
}
-
#endif