File: phptest.cpp

package info (click to toggle)
kdevelop-pg-qt 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,284 kB
  • sloc: cpp: 22,743; lex: 928; ansic: 716; yacc: 615; ruby: 68; sh: 14; lisp: 10; fortran: 6; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,734 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "phplexer.h"
#include "phpparser.h"
#include "phptokentext.h"
#include "phpdebugvisitor.h"

using namespace Php;
using namespace KDevPG;

#include <iostream>
using namespace std;

int main()
{
  qDebug() << "eevl";
  string str;
  while(true)
  {
    string strr;
    getline(cin, strr);
    if(!strr.size())
      break;
    str += strr + "\n";
  }
//   QString qcode(QByteArray(str.c_str(), str.size()));
//   QStringIterator iter(qcode);
  QByteArray qcode(str.c_str(), str.size());
  QByteArrayIterator iter(qcode);
  qDebug() << qcode.size() << iter.hasNext();
  Php::TokenStream lex(iter);
  Php::Parser parser;
  KDevPG::MemoryPool pool;
  parser.setTokenStream(&lex);
  parser.setMemoryPool(&pool);
//   int kind;
//   while((kind = lex.advance().kind) != Parser::Token_EOF)
//   {
//     cout << tokenText(kind).toStdString() << endl;
  //   }
  Php::StartAst *root = 0;
  try
  {
    lex.rewind(0);
    parser.yylex();
    cout << "Parse: " << parser.parseStart(&root) << endl;
    qDebug() << root->statementsSequence;
    qDebug() << root->statementsSequence->element;
  //   cout << tokenText(lex.front().kind).toStdString() << endl;
  //   cout << tokenText(lex.curr().kind).toStdString() << endl;
  //   cout << tokenText(lex.back().kind).toStdString() << endl;
  }
  catch(...)
  {
    cout << "ERROR!!" << endl;
  }
  lex.rewind(0);
  cout << "blub" << endl;
  Php::DebugVisitor vis(&lex, QString::fromUtf8(qcode));
  vis.visitStart(root);
  while(true)
  {
    auto t = lex.curr();
    lex.read();
    cout << t.begin << ".." << t.end << tokenText(t.kind).toStdString() << ": " << qcode.mid(t.begin, t.end - t.begin + 1).data() << endl << "---" << endl;
    if(lex.index() == lex.size())
      break;
  }
}