Skip to content

Avoid hyperbracket capture by using sets of scopes #5

@rocketnia

Description

@rocketnia

Punctaffy's present design may be susceptible to some code injection gotchas if a macro inserts one of its caller-provided subforms into a hyperbracketed region. In that situtation, I believe closing hyperbrackets appearing in the subform will match up with ones generated by the macro (e.g. to open the region). I believe something similar is possible with quasiquote and unquote, but Punctaffy doesn't have to preserve that.

To address this, we can have each bracket refer to an "interposition point" anaphoric variable representing the surrounding lexical context. Usually, this variable is not specified explicitly, and it has the lexical information of the hyperbracket's beginning syntax object. This variable can carry a hyperstack in its syntax-local-value.

We've partially prepared for this with the 'context part of the taffy-notation-akin-to-^<>d-parse result, which currently uses #%context as the name of the interposition point. Let's change this to 'lexical-context and #%lexical-context.

Many other implicit bindings we might want to create should eventually be carried in that variable too. That way, their bindings can be in scope only for a delimited hypersnippet of code, and their preexisting bindings can be visible again in the hypersnippet's holes. But let's focus on matching brackets for now.

  • Make sure that it's an issue in the first place.
    • Create an example of the issue using quasiquote and unquote. [We've done so in the comments below.]
    • Create an example of the issue using Punctaffy's ^< and ^>. [We've done so in the comments below.]
  • Rename 'context and #%context to 'lexical-context and #%lexical-context.
  • Carry a simple hyperstack of trivial values in #%lexical-context. In taffy-notation-akin-to-^<>d? traversals, update the stack, and error out if a closing hyperbracket is of too high degree for the stack's current dimension. Initially, don't worry about whether the bindings of #%lexical-context behave in a set-of-scopes way.
  • Figure out how to make the bindings behave in a set-of-scopes way. This might be tricky if we're code-walking rather than expanding into let-syntax as we go along.
  • Test that the example we created using Punctaffy's ^< and ^> now avoids hyperbracket capture.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions