Lifecycle hooks allow you to embed JavaScript in various parts of the generated parser, enabling you to run custom logic at specific events in the parser's lifecycle. The syntax is simple:

on:lifecycle {
    // Your JavaScript here
} 

Example:

on:import {
    let parses = 0;

    export function GetParseCount(){
        return parses;
    }
}

on:new {
    parses++;
}

Lifecycle Hooks

NameDescription
importWhen the grammar is loaded
newWhenever a new parser is initialized

More lifecycle hooks may be added in future versions.