Changeset View
Changeset View
Standalone View
Standalone View
support/xhpast/xhpast.cpp
| #include "ast.hpp" | #include "ast.hpp" | ||||
| #include <iostream> | #include <iostream> | ||||
| #include <sstream> | #include <sstream> | ||||
| #include <fstream> | #include <fstream> | ||||
| using namespace std; | using namespace std; | ||||
| int xhpastparse(void*, xhpast::Node **); | int xhpastparse(void *, xhpast::Node **); | ||||
| int xhpast_process(std::string &in); | int xhpast_process(std::string &in); | ||||
| void print_node(xhpast::Node *node); | void print_node(xhpast::Node * node); | ||||
| int main(int argc, char* argv[]) { | int main(int argc, char * argv[]) { | ||||
| if (argc != 1) { | if (argc != 1) { | ||||
| // Coupling: modify also src/parser/xhpast/bin/PhutilXHPASTBinary.php | // Coupling: modify also src/parser/xhpast/bin/PhutilXHPASTBinary.php | ||||
| cout << "5.7.2\n"; | cout << "5.7.2\n"; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| ifstream inputFile; | ifstream inputFile; | ||||
| istream *inputStream; | istream * inputStream; | ||||
| inputStream = &cin; | inputStream = &cin; | ||||
| std::stringbuf sb; | std::stringbuf sb; | ||||
| *inputStream >> noskipws >> &sb; | *inputStream >> noskipws >> &sb; | ||||
| std::string buffer = sb.str(); | std::string buffer = sb.str(); | ||||
| inputFile.close(); | inputFile.close(); | ||||
| return xhpast_process(buffer); | return xhpast_process(buffer); | ||||
| } | } | ||||
| int xhpast_process(std::string &in) { | int xhpast_process(std::string &in) { | ||||
| char *buffer; | char * buffer; | ||||
| in.reserve(in.size() + 1); | in.reserve(in.size() + 1); | ||||
| buffer = const_cast<char*>(in.c_str()); | buffer = const_cast<char *>(in.c_str()); | ||||
| buffer[in.size() + 1] = 0; // need double NULL for scan_buffer | buffer[in.size() + 1] = 0; // need double NULL for scan_buffer | ||||
| void* scanner; | void * scanner; | ||||
| yy_extra_type extra; | yy_extra_type extra; | ||||
| extra.idx_expr = true;//flags.idx_expr; | extra.idx_expr = true;//flags.idx_expr; | ||||
| extra.insert_token = 0;//flags.eval ? T_OPEN_TAG_FAKE : 0; | extra.insert_token = 0;//flags.eval ? T_OPEN_TAG_FAKE : 0; | ||||
| extra.short_tags = true;//flags.short_tags; | extra.short_tags = true;//flags.short_tags; | ||||
| extra.asp_tags = false;//flags.asp_tags; | extra.asp_tags = false;//flags.asp_tags; | ||||
| xhpast::Node *root = NULL; | xhpast::Node * root = NULL; | ||||
| xhpastlex_init(&scanner); | xhpastlex_init(&scanner); | ||||
| xhpastset_extra(&extra, scanner); | xhpastset_extra(&extra, scanner); | ||||
| xhpast_scan_buffer(buffer, in.size() + 2, scanner); | xhpast_scan_buffer(buffer, in.size() + 2, scanner); | ||||
| xhpastparse(scanner, &root); | xhpastparse(scanner, &root); | ||||
| xhpastlex_destroy(scanner); | xhpastlex_destroy(scanner); | ||||
| if (extra.terminated) { | if (extra.terminated) { | ||||
| Show All 32 Lines | if (!extra.token_list.empty()) { | ||||
| } | } | ||||
| } | } | ||||
| printf("]"); | printf("]"); | ||||
| printf("}\n"); | printf("}\n"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| void print_node(xhpast::Node *node) { | void print_node(xhpast::Node * node) { | ||||
| int l = -1; | int l = -1; | ||||
| if (node->l_tok != -1) { | if (node->l_tok != -1) { | ||||
| l = node->l_tok; | l = node->l_tok; | ||||
| } | } | ||||
| if (l == -1) { | if (l == -1) { | ||||
| printf("[%u]", node->type); | printf("[%u]", node->type); | ||||
| } else { | } else { | ||||
| Show All 22 Lines | |||||