Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 752 Bytes

CodeTemplateModule.md

File metadata and controls

33 lines (25 loc) · 752 Bytes

CodeTemplate

Small library for support in place code generation. You can use this module independently from CodegenKit.

Usage

Write code as template with markers.

// Visitor.swift
class Visitor {
    ...
    // @codegen(visitImpl)
    func visitImpl(call: CallExpr) { ... }
    func visitImpl(ident: IdentExpr) { ... }
    // @end
}

Load code as template, edit, save.

let file = URL(fileURLWithPath: "Visitor.swift")
var template = try Template(file: file)
template["visitImpl"] = generateVisitImpl()
try template.description.write(to: file, atomically: true, encoding: .utf8)

Detail

CodeTemplate just split source file by lines. It doesn't see any syntax like comments, so it's target language agnostic.