Skip to content

improve error reporting#139

Merged
georghinkel merged 1 commit intomainfrom
error-reporting
Apr 10, 2026
Merged

improve error reporting#139
georghinkel merged 1 commit intomainfrom
error-reporting

Conversation

@georghinkel
Copy link
Copy Markdown
Contributor

@georghinkel georghinkel commented Apr 10, 2026

Summary by MergeMonkey

  • Fresh Additions:
    • Added IComparable implementation to ParsePositionDelta for proper ordering of position deltas
    • Added positive lookahead expression handling in code generation for complete expression support
    • Improved error recovery logic by ordering failures by examined position descending
  • Corrections:
    • Added bounds check in StarRuleApplication to prevent errors when Stopper position exceeds input length
    • Improved error propagation in FailedSequenceRuleApplication by calling AddParseErrors on last successful application
    • Added nullable enum value handling in GetValue to call GetValueOrDefault when lower bound is zero
  • Chores:
    • Added System.Linq import to FailedSequenceRuleApplication for OrderByDescending operation

@mergemonkeyhq
Copy link
Copy Markdown

mergemonkeyhq bot commented Apr 10, 2026

Risk AssessmentNEEDS-TESTING · ~15 min review

Focus areas: error recovery logic changes · positive lookahead expression support · nullable enum value handling · bounds checking for error reporting

Assessment: Adds new expression handling and changes error recovery logic - requires testing to verify parsing behavior

Walkthrough

This PR improves error reporting in the AnyText parsing framework through three main areas: adding IComparable to position deltas for ordering, enhancing the code generator to handle positive lookahead and nullable enums, and improving error propagation in rule applications with bounds checks and better recovery logic.

Changes

Files Summary
Position Delta Improvements
AnyText/AnyText.Core/ParsePositionDelta.cs
Implements IComparable<ParsePositionDelta> interface with line-first comparison logic for proper ordering of parser position deltas
Code Generator Enhancements
AnyText/AnyText.Generator/Transformation/AnytextCodeGenerator.cs
Adds IPositiveLookaheadExpression handling in CreateParserExpression and nullable enum value handling with GetValueOrDefault for optional enum rules with zero lower bound
Error Reporting Improvements
AnyText/AnyText.Core/Rules/StarRuleApplication.cs
AnyText/AnyText.Core/Rules/FailedChoiceRuleApplication.cs
AnyText/AnyText.Core/Rules/FailedSequenceRuleApplication.cs
StarRule adds bounds check before calling Stopper error reporting; FailedChoice improves recovery by ordering failures by examined position; FailedSequence adds error propagation to last successful application

Sequence Diagram

sequenceDiagram
    participant Parser
    participant StarRuleApp as StarRuleApplication
    participant FailedChoiceApp as FailedChoiceRuleApplication
    participant FailedSeqApp as FailedSequenceRuleApplication
    Parser->>StarRuleApp: AddParseErrors(context)
    StarRuleApp->>StarRuleApp: Check bounds (Line < Input.Length)
    alt Position in bounds
        StarRuleApp->>StarRuleApp: Stopper.AddParseErrors(context)
    end
    StarRuleApp->>Parser: Call base error handling
    Parser->>FailedChoiceApp: Recover(currentRoot, context)
    FailedChoiceApp->>FailedChoiceApp: Order _innerFailures by ExaminedTo descending
    FailedChoiceApp->>Parser: Return recovery result
    Parser->>FailedSeqApp: AddParseErrors(context)
    FailedSeqApp->>FailedSeqApp: Call AddParseErrors on last successful application
    FailedSeqApp->>Parser: Continue with further failures
Loading

Dig Deeper With Commands

  • /review <file-path> <function-optional>
  • /chat <file-path> "<question>"
  • /roast <file-path>

Runs only when explicitly triggered.

@mergemonkeyhq
Copy link
Copy Markdown

mergemonkeyhq bot commented Apr 10, 2026

Actionable Comments Posted: 0

👀 Worth a Look (1)
[MEDIUM] Optional enum coercion only handles direct EnumRule assignments - AnyText/AnyText.Generator/Transformation/AnytextCodeGenerator.cs (1100)
The new \`GetValueOrDefault\(\)\` branch fixes one nullable-enum case, but only when \`input.Assigned\` is a direct \`RuleExpression\` whose \`Rule\` is \`EnumRule\`. Other optional enum paths still generate a nullable property type \(\`LowerBound == 0\` makes value types nullable\) and return the property unchanged, so generated \`GetValue\` can still expose a nullable enum where the assignment rule expects a concrete value.

Consider basing enum unwrapping on the feature/property nullability instead of only direct \`RuleExpression -\> EnumRule\`, or extend the condition to cover referenced/indirect enum expressions that still synthesize a nullable enum property.
🧾 Coverage Summary
✔️ Covered (6 files)
- AnyText/AnyText.Core/ParsePositionDelta.cs
- AnyText/AnyText.Core/Rules/FailedChoiceRuleApplication.cs
- AnyText/AnyText.Core/Rules/FailedSequenceRuleApplication.cs
- AnyText/AnyText.Core/Rules/StarRuleApplication.cs
- AnyText/AnyText.Generator/Transformation/AnytextCodeGenerator.cs
- AnyText/AnyText.history

@georghinkel georghinkel merged commit 96d0bc8 into main Apr 10, 2026
1 check passed
@georghinkel georghinkel deleted the error-reporting branch April 10, 2026 15:38
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