Skip to content

Instantly share code, notes, and snippets.

@myfonj
Last active October 16, 2023 12:19
Show Gist options
  • Save myfonj/ffc13bdfc0a473b6cadc5f8d00e5662a to your computer and use it in GitHub Desktop.
Save myfonj/ffc13bdfc0a473b6cadc5f8d00e5662a to your computer and use it in GitHub Desktop.
semver.bnf
# taken from https://semver.org/spec/v2.0.0.html#backusnaur-form-grammar-for-valid-semver-versions
# modified to be "more clear"
<semver> ::= <version>
| <version> "-" <pre>
| <version> "+" <build>
| <version> "-" <pre> "+" <build>
<version> ::= <major> "." <minor> "." <patch>
<major> ::= <number>
<minor> ::= <number>
<patch> ::= <number>
<pre> ::= <pre_chunks>
<build> ::= <build_chunks>
<pre_chunks> ::= <number_or_string>
| <number_or_string> "." <pre_chunks>
<build_chunks> ::= <digits_or_string>
| <digits_or_string> "." <build_chunks>
# either single zero, positive number, or string (mix of letters and numbers)
<number_or_string> ::= <number>
| <string>
# similar, just any amount of zeros also works
<digits_or_string> ::= <digits>
| <string>
# originally "<alphanumeric_identifier>"
# basically string consisting of at least one non-digit anywhere
<string> ::= <letter>
| <letter> <characters>
| <characters> <letter>
| <characters> <letter> <characters>
<characters> ::= <character>
| <character> <characters>
<character> ::= <digit>
| <letter>
<letter> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J"
| "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T"
| "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d"
| "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n"
| "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x"
| "y" | "z" | "-"
<number> ::= "0"
| <positive_digit>
| <positive_digit> <digits>
<digits> ::= <digit>
| <digit> <digits>
<digit> ::= "0"
| <positive_digit>
<positive_digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
# taken from https://semver.org/spec/v2.0.0.html#backusnaur-form-grammar-for-valid-semver-versions
<valid semver> ::= <version core>
| <version core> "-" <pre-release>
| <version core> "+" <build>
| <version core> "-" <pre-release> "+" <build>
<version core> ::= <major> "." <minor> "." <patch>
<major> ::= <numeric identifier>
<minor> ::= <numeric identifier>
<patch> ::= <numeric identifier>
<pre-release> ::= <dot-separated pre-release identifiers>
<dot-separated pre-release identifiers> ::= <pre-release identifier>
| <pre-release identifier> "." <dot-separated pre-release identifiers>
<build> ::= <dot-separated build identifiers>
<dot-separated build identifiers> ::= <build identifier>
| <build identifier> "." <dot-separated build identifiers>
<pre-release identifier> ::= <alphanumeric identifier>
| <numeric identifier>
<build identifier> ::= <alphanumeric identifier>
| <digits>
<alphanumeric identifier> ::= <non-digit>
| <non-digit> <identifier characters>
| <identifier characters> <non-digit>
| <identifier characters> <non-digit> <identifier characters>
<numeric identifier> ::= "0"
| <positive digit>
| <positive digit> <digits>
<identifier characters> ::= <identifier character>
| <identifier character> <identifier characters>
<identifier character> ::= <digit>
| <non-digit>
<non-digit> ::= <letter>
| "-"
<digits> ::= <digit>
| <digit> <digits>
<digit> ::= "0"
| <positive digit>
<positive digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<letter> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J"
| "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T"
| "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d"
| "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n"
| "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x"
| "y" | "z"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment