[Feat] 详细区分左值(LvObject)与右值(RvObject -> ObjectPtr)

[Impl] 重构evaluator.cpp + hpp 全部
[Feat] 增加对于IndexExpr的解析
[Fix][Impl] 现在点运算符不由BinaryExpr负责,增加MemberExpr,单独实现解析
[Impl] 项目目录全部翻修, src/目录下单独文件夹放置每一个模块
This commit is contained in:
2025-12-24 17:51:49 +08:00
parent 3227230aa2
commit fc35368d85
70 changed files with 1558 additions and 1233 deletions

94
src/Lexer/lexer.hpp Normal file
View File

@@ -0,0 +1,94 @@
#pragma once
#include <corecrt.h>
#include <cuchar>
#include <cwctype>
#include <unordered_map>
#include <vector>
#include <Token/token.hpp>
#include <Error/error.hpp>
#include <Core/fig_string.hpp>
#include <Core/utf8_iterator.hpp>
#include <Core/warning.hpp>
namespace Fig
{
class Lexer final
{
private:
size_t line;
const FString source;
SyntaxError error;
UTF8Iterator it;
std::vector<Warning> warnings;
size_t last_line, last_column, column = 1;
bool hasNext()
{
return !this->it.isEnd();
}
void skipLine();
inline void next()
{
if (*it == U'\n')
{
++this->line;
this->column = 1;
}
else
{
++this->column;
}
++it;
}
void pushWarning(size_t id, FString msg)
{
warnings.push_back(Warning(id, std::move(msg), getCurrentLine(), getCurrentColumn()));
}
void pushWarning(size_t id, FString msg, size_t line, size_t column)
{
warnings.push_back(Warning(id, std::move(msg), line, column));
}
public:
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)
{
line = 1;
}
inline size_t getCurrentLine()
{
return line;
}
inline size_t getCurrentColumn()
{
return column;
}
SyntaxError getError() const
{
return error;
}
std::vector<Warning> getWarnings() const
{
return warnings;
}
Token nextToken();
Token scanNumber();
Token scanString();
Token scanRawString();
Token scanMultilineString();
Token scanIdentifier();
Token scanSymbol();
Token scanComments();
};
} // namespace Fig