interp: add stmt, subshell, builtin, func-call, and var-lookup handlers#1331
Open
saracen wants to merge 1 commit into
Open
interp: add stmt, subshell, builtin, func-call, and var-lookup handlers#1331saracen wants to merge 1 commit into
saracen wants to merge 1 commit into
Conversation
ExecHandlers already lets external code wrap external command execution. Apply the same middleware-chain pattern to five more dispatch points so the interpreter can be extended from outside without patching its internals. StmtHandlers fires around every syntax.Stmt before dispatch. SubshellHandlers fires around each subshell creation site, with a SubshellKind to distinguish background, paren, cmd subst, proc subst, and pipeline. BuiltinHandler registers a name-keyed override for a builtin; BuiltinHandlers wraps all builtin dispatch with middleware. FuncCallHandlers wraps the body of a declared shell function. LookupVarHandlers wraps lookupVar on top of the runner's own special-variable and environment resolution, so middlewares can add or override variables without losing the existing behaviour. Each chain follows ExecHandlers' shape: middlewares are chained first-to-last, the bottom of the chain is the runner's own behaviour, and a middleware may short-circuit by not calling next. Chain bottoms recover the active runner from ctx, so the chains are built once in Reset and inherited by subshell copies the same way execHandler is. Also add RunStmts, a top-level helper for dispatching stmts on the runner attached to ctx, useful for handlers that need to execute shell code in the runner's current scope (e.g. a trap body from a Go-side signal handler).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExecHandlersalready lets external code wrap external command execution. Apply the same middleware-chain pattern to five more dispatch points so the interpreter can be extended from outside without patching its internals.StmtHandlersfires around everysyntax.Stmtbefore dispatch.SubshellHandlersfires around each subshell creation site, with aSubshellKindto distinguish background, paren, cmd subst, proc subst, and pipeline.BuiltinHandlerregisters a name-keyed override for a builtin;BuiltinHandlerswraps all builtin dispatch with middleware.FuncCallHandlerswraps the body of a declared shell function.LookupVarHandlerswraps lookupVar on top of the runner's own special-variable and environment resolution, so middlewares can add or override variables without losing the existing behaviour.Each chain follows
ExecHandlers' shape: middlewares are chained first-to-last, the bottom of the chain is the runner's own behaviour, and a middleware may short-circuit by not calling next. Chain bottoms recover the active runner from ctx, so the chains are built once inResetand inherited by subshell copies the same wayexecHandleris.Also add
RunStmts, a top-level helper for dispatching stmts on the runner attached toctx, useful for handlers that need to execute shell code in the runner's current scope (e.g. a trap body from a Go-side signal handler).