← Back to Pull requests

refactor(argparse): match negative numbers with one regex #4865

Closed
unknown closed this pull request without merging on Nov 17, 2026 14:38 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 14:27 UTC
Author

Summary

is_negative_number lets a negative number such as -42 be taken as a positional value instead of an unknown short option. It checked - and a first digit with a view pattern, and the rest with all:

match arg {
  ['-', '0'..<='9', .. rest] => rest.all(c => c is ('0'..<='9'))
  _ => false
}

It is now the pattern it describes:

lexmatch arg {
  re"^-[0-9]+$" => true
  _ => false
}

No .mbti change.

Testing

  • moon test -p moonbitlang/core/argparse --target all passes.

  • Exhaustive differential check (temporary white-box test, not committed): old and new agree on every argument up to length 6 over - 0 9 a . = space ٣ 😀 +. That's 1,111,111 inputs.
  • Performance

    From a temporary benchmark (not committed): 8 typical arguments (-1, -42, --verbose, -v, file.txt, -123456, --out=x, -) × 100, mean of 3 runs.

    | target | before | after | change |
    |---|---:|---:|---:|
    | native | 8.3 µs | 8.6 µs | +4% |
    | js | 8.3 µs | 8.4 µs | +1% |
    | wasm-gc | 6.5 µs | 6.2 µs | −5% |

    It runs once per command-line argument, so this is noise next to everything else parsing does.

    <!-- devin-review-badge-begin -->

    ---

    <a href="https://app.devin.ai/review/moonbitlang/core/pull/4865" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    Diff: 191 lines (+143 / -48) across 2 files Reviewer: devin-ai-integration[bot] Review duration: 10m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 191 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.315
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4865"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35.9% (MEDIUM) · Higher = larger blast radius
    35.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.2% · Safe to merge
    14.2%