- lexer / parser(递归下降)/ evaluate / static-check,四文件纯函数,零 IO 零外部调用 - 子集封顶(ADR-006):比较 · 逻辑 · 算术 · 区间(开闭四态)· 列表与 in · 封闭内建函数集(字符串 / 数字 / 日期);未知函数一律拦下 - 单元格谓词(DMN 一格):`-` 任意 / 比较 / 区间 / 逗号析取 - staticCheck 给「画图即校验」用:语法 + 未知函数 + 引用路径清单 - app 侧以它替下 passthroughEvaluator:监听内容条件真求值,求值异常按不命中处置并留痕 32 个 sfeel 测试;全仓 182 个测试通过,门禁五道全绿 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
/**
|
|
* S-FEEL 子集的抽象语法树(编码规范 §8.3)。
|
|
* AST 是可 diff、可静态检查的中间形态 —— 前端画布的即时校验与后端裁决同源。
|
|
*/
|
|
|
|
export type Node =
|
|
| { readonly kind: 'literal'; readonly value: number | string | boolean | null }
|
|
| { readonly kind: 'path'; readonly segments: readonly string[] }
|
|
| { readonly kind: 'unary'; readonly op: '-' | 'not'; readonly operand: Node }
|
|
| {
|
|
readonly kind: 'binary';
|
|
readonly op: '+' | '-' | '*' | '/' | '=' | '!=' | '<' | '<=' | '>' | '>=' | 'and' | 'or';
|
|
readonly left: Node;
|
|
readonly right: Node;
|
|
}
|
|
| { readonly kind: 'list'; readonly items: readonly Node[] }
|
|
| {
|
|
readonly kind: 'range';
|
|
readonly startOpen: boolean;
|
|
readonly endOpen: boolean;
|
|
readonly start: Node;
|
|
readonly end: Node;
|
|
}
|
|
| { readonly kind: 'in'; readonly value: Node; readonly candidates: Node }
|
|
| { readonly kind: 'call'; readonly name: string; readonly args: readonly Node[] };
|
|
|
|
/** 单元格谓词(DMN 决策表的一格):`-` 任意、`<10`、`[1..5]`、`"A","B"` 析取 */
|
|
export type UnaryTest =
|
|
| { readonly kind: 'any' }
|
|
| { readonly kind: 'compare'; readonly op: '=' | '!=' | '<' | '<=' | '>' | '>='; readonly operand: Node }
|
|
| { readonly kind: 'range'; readonly node: Extract<Node, { kind: 'range' }> }
|
|
| { readonly kind: 'disjunction'; readonly tests: readonly UnaryTest[] };
|