Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add custom hook support #635

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

[FEATURE] Add custom hook support #635

wants to merge 7 commits into from

Conversation

TungstnBallon
Copy link
Contributor

Closes #633.

This PR adds hook functionality to the Jayvee interpreter. Hooks are custom functions that are automatically executed before / after blocks. See the PreBlockHook and PostBlockHook types for such a functions signature.

Library users can add hooks with the addHook method:

const program = /* parse program ...*/;

const before: PreBlockHook = (blocktype, input, context) => { /* ... */ };
program.addHook('preBlock', before, { blocking: true });

const after: PostBlockHook = (blocktype, input, context, output) => { /* ... */ };
program.addHook('postBlock', after);  // Options can be omitted. Non-blocking is the default

// interpret model ...

@TungstnBallon TungstnBallon requested a review from joluj January 10, 2025 13:38
@TungstnBallon TungstnBallon self-assigned this Jan 10, 2025
@TungstnBallon TungstnBallon added the enhancement New feature or request label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add custom hook support
1 participant