d0c-s4vage/gramfuzz

Loading grammars does not use globals() and locals() correctly

d0c-s4vage opened this issue · 0 comments

Problem

As described in #26 , methods on a class in a loaded grammar don't have access to other classes in the same grammar file:

class DEDENT(Field):
    def build(self, pre=None, shortest=False):
        global INDENT_LEVEL
        INDENT_LEVEL -= 1
        return NEWLINE().build(pre, shortest=shortest)

class NEWLINE():
    # ...

When DEDENT.build() is called, NEWLINE is not defined in the current scope

References

https://stackoverflow.com/questions/2904274/globals-and-locals-in-python-exec