feat: 在解析器中实现 Lambda 和 new 表达式

- 增加了对 Lambda 表达式的初步解析支持,包括参数处理和返回类型。Lambda闭包尚未支持。
- 引入了用于对象初始化的新的表达式,支持可选的命名参数。
- 改进了表达式语法错误的错误报告。
- 更新了解析器和分析器以处理新的表达式类型并验证其语义。
- 修改了现有测试以涵盖新功能并确保其正确性。
- 改进了各种解析和语义错误的诊断。
This commit is contained in:
2026-04-12 10:07:51 +08:00
parent 570a87c3cd
commit fafa2b4946
24 changed files with 925 additions and 140 deletions

View File

@@ -138,9 +138,12 @@ namespace Fig
manager.LoadFromMemory(sourceCode);
Lexer lexer(sourceCode, "");
Parser parser(lexer, manager, "");
// 1. 语法检查拦截
Diagnostics diagnostics;
Parser parser(lexer, manager, "", diagnostics);
// 语法检查拦截
auto parserResult = parser.Parse();
if (!parserResult)
{
@@ -148,6 +151,11 @@ namespace Fig
return;
}
for (auto &diag : diagnostics.GetErrors())
{
SendDiagnostics(uri, &diag);
}
Program *program = *parserResult;
Analyzer analyzer(manager);
@@ -160,7 +168,12 @@ namespace Fig
return;
}
// 3. 一切完美,发射空数组清空过去的错误红线
for (auto &diag : analyzer.GetDiagnostics().GetErrors())
{
SendDiagnostics(uri, &diag);
}
// 一切完美,发射空数组清空过去的错误红线
SendDiagnostics(uri, nullptr);
}
};