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

Support Cursors Comparision #523

Open
SamirDroubi opened this issue Oct 26, 2023 · 0 comments
Open

Support Cursors Comparision #523

SamirDroubi opened this issue Oct 26, 2023 · 0 comments
Labels
C: APIs The API exposed by the language S: Needs Discussion This needs discussion to decide if important to work

Comments

@SamirDroubi
Copy link
Collaborator

SamirDroubi commented Oct 26, 2023

It is common when you are doing trees (ASTs being one of them) manipulations to want to query the relative position between two nodes. Some common examples:

  • Are these two nodes the same?
  • Is this node a parent of mine? ----> is this my direct parent scope
  • Is this node an ancesotor of mine? ----> Am I in the scope defined by this cursor
  • Do we both have the same parent? ---> Am I in the same body as another cursor
  • Is this node to my left/right among the children of out shared direct parent? ---> is this statement below or after me in the body of our direct parent scope

Ideally, we can define the Python comparision operators on cursors and give them some clear semantics. Some things to be careful about:

  • Does equality of two cursors mean equality of the location in the tree or the equality of the subtrees each cursor points to? I think it should be the former and some other function to compare the content: cursor1 == cursor2 checks if two cursors point to the same location. cursor1.is_same_ast(cursor2) checks if the two ASTs are the same of cursors that could be at different locations.
  • If cursor1 and cursor2 aren't in the same body, should cursor1 < cursro2 return false or raise an error?

The equality confusion might also suggest that maybe we should decouple the cursors API from the AST/introspection API (like @jrk suggested a while ago): cursors can only be a statement, expressions, block, and gap cursors, with the ability to get an introspectable AST object from statement and expression cursors.

@SamirDroubi SamirDroubi added S: Needs Discussion This needs discussion to decide if important to work C: APIs The API exposed by the language labels Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: APIs The API exposed by the language S: Needs Discussion This needs discussion to decide if important to work
Projects
None yet
Development

No branches or pull requests

1 participant