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
Name | Description |
---|---|
import | When the grammar is loaded |
new | Whenever a new parser is initialized |
More lifecycle hooks may be added in future versions.