Commit 37776c3
docs: fix BNF grammar to distinguish prerelease from build identifiers (#846)
## Summary
The BNF grammar in `README.md` and `range.bnf` incorrectly defined `pre`
and `build` as identical rules (`parts`), but they have different
requirements per the [SemVer 2.0.0
specification](https://semver.org/#spec-item-9):
- **Prerelease identifiers**: Numeric parts must not have leading zeros
- **Build metadata**: Allows any alphanumeric string including leading
zeros
### Current behavior (correctly implemented, but BNF was wrong)
```js
semver.valid('1.2.3-00') // null (invalid - prerelease numeric with leading zero)
semver.valid('1.2.3+00') // '1.2.3' (valid - build metadata allows any alphanumeric)
semver.valid('1.2.3-0') // '1.2.3-0' (valid - single zero is fine)
```
### Changes
Updates the BNF grammar to distinguish between:
- `prepart` - uses `nr` (no leading zeros) or `alphanumid` (alphanumeric
identifier)
- `buildid` - any alphanumeric string including leading zeros
Also adds an explanatory note after the BNF block to clarify the
distinction.
Fixes #665
## Test plan
- [x] Verified the implementation behavior matches the updated BNF
- [x] Confirmed alignment with [SemVer 2.0.0 spec item
9](https://semver.org/#spec-item-9)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 5993c2e commit 37776c3
2 files changed
Lines changed: 16 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
406 | 407 | | |
407 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
408 | 415 | | |
409 | 416 | | |
410 | 417 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
0 commit comments