add missing files

This commit is contained in:
Roy Qu 2024-03-04 21:12:26 +08:00
parent 535dde574b
commit 2245356616
2 changed files with 256 additions and 0 deletions

View File

@ -0,0 +1,169 @@
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "textfile.h"
#include "../constants.h"
//#include <QDebug>
namespace QSynedit {
TextSyntaxer::TextSyntaxer()
{
mTextAttribute = std::make_shared<TokenAttribute>(SYNS_AttrText, TokenType::Default);
addAttribute(mTextAttribute);
}
void TextSyntaxer::procSpace()
{
mTokenID = TokenId::Space;
while (mLine[mRun]!=0 && mLine[mRun].isSpace())
mRun++;
if (mRun>=mStringLen)
mHasTrailingSpaces = true;
}
void TextSyntaxer::procText()
{
mTokenID = TokenId::Text;
while (mLine[mRun]!=0 && !mLine[mRun].isSpace())
mRun++;
}
void TextSyntaxer::procNull()
{
mTokenID = TokenId::Null;
mState = RangeState::Unknown;
}
QMap<QString, PTokenAttribute> TextSyntaxer::attributes() const
{
QMap<QString, PTokenAttribute> result;
result.insert(SYNS_AttrText, mTextAttribute);
result.insert(SYNS_AttrSpace, whitespaceAttribute());
return result;
}
bool TextSyntaxer::eol() const
{
return mTokenID == TokenId::Null;
}
QString TextSyntaxer::languageName()
{
return "textfile";
}
ProgrammingLanguage TextSyntaxer::language()
{
return ProgrammingLanguage::Textfile;
}
QString TextSyntaxer::getToken() const
{
return mLineString.mid(mTokenPos,mRun-mTokenPos);
}
const PTokenAttribute &TextSyntaxer::getTokenAttribute() const
{
/*
Directive,
Unknown
*/
switch(mTokenID) {
case TokenId::Space:
return mWhitespaceAttribute;
default:
return mTextAttribute;
}
}
int TextSyntaxer::getTokenPos()
{
return mTokenPos;
}
void TextSyntaxer::next()
{
mTokenPos = mRun;
if (mLine[mRun].unicode()==0) {
procNull();
} else if (isSpaceChar(mLine[mRun].unicode())) {
procSpace();
} else {
procText();
}
}
void TextSyntaxer::setLine(const QString &newLine, int lineNumber)
{
mLineString = newLine;
mLine = mLineString.data();
mLineNumber = lineNumber;
mRun = 0;
next();
}
bool TextSyntaxer::isCommentNotFinished(int /*state*/) const
{
return false;
}
bool TextSyntaxer::isStringNotFinished(int /*state*/) const
{
return false;
}
SyntaxState TextSyntaxer::getState() const
{
SyntaxState state;
state.state = (int)mState;
state.hasTrailingSpaces = mHasTrailingSpaces;
return state;
}
void TextSyntaxer::setState(const SyntaxState & rangeState)
{
mState = (RangeState)rangeState.state;
mHasTrailingSpaces = false;
}
void TextSyntaxer::resetState()
{
mState = RangeState::Unknown;
mHasTrailingSpaces = false;
}
QSet<QString> TextSyntaxer::keywords()
{
return QSet<QString>();
}
QString TextSyntaxer::commentSymbol()
{
return "";
}
bool TextSyntaxer::supportFolding()
{
return false;
}
bool TextSyntaxer::needsLineState()
{
return false;
}
}

View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef QSYNEDIT_TEXTFILE_SYNTAXER_H
#define QSYNEDIT_TEXTFILE_SYNTAXER_H
#include "syntaxer.h"
#include <QVector>
namespace QSynedit {
class TextSyntaxer : public Syntaxer
{
enum class TokenId {
Null,
Space,
Text
};
enum RangeState {
Unknown,
};
public:
explicit TextSyntaxer();
TextSyntaxer(const TextSyntaxer&)=delete;
TextSyntaxer& operator=(const TextSyntaxer&)=delete;
static const QSet<QString> Directives;
private:
QChar* mLine;
QString mLineString;
int mLineNumber;
int mRun;
int mStringLen;
int mTokenPos;
RangeState mState;
TokenId mTokenID;
bool mHasTrailingSpaces;
PTokenAttribute mTextAttribute;
private:
void procSpace();
void procText();
void procNull();
public:
QMap<QString, PTokenAttribute> attributes() const override;
bool eol() const override;
QString languageName() override;
ProgrammingLanguage language() override;
QString getToken() const override;
const PTokenAttribute &getTokenAttribute() const override;
int getTokenPos() override;
void next() override;
void setLine(const QString &newLine, int lineNumber) override;
bool isCommentNotFinished(int state) const override;
bool isStringNotFinished(int state) const override;
SyntaxState getState() const override;
void setState(const SyntaxState& rangeState) override;
void resetState() override;
QSet<QString> keywords() override;
QString commentSymbol() override;
bool supportFolding() override;
bool needsLineState() override;
};
}
#endif // MAKEFILE_H