-
Notifications
You must be signed in to change notification settings - Fork 2
Implement compound assignment #125
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
Conversation
rycont
commented
Jul 26, 2025
…r compound operators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @rycont, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a significant language enhancement by implementing compound assignment operators. This feature streamlines code by allowing in-place arithmetic and string operations on variables and list elements, improving readability and reducing verbosity. The changes span across the lexer, parser, and execution engine, ensuring full integration and robust error handling for these new operations.
Highlights
- Core Language Feature: Implemented support for compound assignment operators (
+=
,-=
,*=
,/=
,%=
) for both variables and elements within lists. This allows for more concise code when updating values based on their current state. - Lexer and Parser Updates: Introduced a new
ASSIGNER
token type to differentiate between simple assignment (=
) and compound assignment operators. The parsing rules were updated to recognize and handle these new operators, dynamically generating rules for each assigner. - Execution Logic Enhancement: Modified the
SetVariable
andSetToIndex
execution logic to correctly apply the specified compound operation (e.g., addition, subtraction, multiplication) to the existing value before reassigning it. Robust error handling for type mismatches during these operations has also been added. - Documentation and Testing: Updated the language documentation to include a new section explaining compound assignment. Comprehensive unit tests have been added in a new file (
test/compound-operator.test.ts
) to validate the functionality and error handling of these new operators across various data types and scenarios.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces compound assignment operators like +=
, -=
, etc., for both variables and list elements. The implementation correctly touches on all necessary layers: tokenization, parsing, and execution. The use of ASSIGNERS.map
to generate parsing rules is a clean approach that reduces code duplication. The new functionality is also well-tested with a new dedicated test file and additions to existing test cases.
My review includes two main suggestions for improvement:
- A high-severity issue in the tokenizer where compound assignment operators are redundantly defined, which could lead to ambiguity.
- A medium-severity issue regarding duplicated error-handling logic in the execution phase, which could be refactored to improve maintainability.
Overall, this is a great addition to the language. Addressing these points will make the implementation more robust and maintainable.
core/prepare/tokenize/rules.ts
Outdated
'+=', | ||
'-=', | ||
'*=', | ||
'/=', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OPERATORS
array includes compound assignment operators (+=
, -=
, *=
, /=
). These are already handled by the ASSIGNER
token rule.
Including them here is redundant and could lead to tokenization ambiguity or bugs in the future. These operators should be removed from the OPERATORS
list to keep the concerns of operators and assigners separate.
try { | ||
newValue = tempOperator.call(oldValue, operand) | ||
} catch (error) { | ||
if (error instanceof YaksokError) { | ||
if (!error.tokens) { | ||
error.tokens = this.tokens | ||
} | ||
|
||
if (!error.codeFile) { | ||
error.codeFile = scope.codeFile | ||
} | ||
} | ||
|
||
throw error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This try...catch
block is identical to the one in core/node/list.ts
in the SetToIndex.execute
method (lines 176-190). This code duplication can make future maintenance more difficult and error-prone.
To improve maintainability, I recommend extracting this error-handling logic into a shared helper function that can be used in both places. This will ensure consistency and make updates easier.
Deploying dalbit-yaksok with
|
Latest commit: |
940ae3d
|
Status: | ✅ Deploy successful! |
Preview URL: | https://52da4c5b.yaksok-ts.pages.dev |
Branch Preview URL: | https://implement-compound-assignmen.yaksok-ts.pages.dev |