Skip to content

Commit

Permalink
Merge branch '1725-fixed-eolcom-in-tables' into '1.5.x-release'
Browse files Browse the repository at this point in the history
Resolve "Highlighter in table ignores EolCom"

See merge request devel/studio!715
  • Loading branch information
ClemensGAMS committed Feb 19, 2021
2 parents 828cfe1 + 2275c01 commit 66ec0ff
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 170 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version 1.5.4 *
- fixed GDX file reloaded too early while being rewritten
- fixed FIL marker in LOG doesn't handle relative filepaths
- parse port for GAMS Engine URL
- fixed syntax highlighting for standard eolCom in table definition

Version 1.5.3
==================
Expand Down
17 changes: 10 additions & 7 deletions src/syntax/syntaxdeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ int SyntaxKeywordBase::findEnd(SyntaxKind kind, const QString& line, int index,
}


SyntaxDeclaration::SyntaxDeclaration() : SyntaxKeywordBase(SyntaxKind::Declaration)
SyntaxDeclaration::SyntaxDeclaration(SharedSyntaxData *sharedData)
: SyntaxKeywordBase(SyntaxKind::Declaration, sharedData)
{
QList<QPair<QString, QString>> list;
list = SyntaxData::declaration();
Expand Down Expand Up @@ -151,7 +152,8 @@ SyntaxBlock SyntaxDeclaration::find(const SyntaxKind entryKind, int flavor, cons
return SyntaxBlock(this);
}

SyntaxPreDeclaration::SyntaxPreDeclaration(SyntaxKind kind) : SyntaxKeywordBase(kind)
SyntaxPreDeclaration::SyntaxPreDeclaration(SyntaxKind kind, SharedSyntaxData *sharedData)
: SyntaxKeywordBase(kind, sharedData)
{
QList<QPair<QString, QString>> list;
switch (kind) {
Expand Down Expand Up @@ -192,7 +194,7 @@ SyntaxBlock SyntaxPreDeclaration::find(const SyntaxKind entryKind, int flavor, c
return SyntaxBlock(this);
}

SyntaxReserved::SyntaxReserved(SyntaxKind kind) : SyntaxKeywordBase(kind)
SyntaxReserved::SyntaxReserved(SyntaxKind kind, SharedSyntaxData *sharedData) : SyntaxKeywordBase(kind, sharedData)
{
mSubKinds << SyntaxKind::Semicolon << SyntaxKind::String << SyntaxKind::Embedded << SyntaxKind::Solve
<< SyntaxKind::Reserved << SyntaxKind::CommentLine << SyntaxKind::CommentEndline
Expand Down Expand Up @@ -251,7 +253,7 @@ SyntaxBlock SyntaxReserved::find(const SyntaxKind entryKind, int flavor, const Q
}


SyntaxEmbedded::SyntaxEmbedded(SyntaxKind kind) : SyntaxKeywordBase(kind)
SyntaxEmbedded::SyntaxEmbedded(SyntaxKind kind, SharedSyntaxData *sharedData) : SyntaxKeywordBase(kind, sharedData)
{
QList<QPair<QString, QString>> list;
if (kind == SyntaxKind::Embedded) {
Expand Down Expand Up @@ -280,7 +282,8 @@ SyntaxBlock SyntaxEmbedded::find(const SyntaxKind entryKind, int flavor, const Q
return SyntaxBlock(this);
}

SyntaxEmbeddedBody::SyntaxEmbeddedBody() : SyntaxAbstract(SyntaxKind::EmbeddedBody)
SyntaxEmbeddedBody::SyntaxEmbeddedBody(SharedSyntaxData *sharedData)
: SyntaxAbstract(SyntaxKind::EmbeddedBody, sharedData)
{
mSubKinds << SyntaxKind::EmbeddedEnd << SyntaxKind::Directive;
}
Expand All @@ -293,11 +296,11 @@ SyntaxBlock SyntaxEmbeddedBody::find(const SyntaxKind entryKind, int flavor, con

SyntaxBlock SyntaxEmbeddedBody::validTail(const QString &line, int index, int flavor, bool &hasContent)
{
Q_UNUSED(hasContent);
Q_UNUSED(hasContent)
return SyntaxBlock(this, flavor, index, line.length());
}

SyntaxSubsetKey::SyntaxSubsetKey(SyntaxKind kind) : SyntaxKeywordBase(kind)
SyntaxSubsetKey::SyntaxSubsetKey(SyntaxKind kind, SharedSyntaxData *sharedData) : SyntaxKeywordBase(kind, sharedData)
{
mSubKinds << SyntaxKind::Semicolon << SyntaxKind::Directive << SyntaxKind::CommentLine
<< SyntaxKind::CommentEndline << SyntaxKind::CommentInline;
Expand Down
14 changes: 7 additions & 7 deletions src/syntax/syntaxdeclaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SyntaxKeywordBase: public SyntaxAbstract

public:
~SyntaxKeywordBase() override;
SyntaxKeywordBase(SyntaxKind kind) : SyntaxAbstract(kind) {}
SyntaxKeywordBase(SyntaxKind kind, SharedSyntaxData* sharedData) : SyntaxAbstract(kind, sharedData) {}
SyntaxBlock validTail(const QString &line, int index, int flavor, bool &hasContent) override;

protected:
Expand All @@ -84,45 +84,45 @@ class SyntaxKeywordBase: public SyntaxAbstract
class SyntaxDeclaration: public SyntaxKeywordBase
{
public:
SyntaxDeclaration();
SyntaxDeclaration(SharedSyntaxData* sharedData);
SyntaxBlock find(const SyntaxKind entryKind, int flavor, const QString &line, int index) override;
};

class SyntaxPreDeclaration: public SyntaxKeywordBase
{
public:
SyntaxPreDeclaration(SyntaxKind kind);
SyntaxPreDeclaration(SyntaxKind kind, SharedSyntaxData* sharedData);
SyntaxBlock find(const SyntaxKind entryKind, int flavor, const QString &line, int index) override;
};


class SyntaxReserved: public SyntaxKeywordBase
{
public:
SyntaxReserved(SyntaxKind kind);
SyntaxReserved(SyntaxKind kind, SharedSyntaxData* sharedData);
SyntaxBlock find(const SyntaxKind entryKind, int flavor, const QString &line, int index) override;
};

class SyntaxSubsetKey: public SyntaxKeywordBase
{
QVector<int> mOtherKey;
public:
SyntaxSubsetKey(SyntaxKind kind);
SyntaxSubsetKey(SyntaxKind kind, SharedSyntaxData* sharedData);
SyntaxBlock find(const SyntaxKind entryKind, int flavor, const QString &line, int index) override;
SyntaxBlock validTail(const QString &line, int index, int flavor, bool &hasContent) override;
};

class SyntaxEmbedded: public SyntaxKeywordBase
{
public:
SyntaxEmbedded(SyntaxKind kind);
SyntaxEmbedded(SyntaxKind kind, SharedSyntaxData* sharedData);
SyntaxBlock find(const SyntaxKind entryKind, int flavor, const QString &line, int index) override;
};

class SyntaxEmbeddedBody: public SyntaxAbstract
{
public:
SyntaxEmbeddedBody();
SyntaxEmbeddedBody(SharedSyntaxData* sharedData);
SyntaxBlock find(const SyntaxKind entryKind, int flavor, const QString &line, int index) override;
SyntaxBlock validTail(const QString &line, int index, int flavor, bool &hasContent) override;
};
Expand Down
81 changes: 49 additions & 32 deletions src/syntax/syntaxformats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int SyntaxAbstract::endOfParentheses(const QString &line, const int &start, cons
}


SyntaxStandard::SyntaxStandard() : SyntaxAbstract(SyntaxKind::Standard)
SyntaxStandard::SyntaxStandard(SharedSyntaxData *sharedData) : SyntaxAbstract(SyntaxKind::Standard, sharedData)
{
mSubKinds << SyntaxKind::Semicolon
<< SyntaxKind::CommentLine
Expand Down Expand Up @@ -142,7 +142,8 @@ SyntaxBlock SyntaxStandard::validTail(const QString &line, int index, int flavor
return SyntaxBlock();
}

SyntaxDirective::SyntaxDirective(QChar directiveChar) : SyntaxAbstract(SyntaxKind::Directive)
SyntaxDirective::SyntaxDirective(SharedSyntaxData *sharedData, QChar directiveChar)
: SyntaxAbstract(SyntaxKind::Directive, sharedData)
{
mRex.setPattern(QString("(^%1|%1%1)\\s*([\\w]+)\\s*").arg(QRegularExpression::escape(directiveChar)));

Expand Down Expand Up @@ -231,24 +232,25 @@ SyntaxBlock SyntaxDirective::find(const SyntaxKind entryKind, int flavor, const
|| match.captured(2).compare("offembeddedcode", Qt::CaseInsensitive) == 0)
return SyntaxBlock(this, outFlavor, match.capturedStart(1), match.capturedEnd(0), SyntaxShift::out);
return SyntaxBlock(this);
} else if (mSyntaxCommentEndline) {
} else if (mSharedData->commentEndLine()) {
if (match.captured(2).startsWith("oneolcom", Qt::CaseInsensitive)) {
mSyntaxCommentEndline->setCommentChars("!!");
for (SyntaxFormula * sf: mSubSyntaxBody) {
// This only activates the current eolCom
// mSharedData->commentEndLine()->setCommentChars("!!");
for (SyntaxFormula * sf: mSharedData->allFormula()) {
sf->setSpecialDynamicChars(QVector<QChar>() << '!');
}
if (mSubDirectiveBody)
mSubDirectiveBody->setCommentChars(QVector<QChar>() << '!');
mSharedData->directiveBody()->setCommentChars(QVector<QChar>() << '!');
} else if (match.captured(2).startsWith("eolcom", Qt::CaseInsensitive)) {
int i = match.capturedEnd(2);
while (isWhitechar(line,i)) ++i;
if (i+2 <= line.length()) {
mSyntaxCommentEndline->setCommentChars(line.mid(i,2));
for (SyntaxFormula * sf: mSubSyntaxBody) {
int comSize = 2;
if (i+1 == line.length() || isWhitechar(line,i+1)) comSize = 1;
if (i+comSize <= line.length()) {
mSharedData->commentEndLine()->setCommentChars(line.mid(i,comSize));
for (SyntaxFormula * sf: mSharedData->allFormula()) {
sf->setSpecialDynamicChars(QVector<QChar>() << line.at(i));
}
if (mSubDirectiveBody)
mSubDirectiveBody->setCommentChars(QVector<QChar>() << line.at(i));
mSharedData->directiveBody()->setCommentChars(QVector<QChar>() << line.at(i));
}
}
}
Expand Down Expand Up @@ -276,8 +278,10 @@ SyntaxBlock SyntaxDirective::validTail(const QString &line, int index, int flavo
}


SyntaxDirectiveBody::SyntaxDirectiveBody(SyntaxKind kind) : SyntaxAbstract(kind)
SyntaxDirectiveBody::SyntaxDirectiveBody(SyntaxKind kind, SharedSyntaxData *sharedData)
: SyntaxAbstract(kind, sharedData)
{
sharedData->registerDirectiveBody(this);
if (kind == SyntaxKind::IgnoredHead) {
mSubKinds << SyntaxKind::Directive << SyntaxKind::IgnoredHead << SyntaxKind::IgnoredBlock;
mEmptyLineKinds << SyntaxKind::IgnoredBlock;
Expand All @@ -289,16 +293,16 @@ SyntaxDirectiveBody::SyntaxDirectiveBody(SyntaxKind kind) : SyntaxAbstract(kind)

void SyntaxDirectiveBody::setCommentChars(QVector<QChar> chars)
{
mCommentChars = chars;
mEolComChars = chars;
}

SyntaxBlock SyntaxDirectiveBody::find(const SyntaxKind entryKind, int flavor, const QString& line, int index)
{
int end = index;
if (index == 0 && entryKind == SyntaxKind::IgnoredHead) return SyntaxBlock();
if (entryKind == SyntaxKind::DirectiveBody && end < line.length()
&& mCommentChars.contains(line.at(end))) ++end;
while (end < line.length() && !mCommentChars.contains(line.at(end)))
&& mEolComChars.contains(line.at(end))) ++end;
while (end < line.length() && !mEolComChars.contains(line.at(end)))
++end;
return SyntaxBlock(this, flavor, index, end, SyntaxShift::shift);
}
Expand All @@ -308,15 +312,15 @@ SyntaxBlock SyntaxDirectiveBody::validTail(const QString &line, int index, int f
int start = index;
while (isWhitechar(line, start)) start++;
int end = start;
while (end < line.length() && !mCommentChars.contains(line.at(end)))
while (end < line.length() && !mEolComChars.contains(line.at(end)))
++end;
hasContent = end > start;
return SyntaxBlock(this, flavor, start, end, SyntaxShift::shift);
}


SyntaxCommentLine::SyntaxCommentLine(QChar commentChar)
: SyntaxAbstract(SyntaxKind::CommentLine), mCommentChar(commentChar)
SyntaxCommentLine::SyntaxCommentLine(SharedSyntaxData *sharedData, QChar commentChar)
: SyntaxAbstract(SyntaxKind::CommentLine, sharedData), mCommentChar(commentChar)
{ }

SyntaxBlock SyntaxCommentLine::find(const SyntaxKind entryKind, int flavor, const QString& line, int index)
Expand All @@ -336,7 +340,8 @@ SyntaxBlock SyntaxCommentLine::validTail(const QString &line, int index, int fla
}


SyntaxUniformBlock::SyntaxUniformBlock(SyntaxKind kind) : SyntaxAbstract(kind)
SyntaxUniformBlock::SyntaxUniformBlock(SyntaxKind kind, SharedSyntaxData *sharedData)
: SyntaxAbstract(kind, sharedData)
{
mSubKinds << SyntaxKind::Directive;
}
Expand All @@ -355,8 +360,8 @@ SyntaxBlock SyntaxUniformBlock::validTail(const QString &line, int index, int fl
return SyntaxBlock(this, flavor, index, line.length(), SyntaxShift::shift);
}

SyntaxDelimiter::SyntaxDelimiter(SyntaxKind kind)
: SyntaxAbstract(kind)
SyntaxDelimiter::SyntaxDelimiter(SyntaxKind kind, SharedSyntaxData *sharedData)
: SyntaxAbstract(kind, sharedData)
{
mSubKinds << SyntaxKind::CommentEndline;
if (kind == SyntaxKind::Semicolon) {
Expand Down Expand Up @@ -392,8 +397,9 @@ SyntaxBlock SyntaxDelimiter::validTail(const QString &line, int index, int flavo
return SyntaxBlock(this, flavor, index, end, SyntaxShift::shift);
}

SyntaxFormula::SyntaxFormula(SyntaxKind kind) : SyntaxAbstract(kind)
SyntaxFormula::SyntaxFormula(SyntaxKind kind, SharedSyntaxData *sharedData) : SyntaxAbstract(kind, sharedData)
{
sharedData->addFormula(this);
mSubKinds << SyntaxKind::Embedded << SyntaxKind::Semicolon << SyntaxKind::Solve << SyntaxKind::Option
<< SyntaxKind::Execute << SyntaxKind::Reserved << SyntaxKind::CommentLine << SyntaxKind::CommentEndline
<< SyntaxKind::CommentInline << SyntaxKind::String << SyntaxKind::Directive << SyntaxKind::Assignment
Expand Down Expand Up @@ -464,8 +470,8 @@ void SyntaxFormula::setSpecialDynamicChars(QVector<QChar> chars)
mSpecialDynamicChars << '=';
}

SyntaxString::SyntaxString()
: SyntaxAbstract(SyntaxKind::String)
SyntaxString::SyntaxString(SharedSyntaxData *sharedData)
: SyntaxAbstract(SyntaxKind::String, sharedData)
{}

SyntaxBlock SyntaxString::find(const SyntaxKind entryKind, int flavor, const QString &line, int index)
Expand All @@ -492,7 +498,7 @@ SyntaxBlock SyntaxString::validTail(const QString &line, int index, int flavor,
return SyntaxBlock(this);
}

SyntaxAssign::SyntaxAssign() : SyntaxAbstract(SyntaxKind::Assignment)
SyntaxAssign::SyntaxAssign(SharedSyntaxData *sharedData) : SyntaxAbstract(SyntaxKind::Assignment, sharedData)
{}

SyntaxBlock SyntaxAssign::find(const SyntaxKind entryKind, int flavor, const QString &line, int index)
Expand Down Expand Up @@ -528,25 +534,36 @@ SyntaxBlock SyntaxAssign::validTail(const QString &line, int index, int flavor,
return SyntaxBlock(this);
}

SyntaxCommentEndline::SyntaxCommentEndline(QString commentChars)
: SyntaxAbstract(SyntaxKind::CommentEndline)
SyntaxCommentEndline::SyntaxCommentEndline(SharedSyntaxData *sharedData, QString commentChars)
: SyntaxAbstract(SyntaxKind::CommentEndline, sharedData)
{
mSharedData->registerCommentEndLine(this);
setCommentChars(commentChars);
}

void SyntaxCommentEndline::setCommentChars(QString commentChars)
{
if (commentChars.length() == 2)
if (commentChars.length() == 1 || commentChars.length() == 2)
mCommentChars = commentChars;
}

bool SyntaxCommentEndline::check(const QString &line, int index) const
{
if (index + mCommentChars.length() > line.length()) return false;
if (line.at(index) != mCommentChars.at(0)) return false;
if (mCommentChars.length() > 1 && line.at(index+1) != mCommentChars.at(1)) return false;
return true;
}

SyntaxBlock SyntaxCommentEndline::find(const SyntaxKind entryKind, int flavor, const QString &line, int index)
{
Q_UNUSED(entryKind)
int start = index;
while (isWhitechar(line, start))
++start;
if (start+2 <= line.length() && line.at(start) == mCommentChars.at(0) && line.at(start+1) == mCommentChars.at(1))

if (start+mCommentChars.size() <= line.length() && line.at(start) == mCommentChars.at(0) &&
(mCommentChars.size() == 1 || line.at(start+1) == mCommentChars.at(1)))
return SyntaxBlock(this, flavor, start, line.length(), SyntaxShift::skip);
return SyntaxBlock(this);
}
Expand All @@ -560,10 +577,10 @@ SyntaxBlock SyntaxCommentEndline::validTail(const QString &line, int index, int
return SyntaxBlock(this);
}

SyntaxCall::SyntaxCall(): SyntaxAbstract(SyntaxKind::Call)
SyntaxCall::SyntaxCall(SharedSyntaxData *sharedData): SyntaxAbstract(SyntaxKind::Call, sharedData)
{
QList<QPair<QString, QString>> list = SyntaxData::execute();
for (const QPair<QString,QString> &entry : list) {
for (const QPair<QString,QString> &entry : qAsConst(list)) {
if (entry.first != "sync" && entry.first != "embedded")
mSubDirective << entry.first;
}
Expand Down
Loading

0 comments on commit 66ec0ff

Please sign in to comment.