Refactor: 重构Parser和AST结构,以支持新的语言特性
- 更新了 ParserTest,以改进文件路径处理和输出格式。 - 在 StmtParser 中新增了 parseConstDecl 和 parseForStmt 方法,用于处理常量声明和 for 循环。 - TypeExpr现归类为Expr。TypeExpr属于Expr,语义阶段视为Expr - 添加了新的 AST 节点:PostfixExpr、TernaryExpr、ForStmt 和 ImportStmt,用于表示新的语法结构。
This commit is contained in:
33
src/Ast/Stmt/ImportStmt.hpp
Normal file
33
src/Ast/Stmt/ImportStmt.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
@file src/Ast/Stmt/ImportStmt.hpp
|
||||
@brief import
|
||||
@author PuqiAR (im@puqiar.top)
|
||||
@date 2026-06-06
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Ast/Base.hpp>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
struct ImportStmt final : public Stmt
|
||||
{
|
||||
String path;
|
||||
bool isFileImport;
|
||||
|
||||
ImportStmt() { type = AstType::ImportStmt; }
|
||||
|
||||
ImportStmt(String _path, bool _isFileImport, SourceLocation _loc) :
|
||||
path(std::move(_path)), isFileImport(_isFileImport)
|
||||
{
|
||||
type = AstType::ImportStmt;
|
||||
location = std::move(_loc);
|
||||
}
|
||||
|
||||
virtual String toString() const override
|
||||
{
|
||||
return std::format("<ImportStmt '{}'{}>", path, isFileImport ? " [file]" : "");
|
||||
}
|
||||
};
|
||||
} // namespace Fig
|
||||
Reference in New Issue
Block a user