Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using Python AST #99

Open
blueyed opened this issue Jul 15, 2018 · 5 comments
Open

Consider using Python AST #99

blueyed opened this issue Jul 15, 2018 · 5 comments

Comments

@blueyed
Copy link
Member

blueyed commented Jul 15, 2018

Via #71 (comment).

It might make sense to use a library like https://github.com/ambv/black/

However, this would likely involve quite some overhead if the whole text would need to be sent/used/tokenized everytime.

/cc @purpleP

@blueyed
Copy link
Member Author

blueyed commented Jul 17, 2018

Via #71:

I will experiment with using ast module or parso or maybe creating my own parser

Yay! \o/
Would be great if parso fits this need - otherwise I think this would be something @davidhalter might be interested to support.

to correctly determine indent you only need parse one paragraph

Depends on what you mean with "paragraph" .. ;)

If I remember correctly this library searches the whole file for matching quotes by the way, which also isn't very efficient.

Not the whole file necessarily, but it uses searchpairpos, which might also be used by an AST parser then to determine what input should be sent to it.

This indent plugin is certainly not very well optimized for performance though indeed.
I've started looking into this a while ago, but stopped there.

Anyway in 99% of cases parsing one paragraph is totally acceptable and would remove error-prone dependency on on syntax files.

Yes.

Fortunately there are a lot of tests already - and although they are clumsy by themselves it helps to avoid regressions.

@davidhalter
Copy link

Please let me know if you are missing features in parso.

@blueyed
Copy link
Member Author

blueyed commented Jul 18, 2018

@davidhalter
Thanks.

Can you provide us any pointers already to get to the information that is needed for getting the indent of a line?

@davidhalter
Copy link

I don't think that you can easily determine what the indentation of a line is, if you think about newlines and other empty space or multi line statements. However once you have a node in parso you can just use .column to parse the node.

What you could always do is scan for suite nodes that imply there's an indentation for it, check if we're in it's range and check the first statement for it's column. However it's probably more complicated if you care about error nodes.

@blueyed
Copy link
Member Author

blueyed commented Nov 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants