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

Use AST #109

Draft
wants to merge 140 commits into
base: main
Choose a base branch
from
Draft

Use AST #109

wants to merge 140 commits into from

Conversation

pherrymason
Copy link
Owner

@pherrymason pherrymason commented Jan 26, 2025

Motivation

Treesitter is used to obtain a structured representation of source code, which has been utilized to extract symbol declarations.

So far, Treesitter has been used to parse the source code to analyze and obtain a structured representation of the code: Context Syntax Tree (CST). The CST, also known as the Parse Tree, contains all the elements that are part of the text (spaces, brackets, etc.).
Although the CST can be navigated to analyze the code, it contains too much information about the language's syntax, making certain tasks more challenging.

On the other hand, using an AST (Abstract Syntax Tree) would allow working with a simpler structure that more accurately reflects the program's logic.

Strategy

Continuing to use Treesitter as a parser simplifies a large part of the work, as there is currently no other ready-to-use parser available.
One option is to convert the CST generated by Treesitter into an AST.
Subsequently, by using the Visitor pattern, it would be possible to implement different analyzers:

  • Symbol table generator
  • Diagnostics
  • Etc.

TODO

@pherrymason pherrymason marked this pull request as draft January 26, 2025 17:36
… field).

Improve "Find enum member in same module" scenario so it actually challenges the algorithm by placing trap declared before desired result.
…e detected on it.

Added test to find cursor on struct interface.
Parse struct declarations as ast.GenDecl.
AST generation: Work with Module pointers instead to avoid copying their content everytime a module is passed to a function.
Search: Support finding symbols that their identity contain explicit module resolution.
@pherrymason
Copy link
Owner Author

@PgBiel , I'm interested in the design of the ast nodes and how symbols are now indexed.
You'll see there's a single struct type to store all different symbols instead one different struct for each type of symbol. For now I think it is working.

@PgBiel
Copy link
Contributor

PgBiel commented Jan 29, 2025

Thanks. I'll probably stay off for several days now, but I'll try to take a look at a later date and give you some feedback. 👍

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

Successfully merging this pull request may close these issues.

3 participants