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

Add Ast class #29

Merged
merged 2 commits into from
Jan 8, 2025
Merged

Add Ast class #29

merged 2 commits into from
Jan 8, 2025

Conversation

Nirei
Copy link
Collaborator

@Nirei Nirei commented Jan 4, 2025

We refactor the AST produced by the parser to a new class that's compatible with the existing code but will allow us to extend the AST with new behaviours in the future without compromising the existing interface. The original tuple-based tree can still be accessed via Ast#tree method.

This class also provides extra name-based type safety under a convenient name.

@Nirei Nirei self-assigned this Jan 4, 2025
@Nirei Nirei changed the title Add Astclass Add Ast class Jan 4, 2025
@@ -21,7 +32,7 @@ def __init__(
def parse(self, program):
program = self.preprocessor.process(program)
tree = self.grammar.parse(program)
return self.visitor.visit(tree)
return Ast(self.visitor.visit(tree))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the idea of adding as much typing and object orientation as possible. I would add program: str to the method's input so that it is fully typed, both in its input and output.

@TheVaultdweller13
Copy link
Owner

Approve with suggestions.

@Nirei Nirei merged commit 1d42248 into main Jan 8, 2025
1 check passed
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.

2 participants