Tree sitter textwire

The tree-sitter parser for Textwire, dynamic templating and scripting language for Go. Ideal for embedding dynamic content with Go applications

Tree Sitter Parser for Textwire

This is a Tree-sitter parser for Textwire templating language for Go.

Commands

Command Description
make test Generate grammar and run all tests
npm run tree-sitter -- test --filter "test name" Run single test by name
make parse Parse the example.tw file
make generate Generate C parser from grammar.js
make compile Compile parser into textwire.so

Structure

  • grammar.js - Grammar definition using Tree-sitter DSL
  • src/scanner.c - External scanner for text tokenization
  • src/parser.c - Generated C parser (do not edit)
  • test/corpus/ - Test cases in Tree-sitter format
  • example.tw - Contains Textwire syntax examples for manual testing (use with make parse)

External Scanner

Handles TEXT tokens and detects:

  • Directives starting with @ (e.g., @if, @for)
  • Brace statements {{ }}
  • _OPEN_PAREN - Hidden external token to disambiguate @slot from @slot('name')

Tests

Test format in test/corpus/*.txt:

==================
Test description
==================
Input text
---

(expected parse tree)

NPM Commands

Install Dependencies

Run the following command to install the required NPM dependencies:

npm i

Available Make Commands

You can find Make commands in the Makefile in the root of the project.

Build the parser

Run the following command to build the parser:

make generate

Install / Setup tree sitter

Run the following command to install tree sitter:

make install

Test that everything works

Run the following command to test that everything works:

make test

Contribute

With a Container Engine

Build the Image

To build the image, run this command.

With Podman:

podman-compose build

With Docker:

docker compose build

Create node_modules

Run this command to install npm packages and generate a node_modules directory on your local machine.

With Podman:

podman-compose run --rm app npm i

With Docker:

docker compose run --rm app npm i

Enter the Container

To enter inside the container, run this command.

With Podman:

podman-compose run --rm app

With Docker:

docker compose run --rm app

You'll be able to run NPM commands inside of the container.

License

The Tree Sitter Textwire project is licensed under the MIT License