forked from PuqiAR/Fig-TreeWalker
[VER] 0.4.0-alpha
[Fix] 修复恶性Bug: Parser: parseExpression没有正确解析二元表达式,没有用到 right binding power的问题,表现在生成类似 a * b * c时,结果为 a * (b * c) 的Bug [Impl][Fix] 修复跨文件(如import)报错信息错误的问题,现在Ast跟踪保存文件信息,报错统一从Error父类获取 [...] 忘了,好困不管了
This commit is contained in:
@@ -10,6 +10,10 @@
|
||||
#include <iostream> // debug
|
||||
#endif
|
||||
|
||||
#ifndef SourceInfo
|
||||
#define SourceInfo(ptr) (ptr->sourcePath), (ptr->sourceLines)
|
||||
#endif
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
|
||||
@@ -163,7 +167,7 @@ namespace Fig
|
||||
{
|
||||
if (it.isEnd())
|
||||
{
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, it.column());
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, it.column(), SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
next();
|
||||
@@ -200,12 +204,11 @@ namespace Fig
|
||||
}
|
||||
else
|
||||
{
|
||||
error = SyntaxError(FString(
|
||||
std::format(
|
||||
"Unsupported escape character: {}",
|
||||
FString(ec.getString()).toBasicString())),
|
||||
error = SyntaxError(FString(std::format("Unsupported escape character: {}",
|
||||
FString(ec.getString()).toBasicString())),
|
||||
this->line,
|
||||
it.column());
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
}
|
||||
@@ -217,7 +220,7 @@ namespace Fig
|
||||
}
|
||||
if (unterminated)
|
||||
{
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, str_start_col);
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, str_start_col, SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
return Token(str, TokenType::LiteralString);
|
||||
@@ -244,7 +247,7 @@ namespace Fig
|
||||
}
|
||||
if (unterminated)
|
||||
{
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, str_start_col);
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, str_start_col, SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
return Token(str, TokenType::LiteralString);
|
||||
@@ -275,7 +278,7 @@ namespace Fig
|
||||
{
|
||||
if (it.isEnd())
|
||||
{
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, it.column());
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, it.column(), SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
next();
|
||||
@@ -317,12 +320,11 @@ namespace Fig
|
||||
}
|
||||
else
|
||||
{
|
||||
error = SyntaxError(FString(
|
||||
std::format(
|
||||
"Unsupported escape character: {}",
|
||||
FString(ec.getString()).toBasicString())),
|
||||
error = SyntaxError(FString(std::format("Unsupported escape character: {}",
|
||||
FString(ec.getString()).toBasicString())),
|
||||
this->line,
|
||||
it.column());
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
}
|
||||
@@ -334,7 +336,7 @@ namespace Fig
|
||||
}
|
||||
if (unterminated)
|
||||
{
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, str_start_col);
|
||||
error = SyntaxError(u8"Unterminated FString", this->line, str_start_col, SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
return Token(str, TokenType::LiteralString);
|
||||
@@ -378,8 +380,10 @@ namespace Fig
|
||||
|
||||
if (numStr.ends_with(U'e'))
|
||||
{
|
||||
error = SyntaxError(
|
||||
FString(std::format("Illegal number literal: {}", numStr.toBasicString())), this->line, it.column());
|
||||
error = SyntaxError(FString(std::format("Illegal number literal: {}", numStr.toBasicString())),
|
||||
this->line,
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
|
||||
@@ -395,8 +399,10 @@ namespace Fig
|
||||
|
||||
if (!hasDigit)
|
||||
{
|
||||
error = SyntaxError(
|
||||
FString(std::format("Illegal number literal: {}", numStr.toBasicString())), this->line, it.column());
|
||||
error = SyntaxError(FString(std::format("Illegal number literal: {}", numStr.toBasicString())),
|
||||
this->line,
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
|
||||
@@ -407,14 +413,16 @@ namespace Fig
|
||||
{
|
||||
error = SyntaxError(FString(std::format("Illegal number literal: {}", numStr.toBasicString())),
|
||||
this->line,
|
||||
it.column());
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
if (ePos + 1 >= numStr.length())
|
||||
{
|
||||
error = SyntaxError(FString(std::format("Illegal number literal: {}", numStr.toBasicString())),
|
||||
this->line,
|
||||
it.column());
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
bool hasDigitAfterE = false;
|
||||
@@ -427,7 +435,8 @@ namespace Fig
|
||||
{
|
||||
error = SyntaxError(FString(std::format("Illegal number literal: {}", numStr.toBasicString())),
|
||||
this->line,
|
||||
it.column());
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
continue;
|
||||
@@ -438,7 +447,8 @@ namespace Fig
|
||||
{
|
||||
error = SyntaxError(FString(std::format("Illegal number literal: {}", numStr.toBasicString())),
|
||||
this->line,
|
||||
it.column());
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
}
|
||||
@@ -447,7 +457,8 @@ namespace Fig
|
||||
{
|
||||
error = SyntaxError(FString(std::format("Illegal number literal: {}", numStr.toBasicString())),
|
||||
this->line,
|
||||
it.column());
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
return IllegalTok;
|
||||
}
|
||||
}
|
||||
@@ -472,9 +483,10 @@ namespace Fig
|
||||
|
||||
if (!startsWith(sym))
|
||||
{
|
||||
error = SyntaxError(
|
||||
FString(std::format("No such operator: {}", sym.toBasicString())),
|
||||
this->line, it.column());
|
||||
error = SyntaxError(FString(std::format("No such operator: {}", sym.toBasicString())),
|
||||
this->line,
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
next();
|
||||
return IllegalTok;
|
||||
}
|
||||
@@ -500,9 +512,10 @@ namespace Fig
|
||||
|
||||
if (!symbol_map.contains(sym))
|
||||
{
|
||||
error = SyntaxError(
|
||||
FString(std::format("No such operator: {}", sym.toBasicString())),
|
||||
this->line, it.column());
|
||||
error = SyntaxError(FString(std::format("No such operator: {}", sym.toBasicString())),
|
||||
this->line,
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
next();
|
||||
return IllegalTok;
|
||||
}
|
||||
@@ -562,7 +575,8 @@ namespace Fig
|
||||
|
||||
if (!terminated)
|
||||
{
|
||||
error = SyntaxError(FString(u8"Unterminated multiline comment"), this->line, it.column());
|
||||
error =
|
||||
SyntaxError(FString(u8"Unterminated multiline comment"), this->line, it.column(), SourceInfo(this));
|
||||
next();
|
||||
return IllegalTok;
|
||||
}
|
||||
@@ -633,9 +647,11 @@ namespace Fig
|
||||
}
|
||||
else
|
||||
{
|
||||
error = SyntaxError(FString(
|
||||
std::format("Cannot tokenize char: '{}'", FString(ch.getString()).toBasicString())),
|
||||
this->line, it.column());
|
||||
error =
|
||||
SyntaxError(FString(std::format("Cannot tokenize char: '{}'", FString(ch.getString()).toBasicString())),
|
||||
this->line,
|
||||
it.column(),
|
||||
SourceInfo(this));
|
||||
if (hasNext())
|
||||
{
|
||||
next();
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Fig
|
||||
SyntaxError error;
|
||||
UTF8Iterator it;
|
||||
|
||||
FString sourcePath;
|
||||
std::vector<FString> sourceLines;
|
||||
|
||||
std::vector<Warning> warnings;
|
||||
|
||||
size_t last_line, last_column, column = 1;
|
||||
@@ -60,8 +63,8 @@ namespace Fig
|
||||
static const std::unordered_map<FString, TokenType> symbol_map;
|
||||
static const std::unordered_map<FString, TokenType> keyword_map;
|
||||
|
||||
inline Lexer(const FString &_source) :
|
||||
source(_source), it(source)
|
||||
inline Lexer(const FString &_source, const FString &_sourcePath, const std::vector<FString> &_sourceLines) :
|
||||
source(_source), it(source), sourcePath(_sourcePath), sourceLines(_sourceLines)
|
||||
{
|
||||
line = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user