Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
-----------------------------------------------------------------------------
This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems)
For the latest info, see http://www.ostis.net

Copyright (c) 2010 OSTIS

OSTIS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OSTIS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OSTIS. If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------
*/

#include "scsmultilinehighlightingrule.h"

SCsMultiLinetHighlightingRule::SCsMultiLinetHighlightingRule(QRegExp start, QRegExp end, QTextCharFormat format, BlockRuleState state)
Expand All @@ -12,7 +34,7 @@ void SCsMultiLinetHighlightingRule::assignFormat(SCsSyntaxHighlighter *highlight
{

int state = highlighter->curBlockState();
if(state>0 && state!= mState )
if (state>0 && state!= mState )
return;

highlighter->setCurBlockState(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
-----------------------------------------------------------------------------
This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems)
For the latest info, see http://www.ostis.net

Copyright (c) 2010 OSTIS

OSTIS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OSTIS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OSTIS. If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------
*/

#ifndef SCSMULTILINEHIGHLIGHTINGRULE_H
#define SCSMULTILINEHIGHLIGHTINGRULE_H

Expand Down
2 changes: 2 additions & 0 deletions sources/plugins/scs/scs.pro
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ HEADERS += \
scsparser/SCsCLexer.h \
scsparser/SCsCParser.h \
scsparser/scscparserdefs.h \
scsparser/scsasynchparser.h \
scswindow.h \
scsplugin.h \
scscodeerroranalyzer.h \
Expand All @@ -63,6 +64,7 @@ SOURCES += \
scsparser/SCsCLexer.c \
scsparser/SCsCParser.c \
scsparser/scscparserdefs.c \
scsparser/scsasynchparser.cpp \
scswindow.cpp \
scserrortablewidget.cpp \
scscodeeditor.cpp \
Expand Down
92 changes: 69 additions & 23 deletions sources/plugins/scs/scscodeanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,36 @@ along with OSTIS. If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------
*/



#include "scscodeanalyzer.h"
#include <QFile>
#include <QTextStream>
#include <QFileInfo>
#include <QDir>
#include <QStandardItemModel>
#include <QFileSystemWatcher>

#include <limits>

#include "scsparserwrapper.h"
#include "scsasynchparser.h"

#include <QStandardItemModel>

const QRegExp SCsCodeAnalyzer::msIdentifierExp("([A-Za-z0-9_.#]+)");


SCsCodeAnalyzer::SCsCodeAnalyzer(QObject *parent) :
QObject(parent)
QObject(parent)
, mUpdateModel(0)
, mAsynchParser(0)
, mIsBusy(false)
{

mAsynchParser = new SCsAsynchParser(this);
connect(mAsynchParser,SIGNAL(parseIdentifiersFinished()),SLOT(asynchUpdateExtractIdftFinished()));
}


void SCsCodeAnalyzer::fillModel(QStandardItemModel *model)
void SCsCodeAnalyzer::fillModel(QStandardItemModel *model, const QSet<QString> &idtfs)
{
model->clear();
Q_CHECK_PTR(model);

QSet<QString> identifiers = mDocumentIdentifiers;
if (!model)
return;

foreach(const QString &id, identifiers)
model->clear();

foreach (const QString &id, idtfs)
{
QStandardItem *item = new QStandardItem(id);
model->appendRow(item);
Expand All @@ -76,33 +75,80 @@ bool SCsCodeAnalyzer::isIdentifier(const QString &text)

void SCsCodeAnalyzer::update(const QString &text, QStandardItemModel *model)
{
extractIdentifiers(text, &mDocumentIdentifiers);
if (mIsBusy)
return;

extractIdentifiers(text, mDocumentIdentifiers);

mDocumentIdentifiers -= mIgnoreIdentifiers;

fillModel(model);
fillModel(model, mDocumentIdentifiers);

mIgnoreIdentifiers.clear();
}


void SCsCodeAnalyzer::asynchUpdate(const QString &text, QStandardItemModel *model)
{
if (mIsBusy)
return;

if (text.isEmpty())
return;

mIsBusy = true;

mUpdateModel = model;

mAsynchParser->parseIdentifiers(text);

}

void SCsCodeAnalyzer::parse(const QString &text, QStandardItemModel *model)
{
if (mIsBusy)
return;

if (text.isEmpty())
return;

mDocumentIdentifiers.clear();
mIgnoreIdentifiers.clear();

extractIdentifiers(text, &mDocumentIdentifiers);
extractIdentifiers(text, mDocumentIdentifiers);

fillModel(model);
fillModel(model, mDocumentIdentifiers);
}




void SCsCodeAnalyzer::extractIdentifiers(const QString &text, QSet<QString> *identifiers)
void SCsCodeAnalyzer::extractIdentifiers(const QString &text, QSet<QString> &identifiers)
{
SCsParser parser;

*identifiers = parser.getIdentifier(text);
QSharedPointer<SCsParserIdtfArray> idtf = parser.getIdentifier(text);

identifiers = *idtf;
}


void SCsCodeAnalyzer::asynchUpdateExtractIdftFinished()
{
Q_ASSERT(mAsynchParser->isParseIdentifiersResultPresent());

if (!mAsynchParser->isParseIdentifiersResultPresent())
return;

QSharedPointer<SCsParserIdtfArray> idtfs = mAsynchParser->parseIdentifiersResult();

*idtfs -= mIgnoreIdentifiers;

fillModel(mUpdateModel, *idtfs);

mIgnoreIdentifiers.clear();

mIsBusy = false;
}


15 changes: 12 additions & 3 deletions sources/plugins/scs/scscodeanalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ along with OSTIS. If not, see <http://www.gnu.org/licenses/>.
#include <QMap>

class QStandardItemModel;
class SCsParseExtractIdftAsynchTask;
class SCsAsynchParser;


class SCsCodeAnalyzer : public QObject
Expand All @@ -55,6 +57,8 @@ class SCsCodeAnalyzer : public QObject
*/
void update(const QString &text, QStandardItemModel *model);

void asynchUpdate(const QString &text, QStandardItemModel *model);

/*! Force to ignore the addition of an \p identifier during the next update
* (identifier wouldn't be added to autocomleter item model)
* @param identifier String that contains identifier
Expand All @@ -67,14 +71,19 @@ class SCsCodeAnalyzer : public QObject
static bool isIdentifier(const QString &text);

protected:
void fillModel(QStandardItemModel *model);
void extractIdentifiers(const QString &text, QSet<QString> *identifiers);
void fillModel(QStandardItemModel *model, const QSet<QString> &idtfs);
void extractIdentifiers(const QString &text, QSet<QString> &identifiers);

private slots:
void asynchUpdateExtractIdftFinished();

private:
const static QRegExp msIdentifierExp;
QSet<QString> mDocumentIdentifiers;
QSet<QString> mIgnoreIdentifiers;

QStandardItemModel* mUpdateModel;
SCsAsynchParser* mAsynchParser;
bool mIsBusy;
};


Expand Down
Loading