Luke 4b90f15371 test: 添加自定义类型字段嵌套示例
- 新增 Main.snow 文件,定义了 Address 和 Person 两个结构体- 在 Person 结构体中使用 Address 类型的字段,实现类型嵌套
- 添加 OS.snow 文件,提供基本的打印功能- 此示例展示了如何在 SNOBOL 中使用自定义类型进行字段嵌套
2025-08-30 14:25:11 +08:00

46 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module: Main
// 一个很简单的结构体,只有内建类型字段
struct: Address
fields:
declare country: string
declare city: string
// 构造函数(可要可不要,不影响触发点)
init:
params:
country: string
city: string
body:
this.country = country
this.city = city
end body
end init
end struct
// 在这里做“嵌套字段”Person.addr 的类型是 Address
struct: Person
fields:
declare name: string
declare addr: Address // ← 触发点:自定义类型出现在字段类型位置
// 可选构造(同样不影响触发点)
init:
params:
name: string
addr: Address
body:
this.name = name
this.addr = addr
end body
end init
end struct
// 主函数可以是空体,避免其它解析干扰
function: main
returns: void
body:
// 什么都不做;关键在于上面的“嵌套字段”声明
end body
end function
end module