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

Major rewrite for parser and interpreter #109

Merged
merged 60 commits into from
Nov 16, 2023

Conversation

ricardoboss
Copy link
Owner

@ricardoboss ricardoboss commented Nov 7, 2023

Inspired by and will fix #104.

This change is a complete revamp of the parser and how the parsed statements (now called nodes) are interpreted.

Additionally, this adds some features that were too hard to implement previously.

The parser now takes the tokens and generates an abstract syntax tree, consisting of different nodes.
The nodes are interpreted using the visitor pattern by the Interpreter class.

New features:

  • nullable function parameters
  • default values for function parameters
  • (only available for native functions) union types for functions parameters
  • (only available for native functions) return types for functions
  • exceptions that were previously printed with the affected code can now also show the causing token

The CLI has a new parse command to show the parsed abstract syntax tree (AST).

Copy link

github-actions bot commented Nov 7, 2023

Report

Code Coverage

Static Analysis:

  • Code Style: ✅ OK
  • Docblocks: 25 / 931 (2%)

@ricardoboss
Copy link
Owner Author

Example of marked token in case of an error:
image

@ricardoboss
Copy link
Owner Author

This is the current output of the parse command when given the assignment.step example file:
image

@ricardoboss ricardoboss marked this pull request as ready for review November 13, 2023 22:36
@ricardoboss ricardoboss merged commit 9c4d8c4 into main Nov 16, 2023
14 checks passed
@ricardoboss ricardoboss deleted the experiments/abstract-syntax-tree branch November 16, 2023 00:11
@ricardoboss ricardoboss mentioned this pull request Nov 19, 2023
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.

A command to inspect the parsed AST
1 participant