iris-hep/qastle

How to handle unknown ast nodes?

gordonwatts opened this issue · 2 comments

I tried this out as a backend for our stuff, and I got this right off the bat:

    def generic_visit(self, node):
>       raise SyntaxError('Unsupported node type: ' + str(type(node)))
E         File "<string>", line None
E       SyntaxError: Unsupported node type: <class 'func_adl.query_result_asts.ResultTTree'>

How best to deal with this sort of thing?

The safest and easiest way to handle arbitrary nodes like this is to pass them as Attribute/Call nodes instead. I would imagine that's how a node type like this originally began in the Python source, and then it got transformed at some point into its own node. We could delay that transformation until the C++ transformer has actually received the AST. The other main option I can think of is to chop it off before it gets translated into the text AST, since this node is only relevant for the output formatting rather than the selection. That would limit flexibility at the C++ transformer, though.

Ok - I think you are right. Indeed, in my code, they start out as Call nodes, and are converted. This is because the code is slightly cleaner when it comes to the ast visit process. However, the less changes that happen at the front end the better - so putting that off to the backend makes more sense. I'll tackle that.