From 2245356616c1b2e3a77d16fec8852513aed5427e Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 4 Mar 2024 21:12:26 +0800 Subject: [PATCH] add missing files --- libs/qsynedit/qsynedit/syntaxer/textfile.cpp | 169 +++++++++++++++++++ libs/qsynedit/qsynedit/syntaxer/textfile.h | 87 ++++++++++ 2 files changed, 256 insertions(+) create mode 100644 libs/qsynedit/qsynedit/syntaxer/textfile.cpp create mode 100644 libs/qsynedit/qsynedit/syntaxer/textfile.h diff --git a/libs/qsynedit/qsynedit/syntaxer/textfile.cpp b/libs/qsynedit/qsynedit/syntaxer/textfile.cpp new file mode 100644 index 00000000..20edb5e3 --- /dev/null +++ b/libs/qsynedit/qsynedit/syntaxer/textfile.cpp @@ -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 . + */ +#include "textfile.h" +#include "../constants.h" +//#include + +namespace QSynedit { + +TextSyntaxer::TextSyntaxer() +{ + mTextAttribute = std::make_shared(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 TextSyntaxer::attributes() const +{ + QMap 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 TextSyntaxer::keywords() +{ + return QSet(); +} + +QString TextSyntaxer::commentSymbol() +{ + return ""; +} + +bool TextSyntaxer::supportFolding() +{ + return false; +} + +bool TextSyntaxer::needsLineState() +{ + return false; +} + +} diff --git a/libs/qsynedit/qsynedit/syntaxer/textfile.h b/libs/qsynedit/qsynedit/syntaxer/textfile.h new file mode 100644 index 00000000..593d0448 --- /dev/null +++ b/libs/qsynedit/qsynedit/syntaxer/textfile.h @@ -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 . + */ +#ifndef QSYNEDIT_TEXTFILE_SYNTAXER_H +#define QSYNEDIT_TEXTFILE_SYNTAXER_H + + +#include "syntaxer.h" +#include + +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 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 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 keywords() override; + QString commentSymbol() override; + bool supportFolding() override; + bool needsLineState() override; + +}; + +} +#endif // MAKEFILE_H