#Package: dart_ast

    Dart AST 节点定义(零依赖) | Dart AST node definitions (zero dependencies)

    #概述 | Overview

    定义 Dart 源码的抽象语法树(AST)节点类型,包括 Dart 类型、表达式、模式、声明、方法和变体。作为反向转换(Dart → MoonBit)的基础数据模型,同时提供 DartType → MoonBit 类型的反向映射。

    Defines abstract syntax tree (AST) node types for Dart source code, including Dart types, expressions, patterns, declarations, methods, and variants. Serves as the foundational data model for reverse conversion (Dart → MoonBit), and provides DartType → MoonBit type reverse mapping.

    #核心类型 | Core Types

    TypeDescription
    DartType[CN] Dart 类型节点(13 变体:基础类型 + 容器 + Nullable + Future + Result + Custom) / [EN] Dart type node (13 variants)
    DartExpr[CN] Dart 表达式节点(12 变体:字面量/变量/方法调用/函数调用/二元/条件/switch/await/箭头/null) / [EN] Dart expression node (12 variants)
    DartPattern[CN] Dart 模式节点(7 变体:变量/整数/字符串/通配/null/构造器) / [EN] Dart pattern node (7 variants)
    DartDecl[CN] Dart 声明节点(5 变体:顶层函数/async 函数/class/sealed class/abstract class) / [EN] Dart declaration node (5 variants)
    DartMethod[CN] Dart 方法定义 / [EN] Dart method definition
    DartVariant[CN] Dart sealed class 变体 / [EN] Dart sealed class variant

    #核心函数 | Core Functions

    FunctionSignatureDescription
    DartType::to_moon_stringDartType -> String[CN] Dart 类型 → MoonBit 类型字符串(aliased as dart_type_to_moon) / [EN] Dart type to MoonBit type string

    #依赖 | Dependencies

    • (零依赖 / Zero dependencies)

    #测试 | Tests

    • 白盒测试 / Whitebox: 14
    • 黑盒测试 / Blackbox: 0

    DartDecl

    pub(all) enum DartDecl {
    DTopFn(String, Array[String], Array[(String, DartType)], DartType, DartExpr)
    DAsyncTopFn(String, Array[String], Array[(String, DartType)], DartType, DartExpr)
    DClass(String, Array[String], Array[(String, DartType)], Array[DartMethod])
    DSealedClass(String, Array[DartVariant])
    DAbstractClass(String, Array[DartMethod])
    } derive(Compare, Eq,
    Debug
    )

    Dart 声明节点 — 表示 Dart 源码中的顶层声明 | Dart declaration node — represents top-level declarations in Dart source

    DartDecl::compare

    fn DartDecl::compare(DartDecl, DartDecl) -> Int

    DartDecl::equal

    fn DartDecl::equal(DartDecl, DartDecl) -> Bool

    DartDecl::not_equal

    fn DartDecl::not_equal(x : DartDecl, y : DartDecl) -> Bool

    DartDecl::op_ge

    fn DartDecl::op_ge(x : DartDecl, y : DartDecl) -> Bool

    DartDecl::op_gt

    fn DartDecl::op_gt(x : DartDecl, y : DartDecl) -> Bool

    DartDecl::op_le

    fn DartDecl::op_le(x : DartDecl, y : DartDecl) -> Bool

    DartDecl::op_lt

    fn DartDecl::op_lt(x : DartDecl, y : DartDecl) -> Bool

    DartDecl::to_repr

    DartExpr

    pub(all) enum DartExpr {
    DIntLit(Int)
    DDoubleLit(Double)
    DBoolLit(Bool)
    DStringLit(String)
    DVarRef(String)
    DMethodCall(String, String, Array[DartExpr])
    DFunctionCall(String, Array[DartExpr])
    DBinOp(String, DartExpr, DartExpr)
    DIfExpr(DartExpr, DartExpr, DartExpr)
    DSwitchExpr(DartExpr, Array[(DartPattern, DartExpr)])
    DAwaitExpr(DartExpr)
    DArrowFn(Array[String], DartExpr)
    DNullLit
    } derive(Compare, Eq,
    Debug
    )

    Dart 表达式节点 — 表示 Dart 源码中的表达式 | Dart expression node — represents expressions in Dart source

    DartExpr::compare

    fn DartExpr::compare(DartExpr, DartExpr) -> Int

    DartExpr::equal

    fn DartExpr::equal(DartExpr, DartExpr) -> Bool

    DartExpr::not_equal

    fn DartExpr::not_equal(x : DartExpr, y : DartExpr) -> Bool

    DartExpr::op_ge

    fn DartExpr::op_ge(x : DartExpr, y : DartExpr) -> Bool

    DartExpr::op_gt

    fn DartExpr::op_gt(x : DartExpr, y : DartExpr) -> Bool

    DartExpr::op_le

    fn DartExpr::op_le(x : DartExpr, y : DartExpr) -> Bool

    DartExpr::op_lt

    fn DartExpr::op_lt(x : DartExpr, y : DartExpr) -> Bool

    DartExpr::to_repr

    DartMethod

    pub(all) struct DartMethod {
    name : String
    params : Array[(String, DartType)]
    ret_type : DartType
    body : DartExpr
    is_async : Bool
    } derive(Compare, Eq,
    Debug
    )

    Dart 方法 — 表示 class 中的方法定义 | Dart method — represents a method definition in a class

    DartMethod::compare

    fn DartMethod::compare(DartMethod, DartMethod) -> Int

    DartMethod::equal

    fn DartMethod::equal(DartMethod, DartMethod) -> Bool

    DartMethod::not_equal

    fn DartMethod::not_equal(x : DartMethod, y : DartMethod) -> Bool

    DartMethod::op_ge

    fn DartMethod::op_ge(x : DartMethod, y : DartMethod) -> Bool

    DartMethod::op_gt

    fn DartMethod::op_gt(x : DartMethod, y : DartMethod) -> Bool

    DartMethod::op_le

    fn DartMethod::op_le(x : DartMethod, y : DartMethod) -> Bool

    DartMethod::op_lt

    fn DartMethod::op_lt(x : DartMethod, y : DartMethod) -> Bool

    DartPattern

    pub(all) enum DartPattern {
    DPVar(String)
    DPInt(Int)
    DPString(String)
    DPWild
    DPNull
    DPCtor(String, Array[DartPattern])
    } derive(Compare, Eq,
    Debug
    )

    Dart 模式节点 — 表示 Dart 3 switch expression 中的模式 | Dart pattern node — represents patterns in Dart 3 switch expression

    DartPattern::compare

    fn DartPattern::compare(DartPattern, DartPattern) -> Int

    DartPattern::equal

    fn DartPattern::equal(DartPattern, DartPattern) -> Bool

    DartPattern::not_equal

    fn DartPattern::not_equal(x : DartPattern, y : DartPattern) -> Bool

    DartPattern::op_ge

    fn DartPattern::op_ge(x : DartPattern, y : DartPattern) -> Bool

    DartPattern::op_gt

    fn DartPattern::op_gt(x : DartPattern, y : DartPattern) -> Bool

    DartPattern::op_le

    fn DartPattern::op_le(x : DartPattern, y : DartPattern) -> Bool

    DartPattern::op_lt

    fn DartPattern::op_lt(x : DartPattern, y : DartPattern) -> Bool

    DartType

    pub(all) enum DartType {
    DInt
    DDouble
    DBool
    DString
    DRune
    DVoid
    DList(DartType)
    DMap(DartType, DartType)
    DSet(DartType)
    DNullable(DartType)
    DFuture(DartType)
    DResult(DartType, DartType)
    DCustom(String)
    } derive(Compare, Eq,
    Debug
    )

    Dart 类型节点 — 表示 Dart 源码中的类型 | Dart type node — represents types in Dart source

    DartType::compare

    fn DartType::compare(DartType, DartType) -> Int

    DartType::equal

    fn DartType::equal(DartType, DartType) -> Bool

    DartType::not_equal

    fn DartType::not_equal(x : DartType, y : DartType) -> Bool

    DartType::op_ge

    fn DartType::op_ge(x : DartType, y : DartType) -> Bool

    DartType::op_gt

    fn DartType::op_gt(x : DartType, y : DartType) -> Bool

    DartType::op_le

    fn DartType::op_le(x : DartType, y : DartType) -> Bool

    DartType::op_lt

    fn DartType::op_lt(x : DartType, y : DartType) -> Bool

    DartType::to_moon_string

    #as_free_fn(dart_type_to_moon)
    fn DartType::to_moon_string(self : DartType) -> String

    DartType → MoonBit 类型字符串表示 | DartType to MoonBit type string representation

    DartType::to_repr

    DartVariant

    pub(all) struct DartVariant {
    name : String
    fields : Array[(String, DartType)]
    } derive(Compare, Eq,
    Debug
    )

    Dart 变体 — 表示 sealed class 的子类 | Dart variant — represents a subclass of a sealed class

    DartVariant::compare

    fn DartVariant::compare(DartVariant, DartVariant) -> Int

    DartVariant::equal

    fn DartVariant::equal(DartVariant, DartVariant) -> Bool

    DartVariant::not_equal

    fn DartVariant::not_equal(x : DartVariant, y : DartVariant) -> Bool

    DartVariant::op_ge

    fn DartVariant::op_ge(x : DartVariant, y : DartVariant) -> Bool

    DartVariant::op_gt

    fn DartVariant::op_gt(x : DartVariant, y : DartVariant) -> Bool

    DartVariant::op_le

    fn DartVariant::op_le(x : DartVariant, y : DartVariant) -> Bool

    DartVariant::op_lt

    fn DartVariant::op_lt(x : DartVariant, y : DartVariant) -> Bool

    Source Files