Skip to content
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

Fix [*] and ##[*] operator range minimums to be 0 #1192

Merged

Conversation

georgerennie
Copy link
Contributor

According to the LRM, [*] is an equivalent representation of [*0:$] (1800-2023 p411 16.9.1) and ##[*] is used as an equivalent representation of ##[0:$] (1800-2023 p400 16.7).

With the current master build of slang (170ad7b), [*] and [*0:$] produce the following ast json respectively:

"repetition": {
  "kind": "Consecutive",
  "min": 1,
  "max": "$"
}
"repetition": {
  "kind": "Consecutive",
  "min": 0,
  "max": "$"
}

and ##[*] and ##[0:$] produce the following respectively:

{
  "sequence": {
    "kind": "Simple",
    "expr": {
      "kind": "Invalid",
      "type": "<error>"
    }
  },
  "min": 1,
  "max": "$"
}
{
  "sequence": {
    "kind": "Simple",
    "expr": {
      "kind": "Invalid",
      "type": "<error>"
    }
  },
  "min": 0,
  "max": "$"
}

These should all have the same min value of 0, but these cases weren't being handled correctly. This patch adds the special casing needed for these two scenarios, and the output now has "min": 0 for all cases.

An alternative approach could be to set the default SequenceRange::min value to 0, but I wasn't sure if other code relies on it being 1.

Copy link

codecov bot commented Dec 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.72%. Comparing base (170ad7b) to head (1e41ffa).
Report is 3 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1192      +/-   ##
==========================================
- Coverage   94.72%   94.72%   -0.01%     
==========================================
  Files         202      202              
  Lines       50927    50933       +6     
==========================================
+ Hits        48243    48247       +4     
- Misses       2684     2686       +2     
Files with missing lines Coverage Δ
source/ast/expressions/AssertionExpr.cpp 90.09% <100.00%> (-0.16%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 170ad7b...1e41ffa. Read the comment docs.

@MikePopoloski MikePopoloski merged commit 55598e7 into MikePopoloski:master Dec 24, 2024
14 of 15 checks passed
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.

2 participants