On this page:
Rhombus Metaprogramming Tutorial
8.18

Rhombus Metaprogramming Tutorial🔗ℹ

This tutorial is about syntax and macros in Rhombus. It’s intended for readers who are familiar with environment-passing interpreters, but only because interpreters serve as a stand-in for useful applications, and interpreters are not the kind of metaprogramming that the tutorial is about. The tutorial doesn’t assume that you’ve used Rhombus before, but it also doesn’t dwell much on the everyday-programming part of the language. Instead, the tutorial aims to introduce the nuts and bolts of Rhombus’s approach to parsing, syntactic extension, and language creation.

    Setup

    1 New to Rhombus

      1.1 Exercise

      1.2 Exercise

      1.3 Exercise

    2 Shrubbery Notation

      2.1 S-Expressions as Inspiration

      2.2 Shrubbery Goals

      2.3 Shrubbery Abstract Syntax

      2.4 Shrubbery Syntax Details

        2.4.1 Separators and Terminators

        2.4.2 Required and Optional Newlines

        2.4.3 Indentation Rules and Variations

        2.4.4 Two More Tricks

      2.5 Exercise

    3 Post-Shrubbery Parsing

      3.1 Patterns and Templates

      3.2 Shorthands and Syntax Classes

      3.3 Parsing-Time Expressions

      3.4 Definition Macros

      3.5 Exercise

    4 Enforestation

      4.1 Defining Operators

      4.2 Expression Macros

      4.3 Exercise

      4.4 Exercise

    5 Spaces

      5.1 Binding Macros

      5.2 Parsing in Specific Spaces

      5.3 Macro Patterns

      5.4 Exercise

      5.5 Exercise

    6 Implicit Forms

      6.1 Exercise

    7 Whole Languages

      7.1 Modules and Macros

      7.2 Modules and Spaces

      7.3 Modules and Languages

      7.4 Exercise