Skip to content
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

EBNF grammar #192

Closed
christianhujer opened this issue Apr 14, 2014 · 9 comments
Closed

EBNF grammar #192

christianhujer opened this issue Apr 14, 2014 · 9 comments

Comments

@christianhujer
Copy link

The Semantic Versioning Spec could have an EBNF grammar.

Here it is, according to http://www.w3.org/TR/xml/#sec-notation.

version ::= MAJOR '.' MINOR '.' PATCH ('-' PRE)? ('+' BUILD)?
MAJOR ::= decimalnumber
MINOR ::= decimalnumber
PATCH ::= decimalnumber
PRE ::= string
BUILD ::= string
string ::= [0-9A-Za-z-]+
decimalnumber ::= [0-9]+

@rlidwka
Copy link

rlidwka commented Apr 14, 2014

it's much more complex than that...

@bessarabov
Copy link
Contributor

Just in case one hasn't seen it. There is BNF grammar for SemVer: https://github.com/mojombo/semver/blob/master/semver.md#backusnaur-form-grammar-for-valid-semver-versions

@christianhujer
Copy link
Author

Just found a flaw.
decimalnumber should actually be, to disallow leading zeros:
decimalnumber ::= '0' | [1-9] [0-9]+
I've taken a look at the BNF grammar for SemVer. It is quite verbose because it is plain old BNF, which doesn't have quantifiers and character groups, unlike simple EBNF from the W3C.
But I do not care which BNF language as long as there is a BNF, any BNF is fine with me :)

@FichteFoll
Copy link

FWIW, here is a regular expression I used for my Python implementation. It's not 2.0.0-comform because I allow empty build and pre-release fields to make version selectors more simple but otherwise it should be correct. Furthermore, I added a "whitespace detection" to the regex to allow extracting it from a string, but that doesn't matter when enclosing with ^$ anyway (like I did 2 lines later).

@gvlx
Copy link

gvlx commented Jun 27, 2018

Here it is.

Please comment and correct.

@glebec
Copy link

glebec commented Oct 2, 2018

@gvlx my corrections:

  • PreReleaseIdentifier had a spurious + on NumericIdentifier
  • AlphaNumericIdentifier cannot parse as IdentifierCharacter* NonNumericCharacter ... b/c IdentifierCharacter* includes NonNumericCharacter. So a typical parser would consume all of the input using IdentifierCharacter* and then fail because there is no NonNumericCharacter to consume. The correct version is NumericCharacter* NonNumericCharacter ....
Version ::= VersionCore ('-' PreRelease)? ('+' Build)?

VersionCore ::= Major '.' Minor '.' Patch
Major ::= NumericIdentifier  
Minor ::= NumericIdentifier  
Patch ::= NumericIdentifier  
PreRelease ::= CompoundPreReleaseIdentifier 
Build      ::= CompoundBuildIdentifier 

CompoundPreReleaseIdentifier ::= PreReleaseIdentifier ('.' PreReleaseIdentifier)*
CompoundBuildIdentifier      ::= BuildIdentifier      ('.' BuildIdentifier)*

PreReleaseIdentifier     ::= AlphaNumericIdentifier | NumericIdentifier
BuildIdentifier          ::= IdentifierCharacter+

NumericIdentifier        ::= '0' | ( PositiveNumeric NumericCharacter* )
AlphaNumericIdentifier   ::= NumericCharacter* NonNumericCharacter IdentifierCharacter*

IdentifierCharacter ::= NonNumericCharacter | NumericCharacter

NonNumericCharacter ::= [A-Za-z-]
NumericCharacter    ::= '0' | PositiveNumeric
PositiveNumeric     ::= [1-9]

@gvlx
Copy link

gvlx commented Oct 2, 2018

The EBNF has been corrected by @glebec on #192 (comment) .

This issue should now be closed.

@jwdonahue
Copy link
Contributor

@christianhujer , unless you have further questions, can you please close this issue at your earliest possible convenience?

@ebkalderon
Copy link

@christianhujer Looks like the EBNF grammar has already been merged into master. Can this issue be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants