Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Highlighting now takes place again

  • Loading branch information...
commit 0b894ee1fd3afb23e65bafdf66ea30394d3049f9 1 parent f3f2c2f
@scummos authored
View
2  CMakeLists.txt
@@ -55,4 +55,4 @@ target_link_libraries(kdevpythonlanguagesupport
install(TARGETS kdevpythonlanguagesupport DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kdevpythonsupport.desktop DESTINATION ${SERVICES_INSTALL_DIR})
-install(FILES pythonpythonparser.py DESTINATION ${LIB_INSTALL_DIR})
+install(FILES pythonpythonparser.py DESTINATION ${BIN_INSTALL_DIR})
View
1  parser/CMakeLists.txt
@@ -8,6 +8,7 @@ set(parser_STAT_SRCS
astdefaultvisitor.cpp
astvisitor.cpp
astbuilder.cpp
+ pythondriver.cpp
)
# kdevpgqt_generate(_kdevpgList python NAMESPACE PythonParser
View
18 parser/astbuilder.cpp
@@ -31,6 +31,7 @@
#include "kurl.h"
#include <qxmlstream.h>
#include <QXmlStreamReader>
+#include <qdir.h>
namespace Python
{
@@ -45,7 +46,8 @@ QString AstBuilder::getXmlForFile(KUrl filename)
{
QProcess* parser = new QProcess();
// we call a python script to parse the code for us. It returns an XML string with the AST
- parser->start("./pythonpythonparser.py", QStringList(filename.path())); // TODO fix this
+ kDebug() << QDir::current();
+ parser->start("/usr/bin/env", QStringList() << "python" << "/home/sven/projects/compiled/kde4/bin/pythonpythonparser.py" << filename.path());
parser->waitForFinished();
// TODO this is not clean
@@ -62,6 +64,8 @@ QString AstBuilder::getXmlForFile(KUrl filename)
CodeAst* AstBuilder::parseXmlAst(QString xml)
{
+ Q_ASSERT(xml.length());
+
QXmlStreamReader* xmlast = new QXmlStreamReader();
xmlast->addData(xml);
@@ -72,8 +76,7 @@ CodeAst* AstBuilder::parseXmlAst(QString xml)
populateAst();
CodeAst* codeAst = dynamic_cast<CodeAst*>(m_currentNode);
- if ( ! codeAst )
- Q_ASSERT(codeAst);
+ Q_ASSERT(codeAst);
return codeAst;
}
@@ -242,6 +245,7 @@ bool AstBuilder::parseAstNode(QString name, QString text, const QList< QXmlStrea
m_attributeStore.insert(node_id, attributeDict);
m_nodeStack.append(ast);
+ kDebug() << "Stack size: " << m_nodeStack.length();
return true;
}
@@ -685,8 +689,14 @@ void AstBuilder::populateAst()
currentAbstractNode->endLine = startLine;
int startCol = currentAttributes.value("col_offset").toInt();
currentAbstractNode->startCol = startCol;
- currentAbstractNode->endCol = startCol + 10; // TODO fix this ;p
+ currentAbstractNode->endCol = startCol + 100; // TODO fix this ;p
+ if ( ! currentAbstractNode->startLine && currentAbstractNode->parent ) {
+ currentAbstractNode->startLine = currentAbstractNode->parent->startLine;
+ currentAbstractNode->endLine = currentAbstractNode->parent->endLine;
+ currentAbstractNode->startCol = currentAbstractNode->parent->startCol;
+ currentAbstractNode->endCol = currentAbstractNode->parent->endCol;
+ }
switch ( currentAbstractNode->astType ) {
case Ast::CodeAstType: currentAbstractNode = populateCodeAst(currentAbstractNode, currentAttributes); break;
View
14 parser/parsesession.cpp
@@ -42,12 +42,12 @@ ParseSession::~ParseSession()
void ParseSession::setCurrentDocument(KUrl& filename)
{
- m_currentDocument = filename;
+ m_currentDocument = KDevelop::IndexedString(filename);
}
IndexedString ParseSession::currentDocument()
{
- return KDevelop::IndexedString(m_currentDocument.fileName());
+ return m_currentDocument;
}
@@ -63,11 +63,11 @@ void ParseSession::setContents( const QString& contents )
QPair<CodeAst*, bool> ParseSession::parse( Python::CodeAst* ast )
{
- AstBuilder parser;
- ast = parser.parse(m_currentDocument);
- if ( ! ast )
- Q_ASSERT(false);
- return QPair<CodeAst*, bool>(ast, true);
+ Driver driver;
+ driver.setCurrentDocument(m_currentDocument.toUrl());
+ QPair<CodeAst*, bool> result = driver.parse(ast);
+ Q_ASSERT(result.first);
+ return result;
}
}
View
2  parser/parsesession.h
@@ -64,7 +64,7 @@ class KDEVPYTHONPARSER_EXPORT ParseSession
private:
QString m_contents;
- KUrl m_currentDocument;
+ KDevelop::IndexedString m_currentDocument;
};
View
40 parser/pythondriver.cpp
@@ -60,41 +60,23 @@ void Driver::setDebug( bool debug )
m_debug = debug;
}
-bool Driver::parse( Python::CodeAst** ast )
+void Driver::setCurrentDocument(KUrl url)
{
- if(!m_tokenstream)
- m_tokenstream = new KDevPG::TokenStream();
- if(!m_pool)
- m_pool = new KDevPG::MemoryPool();
-
- PythonParser::Parser pythonparser;
- pythonparser.setTokenStream( m_tokenstream );
- pythonparser.setMemoryPool( m_pool );
- pythonparser.setDebug( m_debug );
+ m_currentDocument = url;
+}
- pythonparser.tokenize(m_content);
- PythonParser::ProjectAst* srcast;
- bool matched = pythonparser.parseProject( &srcast );
- if( matched )
+QPair<CodeAst*, bool> Driver::parse( Python::CodeAst* ast )
+{
+ AstBuilder pythonparser;
+ QPair<CodeAst*, bool> matched;
+ matched.first = pythonparser.parse( m_currentDocument );
+ matched.second = true; // TODO fix this
+ if( matched.second )
{
kDebug() << "Sucessfully parsed";
-// if( m_debug )
-// {
-// PythonParser::DebugVisitor d( pythonparser.tokenStream );
-// d.visitProject(*srcast);
-// }
- Python::AstBuilder builder(&pythonparser);
- builder.visitProject( srcast );
- for ( int i=0; i < builder.mNodeStack.count(); i++ ) {
- Ast* dbg_node = builder.mNodeStack.at(i);
- kDebug() << dbg_node;
- }
- *ast = builder.codeAst();
-
}else
{
- *ast = 0;
- pythonparser.expectedSymbol(PythonParser::AstNode::ProjectKind, "project");
+ matched.first = 0;
kDebug() << "Couldn't parse content";
}
return matched;
View
6 parser/pythondriver.h
@@ -23,6 +23,7 @@
#include <QtCore/QString>
#include "parserexport.h"
+#include <kurl.h>
namespace KDevPG
{
class MemoryPool;
@@ -45,15 +46,16 @@ class KDEVPYTHONPARSER_EXPORT Driver
bool readFile( const QString&, const char* = 0 );
void setContent( const QString& );
void setDebug( bool );
- bool parse( Python::CodeAst** ast );
+ QPair<CodeAst*, bool> parse( Python::CodeAst* ast );
void setTokenStream( KDevPG::TokenStream* );
void setMemoryPool( KDevPG::MemoryPool* );
+ void setCurrentDocument(KUrl url);
private:
QString m_content;
bool m_debug;
KDevPG::MemoryPool* m_pool;
KDevPG::TokenStream* m_tokenstream;
-
+ KUrl m_currentDocument;
};
}
View
1  pythonhighlighting.h
@@ -38,7 +38,6 @@ class Highlighting : public KDevelop::CodeHighlighting
Q_OBJECT
public:
Highlighting( QObject* parent );
-
};
}
View
11 pythonparsejob.cpp
@@ -49,6 +49,10 @@
#include "usebuilder.h"
// #include "astprinter.h"
// #include "usebuilder.h"
+#include <language/highlighting/codehighlighting.h>
+#include <interfaces/icore.h>
+#include <interfaces/ilanguagecontroller.h>
+
using namespace KDevelop;
@@ -107,6 +111,9 @@ void ParseJob::run()
m_session->setContents( QString::fromUtf8(contents().contents) + "\n" );
m_session->setCurrentDocument(m_url);
+ IndexedString test(m_url);
+ kDebug() << m_url.toLocalFile();
+
if ( abortRequested() )
return abortJob();
@@ -138,7 +145,7 @@ void ParseJob::run()
usebuilder.buildUses(m_ast);
kDebug() << "----Parsing Succeded---***";
-
+
// {
// DUChainReadLocker lock( DUChain::lock() );
// DumpChain dump;
@@ -148,7 +155,7 @@ void ParseJob::run()
{
if ( m_parent && m_parent->codeHighlighting() ) {
kDebug() << m_duContext.data();
-// DUChainReadLocker lock(DUChain::lock());
+ DUChainReadLocker lock(DUChain::lock());
KDevelop::ICodeHighlighting* hl = m_parent->codeHighlighting();
hl->highlightDUChain(m_duContext);
}
Please sign in to comment.
Something went wrong with that request. Please try again.