sudoblockio / tackle

Tackle is a programmable configuration language for building modular utilities, code generators, and CLIs with schema validation baked in.
Apache License 2.0
51 stars 2 forks source link

Return Hook #256

Open robcxyz opened 8 months ago

robcxyz commented 8 months ago

Return Hook

None

Overview

NOTE: See return-key for an additional macro for ergonomics.

Currently when a declarative hook is called with an exec, the entire context is parsed with a special field for returning the appropriate value (return) being used to specify what the result is of that parsing.

This proposal would add a hook for being able to escape parsing and return a specific value as the public context.

Examples

Normal parsing


foo: bar

return a key->: return {{foo}}

Would result in the value bar being returned in the public context.

Similarly with exec:


<-:

  exec:

    foo: bar

    return a key->: return {{foo}}

    something that: is ignored

Implementation

Context can be set within the hook. Need a way to send kill signal to parsing though since once the context is set, we need to be able to stop the parsing of the next key.

NOTE: Likely this kill signal approach would also enable a macro like approach for implementing return-key.