diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/BufferedCharReader.cpp | 2 | ||||
-rw-r--r-- | src/core/CSS.hpp | 93 | ||||
-rw-r--r-- | src/core/CodeTokenizer.cpp | 26 | ||||
-rw-r--r-- | src/core/CodeTokenizer.hpp | 4 |
4 files changed, 72 insertions, 53 deletions
diff --git a/src/core/BufferedCharReader.cpp b/src/core/BufferedCharReader.cpp index 0821a5d..aeedf12 100644 --- a/src/core/BufferedCharReader.cpp +++ b/src/core/BufferedCharReader.cpp @@ -158,7 +158,7 @@ bool BufferedCharReader::readCharacterAtCursor(ReadCursor &cursor, char *c) // If data has been read, append it to the input buffer and try // again if (cnt > 0) { - buffer.emplace_back(buf.data()); + buffer.emplace_back(std::string(buf.data(), cnt)); continue; } diff --git a/src/core/CSS.hpp b/src/core/CSS.hpp index 1c0ed17..4cf15be 100644 --- a/src/core/CSS.hpp +++ b/src/core/CSS.hpp @@ -23,6 +23,8 @@ #include <vector> #include <tuple> +#include <core/variant/Variant.hpp> + #include "Managed.hpp" #include "Node.hpp" @@ -44,51 +46,50 @@ struct Specificity { int d; Specificity(int b, int c, int d) : b(b), c(c), d(d) {} -}; -// TODO: Is this inline usage correct? I used this to prevent "multiple -// definition" errors -inline 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); -} + friend 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); + } -inline 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); -} + friend 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); + } -inline 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); -} + friend 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); + } +}; /** * The RuleSet class serves as a container class for key-value * pairs. The values are TypeInstances. The proper type is * implicitly defined by the keyword. - * - * TODO: This code is currently commented out until the TypeSystem works. */ -/*class RuleSet : public Managed { +class RuleSet : public Managed { private: - const std::map<std::string, std::string> values; - const Specificity specificity; + std::map<std::string, variant::Variant> rules; public: - RuleSet(Manager &mgr, std::map<std::string, std::string> values, - Specificity specificity) - : Managed(mgr), values(std::move(values)), specificity(specificity) - { - } + /** + * Initializes an empty RuleSet. + */ + RuleSet(Manager &mgr) : Managed(mgr), rules() {} - const std::map<std::string, std::string> &getValues() const - { - return values; - } + std::map<std::string, variant::Variant> &getRules() { return rules; } - const Specificity &getSpecificity() const { return specificity; } -};*/ + const std::map<std::string, variant::Variant> &getRules() const + { + return rules; + } + + void merge(Rooted<RuleSet> other) + { + rules.insert(other->rules.begin(), other->rules.end()); + } +}; /** * PseudoSelectors are functions that change the behaviour of Selectors. @@ -249,8 +250,8 @@ public: private: const PseudoSelector pseudoSelector; ManagedVector<SelectorEdge> edges; - // TODO: This is temporarily commented out until the TypeSystem works. - // Owned<RuleSet> ruleSets; + Owned<RuleSet> ruleSet; + bool accepting = false; /** * This is an internal method all getChildren variants refer to. @@ -260,21 +261,27 @@ private: const PseudoSelector *select); public: + /** + * This initializes an empty SelectorNode with the given name and the + * given PseudoSelector. + */ SelectorNode(Manager &mgr, std::string name, PseudoSelector pseudoSelector) : Node(mgr, std::move(name)), pseudoSelector(std::move(pseudoSelector)), - edges(this) //, - // TODO: This is temporarily commented out until the TypeSystem works. - // ruleSets(acquire(ruleSets)) + edges(this), + ruleSet(new RuleSet(mgr), this) { } + /** + * This initializes an empty SelectorNode with the given name and the + * trivial PseudoSelector "true". + */ SelectorNode(Manager &mgr, std::string name) : Node(mgr, std::move(name)), pseudoSelector("true", false), - edges(this) //, - // TODO: This is temporarily commented out until the TypeSystem works. - // ruleSets(acquire(ruleSets)) + edges(this), + ruleSet(new RuleSet(mgr), this) { } @@ -282,9 +289,7 @@ public: ManagedVector<SelectorEdge> &getEdges() { return edges; } - // TODO: This is temporarily commented out until the TypeSystem works. - // const std::vector<Owned<RuleSet>> &getRuleSets() const { return - // ruleSets; } + Rooted<RuleSet> getRuleSet() const { return ruleSet; } /** * This returns the child of this SelectorNode that is connected by @@ -386,6 +391,10 @@ public: * automatically using the DESCENDANT SelectionOperator. */ std::vector<Rooted<SelectorNode>> append(Rooted<SelectorNode> node); + + bool isAccepting() { return accepting; } + + void setAccepting(bool accepting) { this->accepting = accepting; } }; } #endif diff --git a/src/core/CodeTokenizer.cpp b/src/core/CodeTokenizer.cpp index ce4afe5..e9c1bbf 100644 --- a/src/core/CodeTokenizer.cpp +++ b/src/core/CodeTokenizer.cpp @@ -59,10 +59,14 @@ bool CodeTokenizer::doPrepare(const Token &t, std::deque<Token> &peeked) state = CodeTokenizerState::IN_LINE_COMMENT; break; case CodeTokenMode::LINEBREAK: - peeked.push_back({it->second.id, t.content, t.startColumn, - t.startLine, t.endColumn, t.endLine}); - return true; + if (!ignoreLinebreaks) { + peeked.push_back({it->second.id, t.content, + t.startColumn, t.startLine, + t.endColumn, t.endLine}); + } + return !ignoreLinebreaks; default: + bool empty = true; if (t.tokenId == TOKEN_TEXT) { int begin = -1; for (size_t c = 0; c < t.content.length(); c++) { @@ -86,20 +90,22 @@ bool CodeTokenizer::doPrepare(const Token &t, std::deque<Token> &peeked) t.startColumn + begin, t.startLine, t.startColumn + (int)c, t.endLine}); begin = -1; + empty = false; } } } - if(begin >= 0){ - peeked.push_back(Token{ - TOKEN_TEXT, - t.content.substr(begin), - t.startColumn + begin, t.startLine, - t.endColumn, t.endLine}); + if (begin >= 0) { + peeked.push_back( + Token{TOKEN_TEXT, t.content.substr(begin), + t.startColumn + begin, t.startLine, + t.endColumn, t.endLine}); + empty = false; } } else { + empty = false; peeked.push_back(t); } - return true; + return !empty; } startToken = t; returnTokenId = it->second.id; diff --git a/src/core/CodeTokenizer.hpp b/src/core/CodeTokenizer.hpp index 247918e..43c7abb 100644 --- a/src/core/CodeTokenizer.hpp +++ b/src/core/CodeTokenizer.hpp @@ -101,6 +101,10 @@ public: * true. */ bool ignoreComments = false; + /** + * If you do not want linebreaks to be returned you can set this to true. + */ + bool ignoreLinebreaks = false; /** * |