Skip to content

Commit

Permalink
Merge pull request peggyjs#300 from dselman/example-semver
Browse files Browse the repository at this point in the history
(feat) add semver.org example
  • Loading branch information
hildjj authored Jun 20, 2022
2 parents d603d74 + 0a200be commit 4b98f92
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Balázs Kutil <bkutil@users.noreply.github.com> (https://github.com/bkutil/)
Caleb Hearon <crh0872@gmail.com> (https://github.com/chearon/)
Charles Pick <charles@codemix.com> (https://github.com/phpnode/)
Christian Flach <github@christianflach.de> (https://github.com/cmfcmf/)
Dan Selman <danscode@selman.org> (https://github.com/dselman)
David Berneda <david@steema.com>
Futago-za Ryuu <futagoza.ryuu@gmail.com> (https://github.com/futagoza/)
Jakub Vrana <jakub@vrana.cz> (https://github.com/vrana/)
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This file documents all notable changes to Peggy.
Unreleased
----------

- [#299](https://github.com/peggyjs/peggy/issues/299) Add example grammar for a
[SemVer.org](https://semver.org) semantic version string

Released: TBD

### Major Changes
Expand Down
60 changes: 60 additions & 0 deletions examples/semver.peggy
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]

0 comments on commit 4b98f92

Please sign in to comment.