feat: 支持结构体继承
- 添加对结构体继承的支持,允许使用 "extends" 关键字定义父结构体 - 修改 StructNode 构造函数以支持父结构体名称参数 - 优化结构体解析逻辑,处理可选的继承语句
This commit is contained in:
parent
426452f63f
commit
d258297609
@ -53,6 +53,14 @@ public class StructParser implements TopLevelParser {
|
|||||||
ts.expect("struct");
|
ts.expect("struct");
|
||||||
ts.expect(":");
|
ts.expect(":");
|
||||||
String structName = ts.expectType(TokenType.IDENTIFIER).getLexeme();
|
String structName = ts.expectType(TokenType.IDENTIFIER).getLexeme();
|
||||||
|
|
||||||
|
// 解析可选 extends
|
||||||
|
String parentName = null;
|
||||||
|
if ("extends".equals(ts.peek().getLexeme())) {
|
||||||
|
ts.expect("extends");
|
||||||
|
parentName = ts.expectType(TokenType.IDENTIFIER).getLexeme();
|
||||||
|
}
|
||||||
|
|
||||||
ts.expectType(TokenType.NEWLINE);
|
ts.expectType(TokenType.NEWLINE);
|
||||||
|
|
||||||
/* -------- 初始化容器 -------- */
|
/* -------- 初始化容器 -------- */
|
||||||
@ -112,7 +120,7 @@ public class StructParser implements TopLevelParser {
|
|||||||
ts.expect("end");
|
ts.expect("end");
|
||||||
ts.expect("struct");
|
ts.expect("struct");
|
||||||
// 返回完整结构体 AST 节点
|
// 返回完整结构体 AST 节点
|
||||||
return new StructNode(structName, fields, init, methods,
|
return new StructNode(structName, parentName, fields, init, methods,
|
||||||
new NodeContext(line, col, file));
|
new NodeContext(line, col, file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user