Clean up reflection a bit, and how we do pretty printing of ast nodes. Registered new internal_to_string in reflection module so that we
can have automatic pretty printing of ast nodes during repl eval.
This commit is contained in:
parent
054179ead3
commit
cfa42158af
@ -90,6 +90,25 @@ namespace chaiscript
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prints the contents of an AST node, including its children, recursively
|
||||
*/
|
||||
std::string to_string(std::string prepend = "") {
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << prepend << "(" << ast_node_type_to_string(this->identifier) << ") "
|
||||
<< this->text << " : " << this->start.line << ", " << this->start.column << std::endl;
|
||||
|
||||
for (unsigned int j = 0; j < this->children.size(); ++j) {
|
||||
oss << this->children[j]->to_string(prepend + " ");
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string internal_to_string() {
|
||||
return to_string();
|
||||
}
|
||||
|
||||
virtual Boxed_Value eval(Dispatch_Engine &) {
|
||||
Boxed_Value bv;
|
||||
throw std::runtime_error("Undispatched ast_node (internal error)");
|
||||
|
@ -538,17 +538,6 @@ namespace chaiscript
|
||||
return engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the contents of an AST node, including its children, recursively
|
||||
*/
|
||||
void debug_print(AST_NodePtr t, std::string prepend = "") {
|
||||
std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") "
|
||||
<< t->text << " : " << t->start.line << ", " << t->start.column << std::endl;
|
||||
for (unsigned int j = 0; j < t->children.size(); ++j) {
|
||||
debug_print(t->children[j], prepend + " ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for loading a file
|
||||
*/
|
||||
|
@ -103,19 +103,22 @@ namespace chaiscript
|
||||
/**
|
||||
* Prints the parsed ast_nodes as a tree
|
||||
*/
|
||||
/*
|
||||
void debug_print(AST_NodePtr t, std::string prepend = "") {
|
||||
std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl;
|
||||
for (unsigned int j = 0; j < t->children.size(); ++j) {
|
||||
debug_print(t->children[j], prepend + " ");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Shows the current stack of matched ast_nodes
|
||||
*/
|
||||
void show_match_stack() {
|
||||
for (unsigned int i = 0; i < match_stack.size(); ++i) {
|
||||
debug_print(match_stack[i]);
|
||||
//debug_print(match_stack[i]);
|
||||
std::cout << match_stack[i]->to_string();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect
|
||||
((filename))
|
||||
((start))
|
||||
((end))
|
||||
((internal_to_string))
|
||||
((children))
|
||||
);
|
||||
|
||||
@ -33,7 +34,6 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect
|
||||
(chaiscript::ChaiScript_Parser ()),
|
||||
((parse))
|
||||
((ast))
|
||||
((show_match_stack))
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user