Skip to content

37 parse call expressions#38

Merged
Matthew-Grayson merged 7 commits into
mainfrom
37-parse-call-expressions
Jul 3, 2026
Merged

37 parse call expressions#38
Matthew-Grayson merged 7 commits into
mainfrom
37-parse-call-expressions

Conversation

@Matthew-Grayson

@Matthew-Grayson Matthew-Grayson commented Jul 2, 2026

Copy link
Copy Markdown
Owner

feat(parser): add call expression parsing

  • Add CallExpression AST node
  • Parse function call expressions and arguments
  • Parse expression values in let and return statements
  • Add parser tests for call expressions

- Add CallExpression to ast/ast.go
- Fields: Token token.Token, Function Expression, Arguments []Expression
- Implements expressionNode(), TokenLiteral() and String() to render calls like fn(arg1, arg2)
- Register LPAREN as a call-expression infix so function-call sites are parsed correctly
- Add parseCallExpression and parseCallArguments to build call AST nodes and consume arguments
- Add/update tests in parser/parser_test.go to verify call parsing and operator precedence inside arguments
* Convert let statement cases to table-driven inputs
* Add expected values for integer, boolean, and identifier assignments
* Replace placeholder token skipping with expression parsing in let and return statements.
Copilot AI review requested due to automatic review settings July 2, 2026 17:20
@Matthew-Grayson Matthew-Grayson linked an issue Jul 2, 2026 that may be closed by this pull request
@Matthew-Grayson Matthew-Grayson self-assigned this Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the Monkey interpreter’s front-end by adding function call expression parsing (e.g., add(1, 2)) and by enabling let/return statements to actually parse and store their expression values in the AST.

Changes:

  • Add call-expression precedence and parsing via ( as an infix operator, including argument parsing.
  • Populate LetStatement.Value and ReturnStatement.ReturnValue by parsing expressions instead of skipping them.
  • Introduce ast.CallExpression plus parser tests for call parsing and operator precedence involving calls.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
parser/parser.go Adds call-expression parsing and enables expression parsing for let/return.
parser/parser_test.go Adds call-expression parsing tests and expands precedence/let-statement tests.
ast/ast.go Introduces CallExpression AST node and stringification.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread parser/parser.go Outdated
Comment thread parser/parser.go Outdated
Comment thread parser/parser_test.go Outdated
Comment thread parser/parser.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 2, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread parser/parser.go
…r semicolon

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 3, 2026 16:05
@Matthew-Grayson Matthew-Grayson marked this pull request as ready for review July 3, 2026 16:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread parser/parser_test.go
Comment thread parser/parser.go
@Matthew-Grayson Matthew-Grayson merged commit a3190f7 into main Jul 3, 2026
2 checks 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.

Parse Call Expressions

2 participants