cbuilder.nim 467 B

1234567891011121314151617181920
  1. type
  2. Snippet = string
  3. Builder = string
  4. template newBuilder(s: string): Builder =
  5. s
  6. proc addField(obj: var Builder; field: Snippet;) =
  7. obj.add field
  8. obj.add ";\n"
  9. template withStruct(obj: var Builder; structOrUnion: string; name: string; inheritance: string; body: typed) =
  10. if inheritance.len > 0:
  11. obj.add "$1 $2 : public $1 {$n" % [structOrUnion, name, inheritance]
  12. else:
  13. obj.add "$1 $2 {$n" % [structOrUnion, name]
  14. body
  15. obj.add("};\n")