diff options
author | David Robillard <d@drobilla.net> | 2009-03-30 19:46:51 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-30 19:46:51 +0000 |
commit | b0a77c63d82a1b6e46f37c29e07a29047315cd63 (patch) | |
tree | 7212eaf55c44a5bbcc612198bbd0644a40176c4c /tuplr.cpp | |
parent | fdc794f5dc9de5b55fff71939ee4374ea38efa8f (diff) | |
download | resp-b0a77c63d82a1b6e46f37c29e07a29047315cd63.tar.gz resp-b0a77c63d82a1b6e46f37c29e07a29047315cd63.tar.bz2 resp-b0a77c63d82a1b6e46f37c29e07a29047315cd63.zip |
Add really primitive pretty printer.
git-svn-id: http://svn.drobilla.net/resp/tuplr@110 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'tuplr.cpp')
-rw-r--r-- | tuplr.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -192,8 +192,9 @@ print_usage(char* name, bool error) os << endl; os << " -h Display this help and exit" << endl; os << " -r Enter REPL after evaluating files" << endl; + os << " -p Pretty-print input only" << endl; os << " -e EXPRESSION Evaluate EXPRESSION" << endl; - os << " -o FILE Write assembly output to FILE" << endl; + os << " -o FILE Write output to FILE" << endl; return error ? 1 : 0; } @@ -216,6 +217,8 @@ main(int argc, char** argv) files.push_back(argv[i]); } else if (!strncmp(argv[i], "-r", 3)) { args.insert(make_pair(argv[i], "")); + } else if (!strncmp(argv[i], "-p", 3)) { + args.insert(make_pair(argv[i], "")); } else if (i == argc-1 || argv[i+1][0] == '-') { return print_usage(argv[0], true); } else { @@ -225,7 +228,25 @@ main(int argc, char** argv) } int ret = 0; - map<string,string>::iterator a = args.find("-e"); + + string output; + map<string,string>::const_iterator a = args.find("-o"); + if (a != args.end()) + output = a->second; + + a = args.find("-p"); + if (a != args.end()) { + ifstream is(files.front().c_str()); + if (is.good()) { + Cursor loc; + SExp exp = readExpression(loc, is); + AST* ast = penv.parse(exp); + pprint(cout, ast); + } + return 0; + } + + a = args.find("-e"); if (a != args.end()) { istringstream is(a->second); ret = eval(*cenv, "(command line)", is); @@ -245,9 +266,8 @@ main(int argc, char** argv) if (args.find("-r") != args.end() || (files.empty() && args.find("-e") == args.end())) ret = repl(*cenv); - a = args.find("-o"); - if (a != args.end()) { - ofstream os(a->second.c_str()); + if (output != "") { + ofstream os(output.c_str()); if (os.good()) { cenv->write(os); } else { |