Bobe

raw JSON →
0.0.47 verified Fri May 01 auth: no javascript

Bobe is a template runtime compiler that parses a custom indentation-based template syntax into an AST. Current stable version is 0.0.47. It is a niche, experimental tool for generating structured node trees from a compact DSL, with typed output. Unlike general-purpose template engines like Handlebars or EJS, Bobe focuses on a unique indentation-aware syntax with key-value attributes and nested children.

error SyntaxError: Unexpected token at line 3: expected indent
cause Indentation is inconsistent or uses non-space characters.
fix
Use a consistent number of spaces (e.g., 2 spaces per level) and avoid tabs.
error TypeError: compiler.program is not a function
cause Import of Compiler is incorrect (e.g., default import instead of named).
fix
Use import { Compiler } from 'bobe'.
gotcha The template syntax requires proper indentation with spaces; tabs may not be supported.
fix Use spaces for indentation consistently.
breaking In v0.0.47, the Compiler constructor expects a string, but the program() method may throw if the template is malformed.
fix Wrap in try-catch or validate template before parsing.
gotcha The '|' pipe prefix is used for props on the same line as a node; forgetting the pipe causes props to be parsed incorrectly.
fix Ensure that props on a separate line from the node name begin with '|'.
npm install bobe
yarn add bobe
pnpm add bobe

Parses a sample template string into an AST using the Bobe compiler.

import { Compiler } from 'bobe';

const template = `
node1 k1=1
  node1_1 k2=2 k3=3
node2
| p1=1
| p2=2 p3=3
  node2_1
  | p4=4 p5=5 p6=6
`;

const compiler = new Compiler(template);
const ast = compiler.program();
console.log(JSON.stringify(ast, null, 2));