lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.77k stars 406 forks source link

Use generator instead of list expand or add method #1225

Closed jmishra01 closed 1 year ago

jmishra01 commented 1 year ago

We can use generator to create pretty string of Tree in place of list. This PR reduce memory usage.

erezsh commented 1 year ago

I like this change!

Review: You can turn a few more of the "yield"s to "yield from"s.

jmishra01 commented 1 year ago

@erezsh Done!

erezsh commented 1 year ago

What I meant is that you don't need any for loop..

yield from (i for i in ('\t', '%s' % (self.children[0],), '\n'))

can be

yield from ('\t', '%s' % (self.children[0],), '\n')

etc.

Although this particular expression can be rewritten as a single string format.

Give it another try if you like. Otherwise no problem, I'll do the finishing touches myself.

jmishra01 commented 1 year ago

Thank you for review, I change few lines, use yield with f-string method.

erezsh commented 1 year ago

Thanks!