From 677fef1c09eddc56d13b1f500399efc862cab209 Mon Sep 17 00:00:00 2001 From: sbrandt Date: Mon, 29 Jul 2013 16:14:18 +0000 Subject: Make the --python flag work. git-svn-id: http://svn.cactuscode.org/flesh/trunk@5037 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/piraha/Generic.cc | 9 ++++++++- src/piraha/Group.cc | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/piraha/Piraha.hpp | 2 ++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/piraha/Generic.cc b/src/piraha/Generic.cc index 21012a85..d9b3f84b 100644 --- a/src/piraha/Generic.cc +++ b/src/piraha/Generic.cc @@ -17,7 +17,7 @@ void read_file(const char *file,std::string& buf) { } void usage() { - std::cerr << "usage: generic [--perl] grammar input" << std::endl; + std::cerr << "usage: generic [--perl|--python] grammar input" << std::endl; exit(2); } @@ -50,6 +50,7 @@ bool newEnd(std::string& in,const char *new_end,std::string& out) { int main(int argc,char **argv) { std::string grammarArg, inputArg; bool perlFlag = false; + bool pythonFlag = false; bool oFlag = false; std::string outFile; int narg = 0; @@ -57,6 +58,8 @@ int main(int argc,char **argv) { std::string arg = argv[n]; if(arg == "--perl") { perlFlag = true; + } else if(arg == "--python") { + pythonFlag = true; } else if(arg == "-o") { outFile = argv[++n]; oFlag = true; @@ -76,6 +79,8 @@ int main(int argc,char **argv) { if(!oFlag) { if(perlFlag) { newEnd(inputArg,".pm",outFile); + } else if(pythonFlag) { + newEnd(inputArg,".py",outFile); } else { newEnd(inputArg,".pegout",outFile); } @@ -101,6 +106,8 @@ int main(int argc,char **argv) { mg->children.push_back(src_file); if(perlFlag) { mg->dumpPerl(o); + } else if(pythonFlag) { + mg->dumpPython(o); } else { mg->dump(o); } diff --git a/src/piraha/Group.cc b/src/piraha/Group.cc index 11e1ac61..c236bf4c 100644 --- a/src/piraha/Group.cc +++ b/src/piraha/Group.cc @@ -80,6 +80,60 @@ void Group::dumpPerl(std::ostream &o,int indent) { o << "}" << std::endl; } +void Group::dumpPython(std::ostream& o) { + o << "VAR = "; + dumpPython(o,0); +} +void Group::dumpPython(std::ostream &o,int indent) { + for(int i=0;i >::iterator group_iter; + for(group_iter gi = children.begin(); + gi != children.end(); + ++gi) { + (*gi)->dumpPython(o,indent+2); + for(int i=0;i group(int i) { return children[i]; } smart_ptr group(const char *nm,int ix=0) { -- cgit v1.2.3