zafarkhaja / jsemver

Java implementation of the SemVer Specification
MIT License
429 stars 82 forks source link

Can't parse certain wildcard ranges #45

Closed Ziaunys closed 5 months ago

Ziaunys commented 5 years ago

Using the latest version 0.9.0 I am unable to parse certain wildcard ranges such as "5.x.x". Specifically, the wildcard specified in the patch field is a problem for the parser. Even though ranges like this are redundant they should still be valid syntax. Currently attempting to parse such a range will result in the following exception:

Unexpected token 'DOT(.) at position 3', expecting '[EOI(^(?!))]'
    at com.github.zafarkhaja.semver.expr.ExpressionParser.consumeNextToken(ExpressionParser.java:507)
    at com.github.zafarkhaja.semver.expr.ExpressionParser.parse(ExpressionParser.java:88)
    at com.github.zafarkhaja.semver.expr.ExpressionParser.parse(ExpressionParser.java:43)

I did some debugging and found that the exception is thrown because it assumes that after parsing the wildcard in the "minor" field it should then find an EOI token. This isn't the case if parsing a version range like "5.x.x". Could we just allow version ranges like this? I can't just easily change the version ranges I'm working with because they're externally defined.

zafarkhaja commented 1 year ago

Hello Eric! Sorry it took me this long to get back to you.

Most likely it's not relevant to you anymore, but just in case and for future reference I'm going to respond anyway :)

The current wildcard grammar is as follows

<wildcard-range> ::= <wildcard>
                   | <major> "." <wildcard>
                   | <major> "." <minor> "." <wildcard>

so it will have to change in order to accommodate your needs.

I'm going to investigate if this can be done easily without ending up writing a whole new parser.

zafarkhaja commented 5 months ago

Closing this issue in favor of #70, the progress can be followed from there.