I think we should consider building a Python AST imbued with lexical
information. This could take the form of a NodeVisitor and/or
NodeTransformer
(
http://docs.python.org/3/library/ast.html#ast.NodeVisitor) that
associates each identifier with some metadata on each visit. This
would be a compelling demonstration for the paper's artifact
evaluation, and would certainly be immediately useful for
Python-implemented Python tools. It also would give us a foothold to
start putting more complicated metadata or desugarings into a form
that's immediately useful to folks using Python.
For example, we could implement an environment visitor that allows the
association of arbitrary data with identifiers at binding positions,
which then always gives the *correct* associated information back when
queried with particular identifiers. So if you were NodeVisiting our
favorite example:
def f(x: Int):
class c():
x = "foo"
print(x)
def m(self):
print(x)
At the top of f and c, there would be extra information about the
variable `x' being available for that block, and the programmer could
choose to associate information with each (say, annotations and
initial values). When the programmer looks up the information at the
use site of the first print(x), they would get, say `String' back, but
at the second they would get `Int'.
Concretely, I think the top-level implementation of such a tool should
happen in Python. It would parse the program itself and then call out
to \Py, which would return some JSON with this metadata, and then
create the Visitor/Transformer on top of that metadata. We need to
think carefully about which forms are binding forms and how we
represent the relationship between those places and identifiers, but
it should be quite doable.
(We could also implement phase1/phase2 in Python itself, but that
comes with all the attendant difficulties of mirrored implementations,
etc, so I think for a first cut, we should stay in Racket for the
lexical analysis itself.)
Is anyone interested in taking this on, in whole or in part (Justin,
you're welcome to as well, since this seems to be in your research
trajectory)? I'm willing to help out, of course.