forked from peggyjs/peggy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request peggyjs#300 from dselman/example-semver
(feat) add semver.org example
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* SemVer.org v2 | ||
* https://semver.org/spec/v2.0.0.html | ||
* For unit tests see: https://github.com/dselman/peggy-semver | ||
*/ | ||
semver | ||
= versionCore:versionCore | ||
pre:('-' @preRelease)? | ||
build:('+' @build)? | ||
{ | ||
return { versionCore, pre, build }; | ||
} | ||
|
||
versionCore | ||
= major:$numericIdentifier '.' minor:$numericIdentifier '.' patch:$numericIdentifier | ||
{ | ||
return { | ||
major: parseInt(major, 10), | ||
minor: parseInt(minor, 10), | ||
patch: parseInt(patch, 10), | ||
}; | ||
} | ||
|
||
preRelease | ||
= head:$preReleaseIdentifier tail:('.' @$preReleaseIdentifier)* | ||
{ | ||
return [head, ...tail]; | ||
} | ||
|
||
build | ||
= head:$buildIdentifier tail:('.' @$buildIdentifier)* | ||
{ | ||
return [head, ...tail]; | ||
} | ||
|
||
preReleaseIdentifier | ||
= alphanumericIdentifier | ||
/ numericIdentifier | ||
|
||
buildIdentifier | ||
= alphanumericIdentifier | ||
/ digit+ | ||
|
||
alphanumericIdentifier | ||
= digit* nonDigit identifierChar* | ||
|
||
numericIdentifier | ||
= '0' / (positiveDigit digit*) | ||
|
||
identifierChar | ||
= [a-z0-9-]i | ||
|
||
nonDigit | ||
= [a-z-]i | ||
|
||
digit | ||
= [0-9] | ||
|
||
positiveDigit | ||
= [1-9] |