You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently there has been confusion around what is allowed as a version. The standard is ambiguous. I propose including a BNF grammar for what is allowed. It is short and completely unambiguous so why not include it?
Note that the grammar I have proposed does not allow major, minor, or patch to have unnecessary leading zeros. So major, minor, and patch can be 0, 1, 3200, etc but cannot be 00, 05, etc.
I have no opinion on that detail. My implementation allows leading zeroes.
One point against leading zeroes could be that there are some languages inspired by C that parse numbers starting with 0 as octal notation. This goes well so long as there are only digits 0 through 7 used, but fails if digits 8 or 9 show up. This is one common source of surprise for noobs to a language. On the other hand, I think, a spec should not take such language peculiarities into account.
One point for leading zeroes is that, if they are disallowed in major/minor/patch, they should be disallowed in numeric id parts of pre-release strings, too, and that would make matters even more complicated.
A !JavaScript regular expression for this grammar is the following and could be included as non-normative bonus content since getting regular expressions correct is error prone. (This one should definitely be checked.)
imo leading zero's should be allowed, they don't do any harm (comparison is numerically), but might help out in sorting stuff easily.
I have little regex experience, but it seems to me that the regex fails on 10.10.10 as a version as zeros are not allowed at all. Besides that, I don't think the spec should include any regexes.
In my experience, most developers are nervous and diffident when it comes to regular expressions. Including one as non-normative content could help ensure poor implementations do not appear. This will help the perceived integrity of the standard. It is optional, of course, but I think would be very helpful to have it in an easy to find location: right in the standard.
Leading zeroes should not be allowed. It'd be confusing if 1.1.1 was the "same version" as 01.01.000001. Is this ambiguous in the language of the spec?
Leading zeroes should not be allowed. It'd be confusing if 1.1.1 was the "same version" as 01.01.000001. Is this ambiguous in the language of the spec?
It'd be confusing if 1.1.1 was the "same version" as 01.01.000001.
I don't see the point. What's so bad about that?
As to example rexgexp, certainly would hurt to include one as a non-normative example. There have several examples already been published somewhere in all the issues here.
@tbull The versions look dramatically different. From the spec's point of view, they'd have the same precedence. However, it's strange and confusing to me that they're the same, when they apparently differ quite a bit.
Regardless, this definitely needs to be clarified in the specification.
varr=newRegExp('^'+'(0|[1-9]\\d*)'+// major'\\.(0|[1-9]\\d*)'+// minor'\\.(0|[1-9]\\d*)'+// patch'(?:-'+// start prerelease'('+// capture'(?:'+// first identifier'0|'+// 0, or'[1-9]\\d*|'+// numeric identifier, or'\\d*[a-zA-Z-][a-zA-Z0-9-]*'+// id with at least one non-number')'+// end first identifier'(?:\\.'+// dot-separated'(?:0|[1-9]\\d*|\\d*[a-zA-Z-][a-zA-Z0-9-]*)'+// identifier')*'+// zero or more of those')'+// end prerelease capture')?'+// prerelease is optional'(?:'+// build tag (non-capturing)'\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*'+// pretty much anything goes')?'+// build tag is optional'$')
I'm in favor of a BNF grammar in the spec. As SemVer gains adoption, and especially as tools rely on well-formed versions, it will be critical that no ambiguity exists. Seems fine to put it in the main spec rather than an appendix. One page to rule them all.
@isaacs I believe the following part of your BNF is incorrect. You don't allow aa, --, or a1a, for example. You don't use <identifier character> at all.
@mojombo Great, thanks for the direction. Patch submitted in #116.
Seems fine to put it in the main spec rather than an appendix. One page to rule them all.
I absolutely agree about the BNF grammar, since that's part of the "specification" bit. How would you feel about adding example pseudocode and/or authoritative test cases as separate pages, or even just separate files in this repo that don't show up on the website at all? I'd like them to be included for clarity, but the concern is that the page could get too unwieldy.
Activity
petermichaux commentedon Jun 11, 2013
Note that the grammar I have proposed does not allow major, minor, or patch to have unnecessary leading zeros. So major, minor, and patch can be
0,1,3200, etc but cannot be00,05, etc.tbull commentedon Jun 11, 2013
That could be overcome with the following, provided we want that.
petermichaux commentedon Jun 11, 2013
I think leading zeros are not desirable. They are not semantic. They are for manipulating automatic file listing order.
tbull commentedon Jun 11, 2013
I have no opinion on that detail. My implementation allows leading zeroes.
One point against leading zeroes could be that there are some languages inspired by C that parse numbers starting with
0as octal notation. This goes well so long as there are only digits0through7used, but fails if digits8or9show up. This is one common source of surprise for noobs to a language. On the other hand, I think, a spec should not take such language peculiarities into account.One point for leading zeroes is that, if they are disallowed in major/minor/patch, they should be disallowed in numeric id parts of pre-release strings, too, and that would make matters even more complicated.
isaacs commentedon Jun 11, 2013
YES. THIS. 👍
petermichaux commentedon Jun 12, 2013
A !JavaScript regular expression for this grammar is the following and could be included as non-normative bonus content since getting regular expressions correct is error prone. (This one should definitely be checked.)
The first capturing group is "major".
The second capturing group is "minor".
The third capturing group is "patch".
The forth capturing group is "pre-release" (not including the preceding dash delimiter between patch and pre-release).
The "build" is non-capturing because it is not to be used in any comparisons.
Tieske commentedon Jun 12, 2013
imo leading zero's should be allowed, they don't do any harm (comparison is numerically), but might help out in sorting stuff easily.
I have little regex experience, but it seems to me that the regex fails on
10.10.10as a version as zeros are not allowed at all. Besides that, I don't think the spec should include any regexes.petermichaux commentedon Jun 12, 2013
In my experience, most developers are nervous and diffident when it comes to regular expressions. Including one as non-normative content could help ensure poor implementations do not appear. This will help the perceived integrity of the standard. It is optional, of course, but I think would be very helpful to have it in an easy to find location: right in the standard.
haacked commentedon Jun 12, 2013
@Tieske The
/d*matches0-9. The*means "0 or more". So this would match10.10.10.isaacs commentedon Jun 12, 2013
Leading zeroes should not be allowed. It'd be confusing if
1.1.1was the "same version" as01.01.000001. Is this ambiguous in the language of the spec?petermichaux commentedon Jun 12, 2013
I agree. That is a good example.
tbull commentedon Jun 12, 2013
I don't see the point. What's so bad about that?
As to example rexgexp, certainly would hurt to include one as a non-normative example. There have several examples already been published somewhere in all the issues here.
isaacs commentedon Jun 12, 2013
@tbull The versions look dramatically different. From the spec's point of view, they'd have the same precedence. However, it's strange and confusing to me that they're the same, when they apparently differ quite a bit.
Regardless, this definitely needs to be clarified in the specification.
isaacs commentedon Jun 12, 2013
@petermichaux That regexp doesn't handle zeros in the main version portions.
Fixed to match the BNF you presented (which I believe is correct):
petermichaux commentedon Jun 12, 2013
Thanks, @isaacs. I did miss the zeros.
1 remaining item
petermichaux commentedon Jun 13, 2013
The regular expression could be appropriately included in "An implementers FAQ with normative and non-normative examples" mentioned in #113
isaacs commentedon Jun 14, 2013
That BNF would allow leading zeroes in numeric prerelease identifiers, because "0009" is a valid set of "identifier characters".
Working on a more restrictive grammar now.
isaacs commentedon Jun 14, 2013
Disallowing leading zeroes on numeric identifiers.
Regexp:
BNF:
isaacs commentedon Jun 14, 2013
Regular expression with comments:
mojombo commentedon Jun 14, 2013
I'm in favor of a BNF grammar in the spec. As SemVer gains adoption, and especially as tools rely on well-formed versions, it will be critical that no ambiguity exists. Seems fine to put it in the main spec rather than an appendix. One page to rule them all.
petermichaux commentedon Jun 14, 2013
@isaacs I believe the following part of your BNF is incorrect. You don't allow
aa,--, ora1a, for example. You don't use<identifier character>at all.I think it should be
isaacs commentedon Jun 14, 2013
Yes, that is correct, thanks. My regexp-fu greatly exceeds my bnf-fu :)
Add BNF Grammar for valid version strings
isaacs commentedon Jun 14, 2013
@mojombo Great, thanks for the direction. Patch submitted in #116.
I absolutely agree about the BNF grammar, since that's part of the "specification" bit. How would you feel about adding example pseudocode and/or authoritative test cases as separate pages, or even just separate files in this repo that don't show up on the website at all? I'd like them to be included for clarity, but the concern is that the page could get too unwieldy.
Add BNF Grammar for valid version strings
Add BNF Grammar for valid version strings
EddieGarmon commentedon Jun 18, 2013
A proposed simplified and descriptive update to the BNF.
isaacs#1
Add BNF Grammar for valid version strings
Merge pull request semver#110 from eLobato/patch-2