Skip to content

PriyanshuSharma23/tt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tt — Tiny Template Transpiler

Overview

tt is a tiny C++ utility that converts .h.tt template files into .h files by alternating between raw byte output and inline C/C++ code.

It is designed for generating C/C++ source or headers that embed raw data safely as byte strings while still allowing logic, macros, or hand-written code inline.

Core Idea

  • % is used as a mode toggle
  • Text outside % blocks is treated as raw data
  • Text inside % blocks is treated as C/C++ code
  • Raw data is emitted as escaped hex bytes via an OUT() macro
RAW TEXT % C/C++ CODE % MORE RAW TEXT

Example

Input (index.h.tt)

Hello world
%
// some C/C++ code
#define X 42
%
Goodbye

Output (index.h)

OUT("\x48\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64\x0a", 12);
// some C/C++ code;
OUT("\x47\x6f\x6f\x64\x62\x79\x65", 7);
  • Raw text is converted to \xNN byte sequences
  • Code blocks are copied verbatim (with ; appended)

Building

make build

This produces:

./bin/tt

Usage

./bin/tt index.h.tt
  • Input files must end with .tt
  • Output file name is derived by stripping the suffix
index.h.tt → index.h

Template Rules

  • % toggles between data mode and code mode
  • Processing starts in data mode
  • Every % flips the mode
  • No nesting — intentionally simple

Requirements

  • C++17-compatible compiler
  • Tested with g++

Assumptions

  • An OUT(const char*, size_t) macro or function exists
  • Newlines are preserved as raw bytes
  • No attempt is made to be clever or safe beyond byte-accuracy

Philosophy

  • Small
  • Predictable
  • Hackable
  • Build-system friendly

If it feels like something you’d write at 2am inside Emacs, it’s working.

License

Do whatever you want. If it breaks, you get to keep both pieces.

About

Tiny C++ template transpiler that converts .h.tt templates into .h files by embedding raw data as hex byte strings and allowing inline C/C++ code blocks.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors