🐉 cnsh 示例库

中文原生脚本 · 数学公式 · notion 数据库 · 一体化运行示例

dna: #龍芯⚡️丙午·甲午·庚辰·壬午·䷑蛊-cnsh-examples-page-v1.0
▶ 一键运行示例

cnsh 语法综合测试

覆盖:变量、运算符、if/elif/else、for/while、列表推导式、with、json、math、random、lambda、match/case、位运算、try/except/finally。

cnsh-core/cnsh-runtime/examples/cnsh_syntax_v1.1.cnsh
语法v1.1
打开 cnsh 编辑器

数学公式 + notion 一体化

演示 cnsh 运行时直接调用 longhun-math-formula-core 函数,并查询 notion db3367、同步种子模块。

cnsh-core/cnsh-runtime/examples/notion_math_bridge.cnsh
notion数学
打开 cnsh 编辑器

类 / 装饰器 / 生成器

覆盖:class 定义、继承与 super、@property / @classmethod / @staticmethod / @abstractmethod、生成器 yield / yield from / 生成器表达式、异常类。

cnsh-core/cnsh-runtime/examples/cnsh_class_decorator_generator.cnsh
oop装饰器生成器
打开 cnsh 编辑器

异步 / 上下文管理器 / 枚举 / 数据类

覆盖:async/await、async for/async with、@contextlib.contextmanager、enum.enum + @enum.unique、@dataclasses.dataclass、dataclasses.field。

cnsh-core/cnsh-runtime/examples/cnsh_async_enum_dataclass.cnsh
asyncwithenumdataclass
打开 cnsh 编辑器

类型注解 / 装饰器带参 / 完整异常

覆盖:函数签名类型注解、typing 泛型 / typevar / generic、自定义参数化装饰器、@functools.lru_cache、全中文异常类名(valueerror/keyerror/typeerror/...)、自定义异常继承。

cnsh-core/cnsh-runtime/examples/cnsh_advanced_syntax.cnsh
typingdecoratorexception
打开 cnsh 编辑器

🌌 bra-ket 人格协作量子语法

覆盖:人格基态声明、系统构建、任务测量、酉演化、协作概率读取、三色审计。cnsh v2.1 原生支持,编译后调用 longhun_braket 引擎。

cnsh-core/cnsh-v2.1/examples/braket_persona.cnsh
bra-ket人格协作量子语法三色审计
打开 cnsh 编辑器 打开 bra-ket 操作台
📝 示例代码速查
计数 = 10
计数 加等于 5
如果 计数 大于 10:
    打印("大于10")
否则:
    打印("小于等于10")

平方 = [x * x 对于 x 在 范围(10) 如果 x > 1]

使用 打开("test.txt", "w") 作为 f:
    f.写入("hello")

匹配 值:
    分支 1:
        打印("一")
    分支 _:
        打印("其他")

数据 = 查询数据库("3367125a9c9f808a9692f0c6752e92fa", 最大条数=5)
🛠 cli 运行方式
cd ~/longhun-system/cnsh-core/cnsh-v2.1
python3 run.py examples/braket_persona.cnsh --compile --target python --run-compiled

cd ~/longhun-system/cnsh-core/cnsh-runtime
python3 cnsh_runner.py examples/cnsh_syntax_v1.1.cnsh
python3 cnsh_runner.py examples/cnsh_class_decorator_generator.cnsh
python3 cnsh_runner.py examples/cnsh_async_enum_dataclass.cnsh
python3 cnsh_runner.py examples/cnsh_advanced_syntax.cnsh
python3 cnsh_runner.py examples/notion_math_bridge.cnsh