Skip to content

fix #1685: обработка ошибок в теле модуля#1688

Open
Mr-Rm wants to merge 1 commit into
EvilBeaver:developfrom
Mr-Rm:v2/fix-1685
Open

fix #1685: обработка ошибок в теле модуля#1688
Mr-Rm wants to merge 1 commit into
EvilBeaver:developfrom
Mr-Rm:v2/fix-1685

Conversation

@Mr-Rm
Copy link
Copy Markdown
Collaborator

@Mr-Rm Mr-Rm commented May 26, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved error reporting for unexpected keywords in module code.
    • Enhanced parsing behavior for module body handling with more accurate error positioning.
    • Refined token error recovery to provide clearer error messages.
  • Tests

    • Added test coverage for module body parsing error scenarios.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 17dc5080-c1e2-4adf-af7b-1962da5c4e3d

📥 Commits

Reviewing files that changed from the base of the PR and between 3c3984c and de17102.

📒 Files selected for processing (3)
  • src/OneScript.Language/SyntaxAnalysis/DefaultBslParser.cs
  • src/OneScript.Language/SyntaxAnalysis/LocalizedErrors.cs
  • src/Tests/OneScript.Language.Tests/ParserTests.cs

📝 Walkthrough

Walkthrough

Parser error handling for unexpected tokens at end-of-file is improved. A new localized error factory reports unexpected keywords, the parser exits early from module body parsing at EOF, statement error recovery special-cases EOF, and error column positions are conditionally adjusted. New test validates the behavior.

Changes

EOF and Unexpected Token Error Handling

Layer / File(s) Summary
Unexpected keyword error factory
src/OneScript.Language/SyntaxAnalysis/LocalizedErrors.cs
New UnexpectedKeyword(Token) factory produces localized Russian/English error messages for unexpected tokens using LanguageDef token name and alias.
EOF handling and error recovery in parser
src/OneScript.Language/SyntaxAnalysis/DefaultBslParser.cs
BuildModuleBody exits immediately when current token is EndOfText. Statement error recovery differentiates EOF case, emitting UnexpectedKeyword for unexpected tokens at EOF instead of generic TokenExpected. Error position column adjustment is now conditional on lexem content length.
Test for unexpected keyword errors at EOF
src/Tests/OneScript.Language.Tests/ParserTests.cs
New test Throws_When_Error_In_Module_Body verifies that parsing module code with unexpected EndFunction token produces an UnexpectedKeyword error.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • EvilBeaver/OneScript#1547: Both PRs modify the BSL parser's error handling in DefaultBslParser.cs and extend LocalizedErrors to produce more specific localized token-based error messages, making them directly related at the code level.

Poem

🐰 When tokens hide where EOF roams,
Our parser now knows when to go back home.
With keywords named and columns set right,
Error messages glow with localized light!
The module body bows to EOF's might,
And tests confirm the recovery's bright! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses error handling in module body parsing, which is the primary focus of all three changed files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

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.

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.

1 participant