improve ast
This commit is contained in:
+1655
-1857
File diff suppressed because it is too large
Load Diff
@@ -126,8 +126,8 @@ namespace lsp::language::ast
|
||||
void VisitRepeatStatement(RepeatStatement& node) override;
|
||||
void VisitCaseStatement(CaseStatement& node) override;
|
||||
void VisitTryStatement(TryStatement& node) override;
|
||||
void VisitBreakStatement(BreakStatement& node) override;
|
||||
void VisitContinueStatement(ContinueStatement& node) override;
|
||||
void VisitBreakStatement(BreakStatement&) override;
|
||||
void VisitContinueStatement(ContinueStatement&) override;
|
||||
void VisitReturnStatement(ReturnStatement& node) override;
|
||||
void VisitUsesStatement(UsesStatement& node) override;
|
||||
void VisitFunctionDefinition(FunctionDefinition& node) override;
|
||||
@@ -138,6 +138,7 @@ namespace lsp::language::ast
|
||||
void VisitFieldDeclaration(FieldDeclaration& node) override;
|
||||
void VisitUnpackPattern(UnpackPattern& node) override;
|
||||
void VisitTSSQLExpression(TSSQLExpression& node) override;
|
||||
void VisitMatrixIterationStatement(MatrixIterationStatement& node) override;
|
||||
|
||||
private:
|
||||
std::ostream& os_;
|
||||
@@ -163,6 +164,7 @@ namespace lsp::language::ast
|
||||
void PrintNodeHeader(const std::string& type_name, const Location& loc);
|
||||
void PrintLocation(const Location& loc);
|
||||
void PrintSourceSnippet(const Location& loc);
|
||||
void PrintKeyValue(const std::string& key, const std::string& value, const Location& location, const char* value_color);
|
||||
void PrintKeyValue(const std::string& key, const std::string& value, const char* value_color = nullptr);
|
||||
void PrintKeyValue(const std::string& key, int value);
|
||||
void PrintKeyValue(const std::string& key, bool value);
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 颜色定义
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 测试的可执行文件路径
|
||||
TEST_AST="./test_ast"
|
||||
|
||||
# 需要测试的目录列表(可以自行添加)
|
||||
DIRECTORIES=(
|
||||
"./tests"
|
||||
"./examples"
|
||||
"./samples"
|
||||
# 在这里添加更多目录
|
||||
# "./another_directory"
|
||||
)
|
||||
|
||||
# 检查test_ast是否存在
|
||||
if [ ! -f "$TEST_AST" ]; then
|
||||
echo -e "${RED}错误: 找不到 test_ast 可执行文件${NC}"
|
||||
echo "请确保 test_ast 在当前目录下,或修改脚本中的 TEST_AST 变量"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 统计变量
|
||||
total_files=0
|
||||
tested_files=0
|
||||
failed_files=0
|
||||
|
||||
echo -e "${BLUE}========================================${NC}"
|
||||
echo -e "${BLUE}开始测试 TSF 文件${NC}"
|
||||
echo -e "${BLUE}========================================${NC}"
|
||||
echo ""
|
||||
|
||||
# 遍历每个目录
|
||||
for dir in "${DIRECTORIES[@]}"; do
|
||||
if [ ! -d "$dir" ]; then
|
||||
echo -e "${YELLOW}警告: 目录不存在: $dir${NC}"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}扫描目录: $dir${NC}"
|
||||
|
||||
# 递归查找所有.tsf文件
|
||||
while IFS= read -r -d '' file; do
|
||||
((total_files++))
|
||||
|
||||
echo -e "${YELLOW}[测试]${NC} $file"
|
||||
|
||||
# 运行test_ast,隐藏输出
|
||||
if "$TEST_AST" "$file" > /dev/null 2>&1; then
|
||||
((tested_files++))
|
||||
echo -e "${GREEN} ✓ 通过${NC}"
|
||||
else
|
||||
((failed_files++))
|
||||
echo -e "${RED} ✗ 失败${NC}"
|
||||
echo -e "${RED}========================================${NC}"
|
||||
echo -e "${RED}测试失败: $file${NC}"
|
||||
echo -e "${RED}========================================${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
done < <(find "$dir" -type f -name "*.tsf" -print0 | sort -z)
|
||||
|
||||
echo ""
|
||||
done
|
||||
|
||||
# 打印总结
|
||||
echo -e "${BLUE}========================================${NC}"
|
||||
echo -e "${GREEN}所有测试完成!${NC}"
|
||||
echo -e "${BLUE}========================================${NC}"
|
||||
echo -e "总文件数: $total_files"
|
||||
echo -e "已测试: $tested_files"
|
||||
echo -e "失败: $failed_files"
|
||||
|
||||
if [ $failed_files -eq 0 ]; then
|
||||
echo -e "${GREEN}✓ 全部通过${NC}"
|
||||
exit 0
|
||||
else
|
||||
echo -e "${RED}✗ 存在失败${NC}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,20 +1,10 @@
|
||||
var d, e: boolean;
|
||||
global c, d;
|
||||
static e, f;
|
||||
const a: boolean = false;
|
||||
function f1(a: string; b: boolean = true): integer;
|
||||
begin
|
||||
end;
|
||||
|
||||
var a, b: boolean := true;
|
||||
static d := "abc";
|
||||
global c := 123456;
|
||||
// e := f1();
|
||||
|
||||
// function f1(a: string; b: boolean = true): integer;
|
||||
// begin
|
||||
// end;
|
||||
|
||||
// function f2(a, b, c);overload;
|
||||
// begin
|
||||
// end;
|
||||
function f2(a, b, c);overload;
|
||||
begin
|
||||
end;
|
||||
|
||||
// var d := 1;
|
||||
// c := false;
|
||||
|
||||
Reference in New Issue
Block a user