How can I pass a self.visit() as a function pointer from a visitor method to another method?

15 views
Skip to first unread message

Matti Viljamaa

unread,
May 9, 2017, 1:18:06 PM5/9/17
to antlr-discussion
How can I pass a self.visit() from a visitor method to another method?

I've tried

c = ClassNode()

for f in ctx.feature():
    c.addFeature(self.visit(f))

Which should syntatically work, but self.visit(f) has return value of None, so when I go to
c.addFeature() then I see None coming in and not a function pointer.

So is there a way to get the function pointer into c.addFeature()?

The idea being that then I can call inside c the self.visit(f) and get to the features.

Matti Viljamaa

unread,
May 9, 2017, 1:29:48 PM5/9/17
to antlr-di...@googlegroups.com
It seems that one workaround is to pass the Visitor object self and the FeatureContext f separately.
I.e.

c.addFeature(self, f)

and then retain them separately inside c until one needs to use them.

E.g. put them into list like:

addFeature (obj, f) {
    features.append((obj, f))
}

and when one wants to visit the feature, one does:

c.features[i][0].visit(c.features[i][1])

---

I've tested this works.
Reply all
Reply to author
Forward
0 new messages