summaryrefslogtreecommitdiff
path: root/src/piraha/Group.cc
diff options
context:
space:
mode:
authorsbrandt <sbrandt@17b73243-c579-4c4c-a9d2-2d5706c11dac>2013-04-03 19:12:46 +0000
committersbrandt <sbrandt@17b73243-c579-4c4c-a9d2-2d5706c11dac>2013-04-03 19:12:46 +0000
commita3cb4c5d02f0ee75094fc27814c71f8a025d034b (patch)
tree1dd1af38bf8ad0318f07dd2c8ae00216e942efb0 /src/piraha/Group.cc
parent069e8f1d570cc373c843673be0acf7bc4dd10b6e (diff)
Add the basic grammar files, and the changes
to the piraha code necessary to parse all of Cactus. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4990 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/piraha/Group.cc')
-rw-r--r--src/piraha/Group.cc73
1 files changed, 67 insertions, 6 deletions
diff --git a/src/piraha/Group.cc b/src/piraha/Group.cc
index 544e12be..95079800 100644
--- a/src/piraha/Group.cc
+++ b/src/piraha/Group.cc
@@ -2,22 +2,83 @@
using namespace piraha;
-void Group::dump(int indent) {
+void Group::dump(std::ostream& o) {
+ dump(-1,o,0);
+}
+void Group::dump(int n,std::ostream& o,int indent) {
for(int i=0;i<indent;i++)
- std::cout << ' ';
- std::cout << pattern << ": ";
+ o << ' ';
+ if(n >= 0) {
+ o << "[" << n << "] ";
+ }
+ o << pattern << ": ";
if(children.size()==0) {
for(int i=start_;i<end_;i++)
- std::cout << input[i];
+ o << input[i];
}
- std::cout << std::endl;
+ o << std::endl;
typedef vector<smart_ptr<Group> >::iterator group_iter;
+ int nn = 0;
for(group_iter gi = children.begin();
gi != children.end();
++gi) {
- (*gi)->dump(indent+2);
+ (*gi)->dump(nn++,o,indent+2);
}
}
+void Group::dumpPerl(std::ostream& o) {
+ o << "$VAR = ";
+ dumpPerl(o,0);
+ o << ";" << std::endl;
+}
+void Group::dumpPerl(std::ostream &o,int indent) {
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "{" << std::endl;
+ indent += 2;
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "name=> \"" << getPatternName() << "\"," << std::endl;
+ if(children.size()==0) {
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "children=>[]," << std::endl;
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "text=>\"";
+ for(int i=start_;i<end_;i++)
+ insertc(o,input[i]);
+ o << "\"," << std::endl;
+ } else {
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "children=>[" << std::endl;
+ typedef vector<smart_ptr<Group> >::iterator group_iter;
+ for(group_iter gi = children.begin();
+ gi != children.end();
+ ++gi) {
+ (*gi)->dumpPerl(o,indent+2);
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "," << std::endl;
+ }
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "]," << std::endl;
+ }
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "start=>" << start() << "," << std::endl;
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "end=>" << end() << "," << std::endl;
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "line=>" << line() << "," << std::endl;
+ indent -= 2;
+ for(int i=0;i<indent;i++)
+ o << ' ';
+ o << "}" << std::endl;
+}
std::string Group::substring() {
std::string sub;