Skip to content

Support unary postfix percentage operator in sheet#286

Merged
ggyuchive merged 2 commits into
wafflebase:mainfrom
mahavirkunwar:feature/percentage-operator
May 23, 2026
Merged

Support unary postfix percentage operator in sheet#286
ggyuchive merged 2 commits into
wafflebase:mainfrom
mahavirkunwar:feature/percentage-operator

Conversation

@mahavirkunwar

@mahavirkunwar mahavirkunwar commented May 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Why

Linked Issues

Fixes #279

Author checklist

  • I searched existing issues and PRs and confirmed this is not a duplicate.
  • I read every line of this diff and can explain why each change is necessary.
  • Changes follow the conventions in the touched packages; any deviations are explained in Why above.
  • If AI tools assisted with this PR, I noted where in Notes for Reviewers below.

Verification

CI automatically posts a verification summary comment on this PR with
per-lane results for both verify:self and verify:integration.

  • verify:self — CI comment shows ✅
  • verify:integration — CI comment shows ✅ (or explicit skip reason below)

Skip reason (if applicable):

Risk Assessment

  • User-facing risk:
  • Data/security risk:
  • Rollback plan:

Notes for Reviewers

  • UI changes (screenshots/gifs if applicable):
  • Follow-up work (if any):

Summary by CodeRabbit

  • New Features
    • Formulas now support the percent operator (%) so expressions like 4% or A1*5% evaluate as expected (numeric value divided by 100); invalid usages produce errors.
  • Tests
    • Added test coverage for postfix percentage behavior, operator composition, cell-reference interaction, and error cases.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e1207457-07a6-4556-a0f1-af12f18fa143

📥 Commits

Reviewing files that changed from the base of the PR and between 80282bb and f1f616f.

📒 Files selected for processing (1)
  • packages/sheets/test/formula/formula.test.ts

📝 Walkthrough

Walkthrough

Adds unary postfix percent (%) to the formula grammar and lexer, regenerates ANTLR artifacts (lexer/parser/listener/visitor, token maps, ATNs), implements evaluator logic to return operand/100, and adds tests for percent semantics.

Changes

Percent Operator Support

Layer / File(s) Summary
Grammar definition
packages/sheets/antlr/Formula.g4
The expr rule adds a new expr PERCENT alternative labeled # Percent, and a new PERCENT token matches the % character.
Generated ANTLR infrastructure
packages/sheets/antlr/Formula.interp, packages/sheets/antlr/Formula.tokens, packages/sheets/antlr/FormulaLexer.*, packages/sheets/antlr/FormulaParser.ts, packages/sheets/antlr/FormulaListener.ts, packages/sheets/antlr/FormulaVisitor.ts
The lexer, parser, listener, visitor, and interpreter/token files are regenerated to include PERCENT; token IDs and literal mappings are shifted; PercentContext and precedence adjustments are added; serialized ATN/automata are updated.
Formula evaluator
packages/sheets/src/formula/formula.ts
Evaluator.visitPercent is implemented to coerce the inner expression to a number and return value / 100, propagating error results.
Tests / minor formatting
packages/sheets/test/formula/formula.test.ts
New test cases validate postfix percent behavior and operator interactions; one unrelated formatting tweak in a TRANSPOSE test line.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • wafflebase/wafflebase#276: Also modifies the ANTLR formula grammar and regenerates lexer/parser artifacts for a new operator (pow), causing similar token-ID remapping.

Suggested reviewers

  • ggyuchive

Poem

"A rabbit found a little sign: a percent in play,
The parser learned to read it, then hopped away. 🐰
Divide by a hundred, the numbers cheer,
Tiny symbol, tidy math — now the formulas clear."

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for a unary postfix percentage operator in the sheets subsystem.
Linked Issues check ✅ Passed The code changes fully implement the parsing and evaluation requirements from issue #279: the ANTLR grammar now recognizes % as a unary postfix operator with correct precedence, the lexer/parser are updated accordingly, and the evaluator divides the operand by 100, matching Excel/Google Sheets behavior.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the percentage operator feature: grammar updates, generated parser/lexer files, visitor/listener interfaces, evaluator implementation, and test coverage—no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ggyuchive
ggyuchive self-requested a review May 23, 2026 07:24

@ggyuchive ggyuchive left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, can you add some tests related to new feature?
Please refer issue scenario to check it.

@mahavirkunwar
mahavirkunwar requested a review from ggyuchive May 23, 2026 11:33
@mahavirkunwar

Copy link
Copy Markdown
Contributor Author

@ggyuchive I have added the test for this feature.

@codecov

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/sheets/src/formula/formula.ts 57.14% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ggyuchive ggyuchive left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks for your contribution.

@ggyuchive
ggyuchive merged commit 9bd6510 into wafflebase:main May 23, 2026
4 checks passed
@ggyuchive ggyuchive changed the title feat(sheets): support unary postfix percentage operator Support unary postfix percentage operator in sheet May 23, 2026
@hackerwins hackerwins mentioned this pull request May 24, 2026
2 tasks
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.

Support the unary postfix percentage operator (%)

2 participants