From 3106a1dcd36703b6143c0b5fa3896ac432941820 Mon Sep 17 00:00:00 2001 From: abhu85 <60182103+abhu85@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:40:28 +0000 Subject: [PATCH] docs: fix BNF grammar to distinguish prerelease from build identifiers The BNF grammar incorrectly showed `pre` and `build` as identical rules, but they have different requirements per SemVer 2.0.0 specification: - Prerelease identifiers: numeric parts must not have leading zeros (e.g., `1.2.3-00` is invalid, `1.2.3-0` is valid) - Build metadata: allows any alphanumeric string including leading zeros (e.g., `1.2.3+00` is valid) This updates the BNF in both README.md and range.bnf to correctly reflect the implementation behavior and SemVer spec. Fixes #665 Co-Authored-By: Claude Opus 4.6 --- README.md | 15 +++++++++++---- range.bnf | 9 +++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e9d1bc5e..a7f243c2 100644 --- a/README.md +++ b/README.md @@ -399,12 +399,19 @@ nr ::= '0' | ['1'-'9'] ( ['0'-'9'] ) * tilde ::= '~' partial caret ::= '^' partial qualifier ::= ( '-' pre )? ( '+' build )? -pre ::= parts -build ::= parts -parts ::= part ( '.' part ) * -part ::= nr | [-0-9A-Za-z]+ +pre ::= prepart ( '.' prepart ) * +prepart ::= nr | alphanumid +build ::= buildid ( '.' buildid ) * +alphanumid ::= ( ['0'-'9'] ) * [-A-Za-z] [-0-9A-Za-z] * +buildid ::= [-0-9A-Za-z]+ ``` +Note: Prerelease identifiers (`pre`) use `nr` for numeric parts, which +disallows leading zeros (e.g., `1.2.3-00` is invalid). Build metadata +identifiers (`build`) allow any alphanumeric string including leading +zeros (e.g., `1.2.3+00` is valid). This matches the +[SemVer 2.0.0 specification](https://semver.org/#spec-item-9). + ## Functions All methods and classes take a final `options` object argument. All diff --git a/range.bnf b/range.bnf index d4c6ae0d..a7a4bc37 100644 --- a/range.bnf +++ b/range.bnf @@ -10,7 +10,8 @@ nr ::= '0' | [1-9] ( [0-9] ) * tilde ::= '~' partial caret ::= '^' partial qualifier ::= ( '-' pre )? ( '+' build )? -pre ::= parts -build ::= parts -parts ::= part ( '.' part ) * -part ::= nr | [-0-9A-Za-z]+ +pre ::= prepart ( '.' prepart ) * +prepart ::= nr | alphanumid +build ::= buildid ( '.' buildid ) * +alphanumid ::= ( [0-9] ) * [A-Za-z-] [-0-9A-Za-z] * +buildid ::= [-0-9A-Za-z]+