First, my textfile is parsed to yield an AST. I then want to make several copies of this AST, and perform different manipulations on each individual copy. I tried to use
import copy; copy.deepcopy(ast)
but this yields an error:
TypeError: cannot serialize '_io.TextIOWrapper' object
because _output
is set to wrap stdout:
'_output': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
This comes from trying to copy a antlr4.Token.CommonToken
instance inside my AST node class(es). stdout is assigned to _output
in antlr4.Lexer
.
Perhaps I am missing a simple solution for making a copy of my AST, containing generated Tokens and Context etc. instances?
Thanks!