aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPetteri Räty <petsku@petteriraty.eu>2011-06-25 13:26:05 +0300
committerPetteri Räty <petsku@petteriraty.eu>2011-06-25 13:26:05 +0300
commita0f1ce8a10a50a732a9aaec80a51df8f72120c78 (patch)
tree562072913ba113a4eeaef94a9eb3bded9f2a2453 /utils
parentMerge remote-tracking branch 'mu/break_builtin' (diff)
parentWalker: support arithmetic expression (diff)
downloadlibbash-a0f1ce8a10a50a732a9aaec80a51df8f72120c78.tar.gz
libbash-a0f1ce8a10a50a732a9aaec80a51df8f72120c78.tar.bz2
libbash-a0f1ce8a10a50a732a9aaec80a51df8f72120c78.zip
Merge remote-tracking branch 'mu/fix_arithmetic'
Diffstat (limited to 'utils')
-rw-r--r--utils/ast_printer.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/utils/ast_printer.cpp b/utils/ast_printer.cpp
index 9c4bc3d..4921fa8 100644
--- a/utils/ast_printer.cpp
+++ b/utils/ast_printer.cpp
@@ -84,9 +84,9 @@ static bool build_token_map(std::unordered_map<ANTLR3_INT32, std::string>& token
return qi::parse(first, last, line % qi::eol >> qi::eol, token_map) && first == last;
}
-static void print_token(std::istream& input,
- const std::string& token_path,
- bool silent)
+static void print_parser_token(std::istream& input,
+ const std::string& token_path,
+ bool silent)
{
if(silent)
return;
@@ -95,9 +95,28 @@ static void print_token(std::istream& input,
std::unordered_map<ANTLR3_INT32, std::string> token_map;
if(build_token_map(token_map, token_path))
- std::cout << ast.get_tokens(std::bind(&token_mapper,
- token_map,
- std::placeholders::_1))
+ std::cout << ast.get_parser_tokens(std::bind(&token_mapper,
+ token_map,
+ std::placeholders::_1))
+ << std::endl;
+ else
+ std::cerr << "Building token map failed" << std::endl;
+}
+
+static void print_walker_token(std::istream& input,
+ const std::string& token_path,
+ bool silent)
+{
+ if(silent)
+ return;
+
+ bash_ast ast(input);
+ std::unordered_map<ANTLR3_INT32, std::string> token_map;
+
+ if(build_token_map(token_map, token_path))
+ std::cout << ast.get_walker_tokens(std::bind(&token_mapper,
+ token_map,
+ std::placeholders::_1))
<< std::endl;
else
std::cerr << "Building token map failed" << std::endl;
@@ -144,6 +163,8 @@ int main(int argc, char** argv)
("dot,d", "print graphviz doc file instead of tree string if -s is not specified")
("token,t", po::value<std::string>(), "Print all tokens instead of AST. "
"The argument is the path to libbash.tokens")
+ ("walker-token,w", po::value<std::string>(), "Print all tokens received by the walker. "
+ "The argument is the path to libbashWalker.tokens")
("name,n", "When using files as input scripts, print out file names")
("silent,s", "do not print any AST")
;
@@ -160,10 +181,15 @@ int main(int argc, char** argv)
std::function<void(std::istream&)> printer;
if(vm.count("token"))
- printer = std::bind(&print_token,
+ printer = std::bind(&print_parser_token,
std::placeholders::_1,
vm["token"].as<std::string>(),
vm.count("silent"));
+ else if(vm.count("walker-token"))
+ printer = std::bind(&print_walker_token,
+ std::placeholders::_1,
+ vm["walker-token"].as<std::string>(),
+ vm.count("silent"));
else
printer = std::bind(&print_ast,
std::placeholders::_1,