mirror of
https://github.com/semver/semver.git
synced 2026-03-09 07:22:04 -05:00
BNF Grammar for Version #73
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @petermichaux on GitHub (Jun 11, 2013).
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?
@petermichaux commented on GitHub (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 commented on GitHub (Jun 11, 2013):
That could be overcome with the following, provided we want that.
@petermichaux commented on GitHub (Jun 11, 2013):
I think leading zeros are not desirable. They are not semantic. They are for manipulating automatic file listing order.
@tbull commented on GitHub (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 commented on GitHub (Jun 11, 2013):
YES. THIS. 👍
@petermichaux commented on GitHub (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 commented on GitHub (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 commented on GitHub (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 commented on GitHub (Jun 12, 2013):
@Tieske The
/d*matches0-9. The*means "0 or more". So this would match10.10.10.@isaacs commented on GitHub (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 commented on GitHub (Jun 12, 2013):
I agree. That is a good example.
@tbull commented on GitHub (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 commented on GitHub (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 commented on GitHub (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 commented on GitHub (Jun 12, 2013):
Thanks, @isaacs. I did miss the zeros.
@isaacs commented on GitHub (Jun 12, 2013):
Note for posterity: the BNF and regexp can be simplified somewhat if I'm overruled in #112.
@petermichaux commented on GitHub (Jun 13, 2013):
The regular expression could be appropriately included in "An implementers FAQ with normative and non-normative examples" mentioned in #113
@isaacs commented on GitHub (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 commented on GitHub (Jun 14, 2013):
Disallowing leading zeroes on numeric identifiers.
Regexp:
BNF:
@isaacs commented on GitHub (Jun 14, 2013):
Regular expression with comments:
@mojombo commented on GitHub (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 commented on GitHub (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 commented on GitHub (Jun 14, 2013):
Yes, that is correct, thanks. My regexp-fu greatly exceeds my bnf-fu :)
@isaacs commented on GitHub (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.
@EddieGarmon commented on GitHub (Jun 18, 2013):
A proposed simplified and descriptive update to the BNF.
isaacs#1