2022-11-06 00:37:50 +00:00
|
|
|
#include "SyntaxBase.h"
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
using namespace Parse;
|
|
|
|
using namespace Lex;
|
2022-11-06 11:40:11 +00:00
|
|
|
using namespace Syntax;
|
|
|
|
using namespace Parse::Result;
|
|
|
|
|
|
|
|
namespace Parse {
|
|
|
|
class Unknown : public DesNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Unknown(DocCore *ins)
|
|
|
|
: doc_store(ins) {}
|
|
|
|
|
|
|
|
// 通过 DesNode 继承
|
|
|
|
virtual int depth() const override
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
virtual DocCore * document() const override
|
|
|
|
{
|
|
|
|
return doc_store;
|
|
|
|
}
|
|
|
|
virtual int typeValue() const override
|
|
|
|
{
|
|
|
|
return NODE_UNKNOWNHOST;
|
|
|
|
}
|
|
|
|
virtual DesNode * parent() const override
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual void appendChild(DesNode *) override
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual QList<DesNode*> children() const override
|
|
|
|
{
|
|
|
|
return QList<DesNode*>();
|
|
|
|
}
|
|
|
|
virtual bool check(QList<QString>&) const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual QString toString() const override
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
DocCore *const doc_store;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
Words::Words(Result::DesNode *host, DocCore *doc, const QString & value, int row, int col)
|
|
|
|
: value_store(value), row_store(row), col_store(col), desnode_store(host), docpresent_store(doc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int Words::row() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return row_store;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
int Words::column() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return col_store;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
int Words::length() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return value_store.length();
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
DesNode * Words::host() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return desnode_store;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
DocCore * Words::doc() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return docpresent_store;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
QString Words::toString() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return value_store;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
DocCore::DocCore(ProjectCore * core, const QString & path)
|
|
|
|
: unknown_host(new Unknown(this)), core_store(core), file_path_store(path)
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
DesNode * DocCore::unknowns() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return unknown_host;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
ProjectCore * DocCore::project() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return core_store;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
void DocCore::rename(const QString & new_name)
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
file_path_store = new_name;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
QString DocCore::filePath() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return file_path_store;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
QString DocCore::fileName() const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
return QFileInfo(file_path_store).fileName();
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
void DocCore::clear()
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
nodes_store.clear();
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
int DocCore::append(Words * ins)
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
nodes_store << ins;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:40:11 +00:00
|
|
|
Words * DocCore::getWords(int row, int col) const
|
2022-11-06 00:37:50 +00:00
|
|
|
{
|
|
|
|
for (auto it : nodes_store)
|
|
|
|
if (it->row() == row && it->column() <= col && it->column() + it->length() >= col)
|
|
|
|
return it;
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|