Sign in

    rinnein/moonata/ast does not have a README file

    Ast

    pub(all) enum Ast {
    String(String)
    QuotedName(String)
    Regex(pattern~ : String, flags~ : String)
    Number(Double)
    Boolean(Bool)
    Null
    Placeholder
    Path(Array[Step])
    Binary(op~ : String, lhs~ : Ast, rhs~ : Ast)
    Unary(op~ : String, expr~ : Ast)
    Conditional(condition~ : Ast, consequent~ : Ast, alternate~ : Ast?)
    Construct(Array[Ast])
    Group(Array[(Ast, Ast)])
    Sort(expr~ : Ast, terms~ : Array[SortTerm])
    Lambda(params~ : Array[String], body~ : Ast, signature~ : String?)
    Var(String)
    Bind(name~ : String, value~ : Ast)
    Apply(func~ : Ast, args~ : Array[Ast])
    Chain(Array[Ast])
    Block(Array[Ast])
    Transform(path~ : Ast, update~ : Ast, delete~ : Ast?)
    } derive(Eq,
    Debug
    )

    JSONata AST 节点:单一 enum + 标签字段。

    所有节点统一为 Ast enum,子结构 Step/SortTerm 独立定义。 路径访问统一用 Path(Array[Step]) 表示,Step 携带 StepKind 与 StepStage。

    Ast::path1

    fn Ast::path1(step : Step) -> Ast

    便捷构造单步路径。

    SortTerm

    pub(all) struct SortTerm {
    expr : Ast
    descending : Bool
    } derive(Eq,
    Debug
    )

    排序项:表达式 + 升降序标记。

    SortTerm::new

    fn SortTerm::new(expr : Ast, descending? : Bool) -> SortTerm

    构造排序项(默认升序)。

    Step

    pub(all) struct Step {
    kind : StepKind
    stage : StepStage
    focus : String?
    tuple : Bool
    index : Int?
    pos_var : String?
    } derive(Eq,
    Debug
    )

    路径步:由种类与阶段(单层/递归)组成。 focus 与 tuple 由 @ $var 标注:focus 绑定变量名,tuple 标记进入 tuple stream 模式。 index 仅在 stage=Recursive 时有效:表示 **.X[idx] 需对每个匹配项单独索引。 pos_var 由 # $var 标注:将迭代位置索引绑定到指定变量。

    Step::new

    fn Step::new(kind~ : StepKind, stage~ : StepStage, focus? : String?, tuple? : Bool, index? : Int?, pos_var? : String?) -> Step

    构造路径步。

    StepKind

    pub(all) enum StepKind {
    Name(String)
    Wildcard
    Index(Int)
    Slice(Int?, Int?)
    Eval(Ast)
    Filter(Ast)
    Map(Ast)
    GroupAggregate(Ast)
    Arrayify
    Parent
    } derive(Eq,
    Debug
    )

    路径步种类。

    StepStage

    pub(all) enum StepStage {
    Single
    Recursive
    } derive(Eq,
    Debug
    )

    路径步阶段:单层访问或递归降序(**)。

    arrayify_step

    fn arrayify_step() -> Step

    便捷构造空数组选择器 []。

    eval_step

    fn eval_step(expr : Ast) -> Step

    便捷构造路径基值求值步。

    map_step

    fn map_step(expr : Ast) -> Step

    便捷构造路径映射步 .(expr)。

    name_step

    fn name_step(name : String, recursive? : Bool) -> Step

    便捷构造名称步。

    parent_step

    fn parent_step() -> Step

    便捷构造父级访问步 %。

    wildcard_step

    fn wildcard_step(recursive? : Bool) -> Step

    便捷构造通配符步。

    Source Files