lifter

Lifts compile-time object to AST

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.2.3
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:26

Authors

  • savannt

Installation

nimble install lifter
choosenim install lifter
git clone https://github.com/thing-king/lifter

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
lifter - - - - - - -

Dependencies

Package Version Optional
nim >= 1.0.0 No

Source

Repository https://github.com/thing-king/lifter
Homepage https://github.com/thing-king/lifter
Registry Source nimble_official

README

lifter

Converts compile-time type instances to their Nim literal constructor syntax for macro code generation.

Example

type Person = object
  name: string
  age: int

import pkg/lifter

macro buildPerson(): untyped =
  # Create an instance at compile-time
  let someone = Person(name: "Alice", age: 30)
  # Convert it to AST syntax: Person(name: "Alice", age: 30)
  result = someone.lift()

let alice = buildPerson()
echo alice  # Person(name: "Alice", age: 30)

What it does

Takes a type instance that exists at compile-time (in a macro) and generates the Nim source code needed to construct it. This is useful for:

  • Embedding compile-time computed values into generated code
  • Code generation from configuration objects
  • Macro-based serialization/deserialization

API

proc toNimLiteral*[T](x: T): string
  # Converts a value to its Nim literal string representation
  # Example: Point(x: 10, y: 20) -> "Point(x: 10, y: 20)"

proc lift*[T](item: T): NimNode
  # Converts a value directly to a NimNode
  # Equivalent to: parseExpr(item.toNimLiteral)

No macro invocation needed! Just call lift() or toNimLiteral() directly on any type.

Supported Types

  • ✅ Objects, ref objects, ptr objects
  • ✅ Strings (with proper escaping)
  • ✅ Sequences
  • ✅ Primitives (int, float, bool, etc.)
  • ❌ NimNode (raises ValueError)

Roadmap

  • [ ] Support for tables/sets
  • [ ] Support for tuples
  • [ ] Reverse lifting (AST → object instances)
  • [ ] Custom serialization hooks