File indexing completed on 2024-04-28 04:36:08

0001 #include "phplexer.h"
0002 #include "phpparser.h"
0003 #include "phptokentext.h"
0004 #include "phpdebugvisitor.h"
0005 
0006 using namespace Php;
0007 using namespace KDevPG;
0008 
0009 #include <iostream>
0010 using namespace std;
0011 
0012 int main()
0013 {
0014   qDebug() << "eevl";
0015   string str;
0016   while(true)
0017   {
0018     string strr;
0019     getline(cin, strr);
0020     if(!strr.size())
0021       break;
0022     str += strr + "\n";
0023   }
0024 //   QString qcode(QByteArray(str.c_str(), str.size()));
0025 //   QStringIterator iter(qcode);
0026   QByteArray qcode(str.c_str(), str.size());
0027   QByteArrayIterator iter(qcode);
0028   qDebug() << qcode.size() << iter.hasNext();
0029   Php::TokenStream lex(iter);
0030   Php::Parser parser;
0031   KDevPG::MemoryPool pool;
0032   parser.setTokenStream(&lex);
0033   parser.setMemoryPool(&pool);
0034 //   int kind;
0035 //   while((kind = lex.advance().kind) != Parser::Token_EOF)
0036 //   {
0037 //     cout << tokenText(kind).toStdString() << endl;
0038   //   }
0039   Php::StartAst *root = 0;
0040   try
0041   {
0042     lex.rewind(0);
0043     parser.yylex();
0044     cout << "Parse: " << parser.parseStart(&root) << endl;
0045     qDebug() << root->statementsSequence;
0046     qDebug() << root->statementsSequence->element;
0047   //   cout << tokenText(lex.front().kind).toStdString() << endl;
0048   //   cout << tokenText(lex.curr().kind).toStdString() << endl;
0049   //   cout << tokenText(lex.back().kind).toStdString() << endl;
0050   }
0051   catch(...)
0052   {
0053     cout << "ERROR!!" << endl;
0054   }
0055   lex.rewind(0);
0056   cout << "blub" << endl;
0057   Php::DebugVisitor vis(&lex, QString(qcode));
0058   vis.visitStart(root);
0059   forever
0060   {
0061     auto t = lex.curr();
0062     lex.read();
0063     cout << t.begin << ".." << t.end << tokenText(t.kind).toStdString() << ": " << qcode.mid(t.begin, t.end - t.begin + 1).data() << endl << "---" << endl;
0064     if(lex.index() == lex.size())
0065       break;
0066   }
0067 }