mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 12:02:21 +02:00
Improved "unexpected character" error
This commit is contained in:
parent
a8ef67477a
commit
0010b29a98
2 changed files with 23 additions and 2 deletions
|
@ -477,6 +477,25 @@ void BfParser::Fail(const StringImpl& error, int offset)
|
||||||
mPassInstance->FailAt(error, mSourceData, mSrcIdx + offset);
|
mPassInstance->FailAt(error, mSourceData, mSrcIdx + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BfParser::UnexpectedCharacter()
|
||||||
|
{
|
||||||
|
if (mPreprocessorIgnoredSectionNode != NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int startIdx = mTokenStart;
|
||||||
|
int endIdx = startIdx;
|
||||||
|
char32_t c = u8_nextchar((char*)mSrc, &endIdx);
|
||||||
|
int charLen = endIdx - startIdx;
|
||||||
|
|
||||||
|
String str = "Unexpected character '";
|
||||||
|
for (int i = 0; i < charLen; i++)
|
||||||
|
str += mSrc[startIdx + i];
|
||||||
|
str += StrFormat("' (0x%0X)", (int)c);
|
||||||
|
|
||||||
|
mPassInstance->FailAt(str, mSourceData, startIdx);
|
||||||
|
mSrcIdx = endIdx;
|
||||||
|
}
|
||||||
|
|
||||||
void BfParser::TokenFail(const StringImpl& error, int offset)
|
void BfParser::TokenFail(const StringImpl& error, int offset)
|
||||||
{
|
{
|
||||||
if (mPreprocessorIgnoredSectionNode == NULL)
|
if (mPreprocessorIgnoredSectionNode == NULL)
|
||||||
|
@ -2446,7 +2465,8 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro
|
||||||
case '#':
|
case '#':
|
||||||
if (disablePreprocessor)
|
if (disablePreprocessor)
|
||||||
{
|
{
|
||||||
TokenFail("Unexpected character");
|
mTokenStart = mSrcIdx - 1;
|
||||||
|
UnexpectedCharacter();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3457,7 +3477,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro
|
||||||
{
|
{
|
||||||
AddErrorNode(mTokenStart, mSrcIdx);
|
AddErrorNode(mTokenStart, mSrcIdx);
|
||||||
mTriviaStart = mSrcIdx;
|
mTriviaStart = mSrcIdx;
|
||||||
TokenFail("Unexpected character");
|
UnexpectedCharacter();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,6 +234,7 @@ public:
|
||||||
|
|
||||||
void Fail(const StringImpl& error, int offset = -1);
|
void Fail(const StringImpl& error, int offset = -1);
|
||||||
void TokenFail(const StringImpl& error, int offset = -1);
|
void TokenFail(const StringImpl& error, int offset = -1);
|
||||||
|
void UnexpectedCharacter();
|
||||||
|
|
||||||
void SetSource(const char* data, int length);
|
void SetSource(const char* data, int length);
|
||||||
void MoveSource(const char* data, int length); // Takes ownership of data ptr
|
void MoveSource(const char* data, int length); // Takes ownership of data ptr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue