Tiramisu Docs

AST Overview

Explore the Tiramisu AST node types, structure, and how to work with parsed documents.

The Tiramisu parser (@timeleap/tiramisu) takes source text and produces an Abstract Syntax Tree (AST). The AST is a tree of typed nodes that represents the structure of your document.

Node Types

The AST consists of the following node types:

NodeDescription
TiramisuRoot node of the document. Contains all top-level nodes.
ParagraphA paragraph of text. Created by blank line separation.
MixedTextText that contains both plain text and function calls.
PureTextA plain text segment with no function calls.
FunctionCallA function call with a name and parameters.
ParametersThe parameter list of a function call.
ParameterA single positional parameter.
NamedParameterA named parameter (key = value).
ArrayValueAn array value ([a, b, c]).
ArrayItemA single item within an array.

Example

Given this Tiramisu source:

tiramisu
bold { Hello } world

The parser produces this AST:

typescript
Tiramisu
└── Paragraph
    └── MixedText
        ├── FunctionCall (name: "bold")
        │   └── Parameters
        │       └── Parameter
        │           └── PureText ("Hello")
        └── PureText (" world")

FunctionCall Structure

The FunctionCall node is the core of Tiramisu. It has:

  • functionName — the name of the function (text before the {)
  • parameters — a Parameters node containing the function's arguments

Parameters contain a list of Parameter and NamedParameter nodes. Each parameter can contain text, nested function calls, or arrays.

Importing Node Types

All node types are available from the parser package:

typescript
import {
  Tiramisu,
  Paragraph,
  MixedText,
  PureText,
  FunctionCall,
  Parameters,
  Parameter,
  NamedParameter,
  ArrayValue,
  ArrayItem,
} from "@timeleap/tiramisu/src/types/nodes";

Node type checking uses instanceof:

typescript
if (node instanceof FunctionCall) {
  console.log(node.functionName);
}