Golden

Systems & Software

<- WebcornGDSL ->

TwigSnap

TwigSnap is a dialect of Acorn_script that introduces html emission behaviour, request handeling, and the RUN protocal.

It's what I program websites like this in.

source

Basics

TwigSnap has the same syntax as Acorn_script, but introduces new scoped keywords like div, text, input, which resolve as function calls.

I could explain it in depth, but I feel like just looking at the code for this website is more informative.Or my current project if you want a more complete and complex application.

Subemit

TwigSnap emits HTML by running an htmlemitting stage, each scoped keyword uses subemit to traverse its children and construct a stack of properties.

Since TwigSnap is just Acorn_script but more, all normal variables, functions, and control flows still work during this stage. If a type has no htmlemitting handler it defaults to its x stage handler.

Inlined

Inlined is a TwigSnap keyword that essentially just makes a function call, at this stage there's no real difference between void and inlined, but in the future I can add optimizations here.

Template

A function call which can preserve its scope, if it isn't declared as stateless. This was more prominent before I started liking statless more.

Capture

A keyword which emits a string pointing to itself and a list of its arguments as strings. It can also be signaled to instead run itself when called like a function call.

Because nodes have a persistent identity they can be serialized and called back, and even preserved across restarts by having the subunit re-adopt the Ptr.

Captures can also execute JavaScript code on the client.

RUN protocal

This is what captures emit as strings, on the TwigSnap end it is decoded into a Node to execute like a function call with arguments, on the JavaScript side it can be interpreted as fragment swaps and code to eval.

I prefer to push behaviour into JavaScript on the client to save roundtripping when it's a presentation concern. Though TwigSnap can very much operate server-side.