mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Bookmark panel tweaks
This commit is contained in:
parent
9daae6baa6
commit
ebcaffbae9
7 changed files with 204 additions and 24 deletions
|
@ -452,6 +452,26 @@ void BfParser::GetLineCharAtIdx(int idx, int& line, int& lineChar)
|
|||
mParserData->GetLineCharAtIdx(idx, line, lineChar);
|
||||
}
|
||||
|
||||
int BfParser::GetIndexAtLine(int line)
|
||||
{
|
||||
if (line == 0)
|
||||
return 0;
|
||||
|
||||
int curLine = 0;
|
||||
for (int i = 0; i < mSrcLength; i++)
|
||||
{
|
||||
char c = mSrc[i];
|
||||
if (c == '\n')
|
||||
{
|
||||
curLine++;
|
||||
if (line == curLine)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void BfParser::Fail(const StringImpl& error, int offset)
|
||||
{
|
||||
mPassInstance->FailAt(error, mSourceData, mSrcIdx + offset);
|
||||
|
|
|
@ -230,6 +230,7 @@ public:
|
|||
virtual BfParser* ToParser() override { return this; }
|
||||
|
||||
void GetLineCharAtIdx(int idx, int& line, int& lineChar);
|
||||
int GetIndexAtLine(int line);
|
||||
|
||||
void Fail(const StringImpl& error, int offset = -1);
|
||||
void TokenFail(const StringImpl& error, int offset = -1);
|
||||
|
|
|
@ -4090,6 +4090,72 @@ BF_EXPORT void BF_CALLTYPE BfSystem_DeleteParser(BfSystem* bfSystem, BfParser* b
|
|||
//bfSystem->mParserDeleteQueue.push_back(bfParser);
|
||||
}
|
||||
|
||||
class BfLocationNameVisitor : public BfElementVisitor
|
||||
{
|
||||
public:
|
||||
int mIndex;
|
||||
String mName;
|
||||
|
||||
bool TryNode(BfAstNode* node)
|
||||
{
|
||||
if ((mIndex >= node->mSrcStart) && (mIndex < node->mSrcEnd))
|
||||
{
|
||||
if (!mName.IsEmpty())
|
||||
mName += ".";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void Visit(BfTypeDeclaration* typeDeclaration)
|
||||
{
|
||||
if ((typeDeclaration->mNameNode != NULL) && (TryNode(typeDeclaration)))
|
||||
{
|
||||
typeDeclaration->mNameNode->ToString(mName);
|
||||
}
|
||||
|
||||
BfElementVisitor::Visit(typeDeclaration);
|
||||
}
|
||||
|
||||
virtual void Visit(BfMethodDeclaration* methodDeclaration)
|
||||
{
|
||||
if ((methodDeclaration->mNameNode != NULL) && (TryNode(methodDeclaration)))
|
||||
{
|
||||
if (methodDeclaration->mNameNode != NULL)
|
||||
methodDeclaration->mNameNode->ToString(mName);
|
||||
}
|
||||
|
||||
BfElementVisitor::Visit(methodDeclaration);
|
||||
}
|
||||
|
||||
virtual void Visit(BfPropertyDeclaration* propertyDeclaration)
|
||||
{
|
||||
if ((propertyDeclaration->mNameNode != NULL) && (TryNode(propertyDeclaration)))
|
||||
{
|
||||
if (propertyDeclaration->mNameNode != NULL)
|
||||
propertyDeclaration->mNameNode->ToString(mName);
|
||||
}
|
||||
|
||||
BfElementVisitor::Visit(propertyDeclaration);
|
||||
}
|
||||
};
|
||||
|
||||
BF_EXPORT const char* BfSystem_GetParserLocationName(BfParser* parser, int line, int column)
|
||||
{
|
||||
int idx = parser->GetIndexAtLine(line);
|
||||
if (idx == -1)
|
||||
return NULL;
|
||||
idx += column;
|
||||
|
||||
BfLocationNameVisitor visitor;
|
||||
visitor.mIndex = idx;
|
||||
visitor.VisitMembers(parser->mRootNode);
|
||||
|
||||
String& outString = *gTLStrReturn.Get();
|
||||
outString = visitor.mName;
|
||||
return outString.c_str();
|
||||
}
|
||||
|
||||
BF_EXPORT BfCompiler* BF_CALLTYPE BfSystem_CreateCompiler(BfSystem* bfSystem, bool isResolveOnly)
|
||||
{
|
||||
return bfSystem->CreateCompiler(isResolveOnly);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue