From c85705a2397c611f86332f33e05dd9d115f710f8 Mon Sep 17 00:00:00 2001
From: Honza <honza@Pinguino.zoo>
Date: Sun, 8 Dec 2013 19:46:09 +0100
Subject: [PATCH] feature: Rules can be printed to ostream

---
 alib/src/grammar/Rule.cpp | 24 ++++++++++++++++++++++++
 alib/src/grammar/Rule.h   |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/alib/src/grammar/Rule.cpp b/alib/src/grammar/Rule.cpp
index 8113b2ca37..6aa296a25f 100644
--- a/alib/src/grammar/Rule.cpp
+++ b/alib/src/grammar/Rule.cpp
@@ -102,4 +102,28 @@ bool Rule::operator !=(const Rule& other) const {
 			|| !equal(rightSide.begin(), rightSide.end(), other.rightSide.begin());
 }
 
+std::ostream& operator<<(std::ostream& out, const Rule& rule) {
+	bool first;
+	out << " leftSide = [";
+
+	first = true;
+	for(list<Symbol>::const_iterator iter = rule.leftSide.begin(); iter != rule.leftSide.end(); iter++) {
+		if(!first) out << ", ";
+		first = false;
+		out << *iter;
+	}
+
+	out << "] rightSize = [";
+
+	first = true;
+	for(list<Symbol>::const_iterator iter = rule.rightSide.begin(); iter != rule.rightSide.end(); iter++) {
+		if(!first) out << ", ";
+		first = false;
+		out << *iter;
+	}
+	out << "]";
+
+	return out;
+}
+
 } /* namespace grammar */
diff --git a/alib/src/grammar/Rule.h b/alib/src/grammar/Rule.h
index 1395dc2fef..ab2235a836 100644
--- a/alib/src/grammar/Rule.h
+++ b/alib/src/grammar/Rule.h
@@ -65,6 +65,8 @@ public:
 	bool operator <(const Rule& other) const;
 	bool operator ==(const Rule& other) const;
 	bool operator !=(const Rule& other) const;
+
+	friend std::ostream& operator<<(std::ostream&, const Rule&);
 };
 
 } /* namespace grammar */
-- 
GitLab