On Nov 16, 8:25 pm, "Edward K. Ream" <edream...@gmail.com> wrote:
> When the format method is written, we would replace:: > > print(z.sd.dump_ast(z.tree())) > > by: > > print(z.format()) > > but that is just "syntactic sugar". And rather than printing the > "raw" AST tree shown above, format will print it as it would look in > the actual source file. It will take a bit of work tomorrow... The first draft of Context.format was:: def format(self,brief=True): cx = self return ast.dump(cx._tree,annotate_fields=True,include_attributes=not brief) This produces output such as:: Assign(targets=[Attribute(value=Name(id='self', ctx=Load()), attr='c', ctx=Store())], value=Name(id='c', ctx=Load())) Call(func=Attribute(value=Name(id='self', ctx=Load()), attr='beginCommandHelper', ctx=Load()), args=[], keywords=[keyword(arg='ch', value=Str(s='')), keyword(arg='undoType', value=Name(id='undoType', ctx=Load())), keyword(arg='w', value=Attribute(value=Name(id='self', ctx=Load()), attr='w', ctx=Load()))], starargs=None, kwargs=None) This is just a squished version of the ast tree. Alas, ast.dump has no option to reproduce the tree's source. It's a big hole in the ast class, imo. But there is no use complaining. Early this morning I started work on the AstFormatter class, yet another AST traversal class. It's coming along nicely. Here is format's present output corresponding to the dumps above:: self.c = c self.beginCommandHelper(ch='',undoType=undoType ,w=self.w) In other words, format is nearing completion. There are a lot of picky details to handle, however: the formatter must generate code for virtually all AST nodes. In addition, the present code adds spaces around all identifiers, so that constructions such as "a or b" don't get turned into "aorb". This can lead to too many spaces, as you can see above. Eventually, format will beautify its result, perhaps using Leo's token-oriented beautify-python code. I expect to spend at least the rest of today on format and the AstFormatter class. Edward -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To post to this group, send email to leo-editor@googlegroups.com. To unsubscribe from this group, send email to leo-editor+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en.