def get_field(ctx, field):
<EOL>if isinstance(field, str):<EOL><INDENT>field = getattr(ctx, field, None)<EOL><DEDENT>if callable(field):<EOL><INDENT>field = field()<EOL><DEDENT>elif isinstance(field, CommonToken):<EOL><INDENT>field = next(<EOL>filter(lambda c: getattr(c, "<STR_LIT>", None) is field, ctx.children)<EOL>)<EOL><DEDENT>return field<EOL>
Helper to get the value of a field