From 0efe8110e49efd9f61c89868663de851938570e7 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sun, 8 Feb 2015 23:02:24 -0500 Subject: [PATCH] Changed to use SemanticValues instead of SemanticStack. --- peglib.h | 153 +++++++++++++++++++++++++------------------------------ 1 file changed, 70 insertions(+), 83 deletions(-) diff --git a/peglib.h b/peglib.h index 8acd0e2..8dc3e04 100644 --- a/peglib.h +++ b/peglib.h @@ -325,7 +325,7 @@ template struct SemanticActions; template -struct SemanticStack; +struct SemanticValues; /* * Match @@ -373,7 +373,7 @@ public: Sequence(std::vector>&& rules) : rules_(std::move(rules)) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::vector> rules_; @@ -402,7 +402,7 @@ public: PrioritizedChoice(std::vector>&& rules) : rules_(std::move(rules)) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::vector> rules_; @@ -414,7 +414,7 @@ public: ZeroOrMore(const std::shared_ptr& rule) : rule_(rule) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::shared_ptr rule_; @@ -426,7 +426,7 @@ public: OneOrMore(const std::shared_ptr& rule) : rule_(rule) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::shared_ptr rule_; @@ -438,7 +438,7 @@ public: Option(const std::shared_ptr& rule) : rule_(rule) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::shared_ptr rule_; @@ -450,7 +450,7 @@ public: AndPredicate(const std::shared_ptr& rule) : rule_(rule) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::shared_ptr rule_; @@ -462,7 +462,7 @@ public: NotPredicate(const std::shared_ptr& rule) : rule_(rule) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::shared_ptr rule_; @@ -474,7 +474,7 @@ public: LiteralString(const char* s) : lit_(s) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const { + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const { auto i = 0u; for (; i < lit_.size(); i++) { if (i >= l || s[i] != lit_[i]) { @@ -494,7 +494,7 @@ public: CharacterClass(const char* chars) : chars_(chars) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const { + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const { if (l < 1) { return fail(); } @@ -526,7 +526,7 @@ public: Character(char ch) : ch_(ch) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const { + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const { if (l < 1 || s[0] != ch_) { return fail(); } @@ -541,7 +541,7 @@ class AnyCharacter { public: template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const { + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const { if (l < 1) { return fail(); } @@ -555,7 +555,7 @@ public: Grouping(const std::shared_ptr& rule) : rule_(rule) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::shared_ptr rule_; @@ -567,14 +567,11 @@ public: NonTerminal(Definition* outer) : outer_(outer) {}; template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: friend class Definition; - template - void reduce(SemanticStack& ss, const char* s, size_t l, Action action) const; - template T reduce(const char* s, size_t l, const std::vector& v, const std::vector& n, Action action) const; @@ -591,7 +588,7 @@ public: , name_(name) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: const std::map& grammar_; @@ -604,7 +601,7 @@ public: WeakHolder(const std::shared_ptr& rule) : weak_(rule) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const; + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const; private: std::weak_ptr weak_; @@ -624,23 +621,23 @@ public: TRule(T&& val) : vt(std::move(val)) {} template - Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticStack* ss) const { + Match parse(const char* s, size_t l, const SemanticActions* sa, SemanticValues* sv) const { switch (vt.type_index) { - case 0: return vt.template get().template parse(s, l, sa, ss); - case 1: return vt.template get().template parse(s, l, sa, ss); - case 2: return vt.template get().template parse(s, l, sa, ss); - case 3: return vt.template get().template parse(s, l, sa, ss); - case 4: return vt.template get