Expose the parsed expression tree from Program (for explain/trace tooling, linting and sub-expression evaluation)
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 45/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
调研方向
先检查 Python Program wrapper 和 cel::Program::expression(),然后将其 IdedExpr 和 Expr 变体与提议的可序列化为 JSON 的树进行比较。当 Program.ast() 暴露字面量、标识符、select、调用、列表、映射、struct 和展开后的 comprehension,并提供与 cel-rust 版本关联的临时文档时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Motivation
Program.references() answers "which names does this expression use", but several things people ask for need the structure of the expression, not just its leaves:
- #30 wants to know which element or clause made an
exists/&&chain true or false. cel-rust has no evaluation hooks, so a wrapper-sideexplain()would have to walk the tree and re-evaluate sub-expressions. - Policy linting beyond name lists: "no
matches()on untrusted input", "no more than N nested comprehensions", "field access only underrequest.". - Pretty-printing / normalising expressions stored by users.
What upstream gives us
cel::Program::expression() returns the parsed Expression (IdedExpr: an id plus an Expr enum covering literals, identifiers, selects, calls, lists, maps, structs and the expanded comprehensions). No protobuf AST, but the shape is close to cel.expr.Expr and would be straightforward to mirror as nested dicts or small dataclasses.
Proposal
Program.ast() returning a plain, JSON-serialisable tree, e.g. {"kind": "call", "function": "_&&_", "args": [...]}, with comprehension macros shown in their expanded form (that is what cel-rust holds after parsing; the original macro call is not retained). Ship it as provisional, tied to the cel-rust version, and note that the node shapes may change when cel-rust changes its AST.
A Python-side cel.explain(program, context) built on it could then evaluate each boolean sub-expression and report the first failing clause, which covers the exists/all case in #30 without upstream changes, at the cost of re-evaluation (custom functions run again).
- 主要语言
- Python
- 星标
- 43
- 派生
- 4
- 平均合并
- 9 小时 57 分钟
- 30 天内合并 PR
- 14
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
hardbyte/python-common-expression-language 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
-
enhancement
难度 4/5 3-5 天 新手友好度 45/100
-
难度 5/5 一周以上 新手友好度 35/100
-
enhancement
难度 4/5 3-5 天 新手友好度 48/100
-
enhancement
难度 4/5 3-5 天 新手友好度 48/100
查看 hardbyte/python-common-expression-language 的全部 Issue
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·