pub struct SwiftBackend {
pub emit_public: bool,
pub emit_comments: bool,
/* private fields */
}Expand description
Swift code generation backend.
Compiles LCNF declarations/expressions to valid Swift source code. Entry points:
SwiftBackend::compile_module— compile a completeLcnfDeclcollectionSwiftBackend::compile_decl— compile a singleLcnfDeclSwiftBackend::compile_expr— compile anLcnfExprSwiftBackend::mangle_name— escape an OxiLean identifier for Swift
Fields§
§emit_public: boolWhether to emit public declarations
emit_comments: boolWhether to emit inline comments
Implementations§
Source§impl SwiftBackend
impl SwiftBackend
Sourcepub fn mangle_name(name: &str) -> String
pub fn mangle_name(name: &str) -> String
Mangle an OxiLean name into a valid Swift identifier.
Rules:
- Empty input →
"ox_empty" - Swift keywords → prefixed with
ox_ - Leading digit → prefixed with
ox_ - Non-alphanumeric / non-underscore characters → replaced with
_
Sourcepub fn compile_arg(&self, arg: &LcnfArg) -> SwiftExpr
pub fn compile_arg(&self, arg: &LcnfArg) -> SwiftExpr
Compile an LCNF argument to a Swift expression.
Sourcepub fn compile_lit(&self, lit: &LcnfLit) -> SwiftExpr
pub fn compile_lit(&self, lit: &LcnfLit) -> SwiftExpr
Compile an LCNF literal to a Swift expression.
Sourcepub fn compile_expr(&self, expr: &LcnfExpr) -> Vec<SwiftStmt>
pub fn compile_expr(&self, expr: &LcnfExpr) -> Vec<SwiftStmt>
Compile an LCNF expression to a list of Swift statements.
The final statement is always a return.
Sourcepub fn compile_let_value(&self, value: &LcnfLetValue) -> SwiftExpr
pub fn compile_let_value(&self, value: &LcnfLetValue) -> SwiftExpr
Compile a let-value to a Swift expression.
Sourcepub fn compile_decl(&self, decl: &LcnfFunDecl) -> SwiftFunc
pub fn compile_decl(&self, decl: &LcnfFunDecl) -> SwiftFunc
Compile a single LCNF function declaration to a SwiftFunc.
Sourcepub fn compile_lcnf_type(&self, ty: &LcnfType) -> SwiftType
pub fn compile_lcnf_type(&self, ty: &LcnfType) -> SwiftType
Map an LCNF type to the closest Swift type.
Sourcepub fn compile_module(&self, name: &str, decls: &[LcnfFunDecl]) -> SwiftModule
pub fn compile_module(&self, name: &str, decls: &[LcnfFunDecl]) -> SwiftModule
Compile a collection of LCNF declarations into a SwiftModule.
Sourcepub fn emit_module(&self, module: &SwiftModule) -> String
pub fn emit_module(&self, module: &SwiftModule) -> String
Emit a SwiftModule to a Swift source string.
Sourcepub fn emit_func(&self, func: &SwiftFunc) -> String
pub fn emit_func(&self, func: &SwiftFunc) -> String
Emit a single SwiftFunc to a Swift source string.
Sourcepub fn emit_type_decl(&self, decl: &SwiftTypeDecl) -> String
pub fn emit_type_decl(&self, decl: &SwiftTypeDecl) -> String
Emit a single SwiftTypeDecl to a Swift source string.