<?xml version="1.0" encoding="UTF-8"?>
<spec xmlns="https://vibevm.org/spec/1">
  <title>Considerations</title>
  <section title="Extensibility">
    <p p="1">Implementations storing or copying content MUST NOT modify or alter the content in a way that would change the digest of the content.
Examples of these implementations include:</p>
    <list ordered="false" p="2">
      <item>A [registry implementing the distribution specification][distribution-spec], including local registries, caching proxies</item>
      <item>An application which copies content to disk or between registries</item>
    </list>
    <p p="3">Implementations processing content SHOULD NOT generate an error if they encounter an unknown property in a known media type.
Examples of these implementations include:</p>
    <list ordered="false" p="4">
      <item>A [runtime implementing the runtime specification][runtime-spec]</item>
      <item>An implementation using OCI to retrieve and utilize artifacts, e.g.: a WASM runtime</item>
    </list>
  </section>
  <section title="Canonicalization">
    <list ordered="false" p="5">
      <item>OCI Images are [content-addressable](https://en.wikipedia.org/wiki/Content-addressable_storage). See [descriptors](descriptor.md) for more.</item>
      <item>One benefit of content-addressable storage is easy deduplication.</item>
      <item>Many images might depend on a particular [layer](layer.md), but there will only be one blob in the [store](image-layout.md).</item>
      <item>With a different serialization, that same semantic layer would have a different hash, and if both versions of the layer are referenced there will be two blobs with the same semantic content.</item>
      <item>To allow efficient storage, implementations serializing content for blobs SHOULD use a canonical serialization.</item>
      <item>This increases the chance that different implementations can push the same semantic content to the store without creating redundant blobs.</item>
    </list>
  </section>
  <section title="JSON">
    <p p="6">Of the [OCI Image Format Specification media types](media-types.md), all the types ending in `+json` contain JSON content.
All [JSON][JSON] content MUST follow the I-JSON limitations in [RFC 7493][rfc7493]:</p>
    <list ordered="false" p="7">
      <item>The encoding MUST be [UTF-8][rfc3629]</item>
      <item>Numbers SHOULD be limited to IEEE 754 double precision</item>
      <item>Objects MUST NOT contain duplicate names</item>
    </list>
    <p p="8">The order of entries in JSON objects is not significant.
Implementations MAY implement Canonical JSON documented in [RFC 8785][rfc8785].</p>
  </section>
  <section title="EBNF">
    <p p="9">For field formats described in this specification, we use a limited subset of [Extended Backus-Naur Form][ebnf], similar to that used by the [XML specification][xmlebnf].
Grammars present in the OCI specification are regular and can be converted to a single regular expressions.
However, regular expressions are avoided to limit ambiguity between regular expression syntax.
By defining a subset of EBNF used here, the possibility of variation, misunderstanding or ambiguities from linking to a larger specification can be avoided.</p>
    <p p="10">Grammars are made up of rules in the following form:</p>
    <fence lang="ebnf" p="11">symbol ::= expression</fence>
    <p p="12">We can say we have the production identified by symbol if the input is matched by the expression.
Whitespace is completely ignored in rule definitions.</p>
    <section title="Expressions">
      <p p="13">The simplest expression is the literal, surrounded by quotes:</p>
      <fence lang="ebnf" p="14">literal ::= "matchthis"</fence>
      <p p="15">The above expression defines a symbol, "literal", that matches the exact input of "matchthis".
Character classes are delineated by brackets (`[]`), describing either a set, range or multiple range of characters:</p>
      <fence lang="ebnf" p="16">set := [abc]
range := [A-Z]</fence>
      <p p="17">The above symbol "set" would match one character of either "a", "b" or "c".
The symbol "range" would match any character, "A" to "Z", inclusive.
Currently, only matching for 7-bit ascii literals and character classes is defined, as that is all that is required by this specification.
Multiple character ranges and explicit characters can be specified in a single character classes, as follows:</p>
      <fence lang="ebnf" p="18">multipleranges := [a-zA-Z=-]</fence>
      <p p="19">The above matches the characters in the range `A` to `Z`, `a` to `z` and the individual characters `-` and `=`.</p>
      <p p="20">Expressions can be made up of one or more expressions, such that one must be followed by the other.
This is known as an implicit concatenation operator.
For example, to satisfy the following rule, both `A` and `B` must be matched to satisfy the rule:</p>
      <fence lang="ebnf" p="21">symbol ::= A B</fence>
      <p p="22">Each expression must be matched once and only once, `A` followed by `B`.
To support the description of repetition and optional match criteria, the postfix operators `*` and `+` are defined.
`*` indicates that the preceding expression can be matched zero or more times.
`+` indicates that the preceding expression must be matched one or more times.
These appear in the following form:</p>
      <fence lang="ebnf" p="23">zeroormore ::= expression*
oneormore ::= expression+</fence>
      <p p="24">Parentheses are used to group expressions into a larger expression:</p>
      <fence lang="ebnf" p="25">group ::= (A B)</fence>
      <p p="26">Like simpler expressions above, operators can be applied to groups, as well.
To allow for alternates, we also define the infix operator `|`.</p>
      <fence lang="ebnf" p="27">oneof ::= A | B</fence>
      <p p="28">The above indicates that the expression should match one of the expressions, `A` or `B`.</p>
    </section>
    <section title="Precedence">
      <p p="29">The operator precedence is in the following order:</p>
      <list ordered="false" p="30">
        <item>Terminals (literals and character classes)</item>
        <item>Grouping `()`</item>
        <item>Unary operators `+*`</item>
        <item>Concatenation</item>
        <item>Alternates `|`</item>
      </list>
      <p p="31">The precedence can be better described using grouping to show equivalents.
Concatenation has higher precedence than alternates, such `A B | C D` is equivalent to `(A B) | (C D)`.
Unary operators have higher precedence than alternates and concatenation, such that `A+ | B+` is equivalent to `(A+) | (B+)`.</p>
    </section>
    <section title="Examples">
      <p p="32">The following combines the previous definitions to match a simple, relative path name, describing the individual components:</p>
      <fence lang="ebnf" p="33">path      ::= component ("/" component)*
component ::= [a-z]+</fence>
      <p p="34">The production "component" is one or more lowercase letters.
A "path" is then at least one component, possibly followed by zero or more slash-component pairs.
The above can be converted into the following regular expression:</p>
      <fence lang="regex" p="35">[a-z]+(?:/[a-z]+)*</fence>
      <p p="36">[distribution-spec]: https://github.com/opencontainers/distribution-spec/blob/main/spec.md
[ebnf]: https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form
[JSON]: https://json.org/
[rfc3629]: https://datatracker.ietf.org/doc/html/rfc3629
[rfc7493]: https://datatracker.ietf.org/doc/html/rfc7493
[rfc8785]: https://datatracker.ietf.org/doc/html/rfc8785
[runtime-spec]: https://github.com/opencontainers/runtime-spec/blob/main/spec.md
[xmlebnf]: https://www.w3.org/TR/REC-xml/#sec-notation</p>
    </section>
  </section>
</spec>
