-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
peggy.js grammar for semver #299
Comments
Interesting. If you'd like to contribute it to the Peggy project, you could remove the Apache license and create a PR where you also add yourself to the AUTHORS file, and a bullet to CHANGELOG.md, which I'd accept. As far as the grammar goes, here are some suggestions:
rule
= alt1
/ alt2
/ alt3 Great work so far! |
Hi @dselman I got inspired by your work and tried to avoid the 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] |
That's awesome - thank you @hildjj and @MarcelBolten -- much more elegant. |
PR created: #300 |
Fixed in #304 |
I've recently been working on a peggy.js grammar for semver strings. I'd welcome feedback and if suitable you are welcome to add it to your library of example grammars.
https://github.com/dselman/peggy-semver/blob/main/parser.pegjs
The text was updated successfully, but these errors were encountered: