You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To clarify the grammar definitions, we define the subset of EBNF used by
this specification to specify various field formats.
Signed-off-by: Stephen J Day <[email protected]>
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].
31
+
Grammars present in the OCI specification are regular and can be converted to a single regular expressions.
32
+
However, regular expressions are avoided to limit abiguity between regular expression syntax.
33
+
By defining a subset of EBNF used here, the possibility of variation, misunderstanding or ambiguities from linking to a larger specification can be avoided.
34
+
35
+
Grammars are made up of rules in the following form:
36
+
37
+
```
38
+
symbol ::= expression
39
+
```
40
+
41
+
We can say we have the production identified by symbol if the input is matched by the expression.
42
+
Whitespace is completely ignored in rule definitions.
43
+
44
+
## Expressions
45
+
46
+
The simplest expression is the literal, surrounded by quotes:
47
+
48
+
```
49
+
literal ::= "matchthis"
50
+
```
51
+
52
+
The above expression defines a symbol, "literal", that matches the exact input of "matchthis".
53
+
Character classes are delineated by brackets (`[]`), describing either a set, range or multiple range of characters:
54
+
55
+
```
56
+
set := [abc]
57
+
range := [A-Z]
58
+
```
59
+
60
+
The above symbol "set" would match one character of either "a", "b" or "c".
61
+
The symbol "range" would match any character, "A" to "Z", inclusive.
62
+
Currently, only matching for 7-bit ascii literals and character classes is defined, as that is all that is required by this specification.
63
+
64
+
Expressions can be made up of one or more expressions, such that one must be followed by the other.
65
+
This is known as an implicit concatenation operator.
66
+
For example, to satisfy the following rule, both `A` and `B` must be matched to satisfy the rule:
67
+
68
+
```
69
+
symbol ::= A B
70
+
```
71
+
72
+
Each expression must be matched once and only once, `A` followed by `B`.
73
+
To support the description of repetition and optional match criteria, the postfix operators `*` and `+` are defined.
74
+
`*` indicates that the preceeding expression can be matched zero or more times.
75
+
`+` indicates that the preceeding expression must be matched one or more times.
76
+
These appear in the following form:
77
+
78
+
```
79
+
zeroormore ::= expression*
80
+
oneormore ::= expression+
81
+
```
82
+
83
+
Parentheses are used to group expressions into a larger expression:
84
+
85
+
```
86
+
group ::= (A B)
87
+
```
88
+
89
+
Like simpler expressions above, operators can be applied to groups, as well.
90
+
To allow for alternates, we also define the infix operator `|`.
91
+
92
+
```
93
+
oneof ::= A | B
94
+
```
95
+
96
+
The above indicates that the expression should match one of the expressions, `A` or `B`.
97
+
98
+
## Precedence
99
+
100
+
The operator precedence is in the following order:
101
+
102
+
- Terminals (literals and character classes)
103
+
- Grouping `()`
104
+
- Unary operators `+*`
105
+
- Concatenation
106
+
- Alternates `|`
107
+
108
+
The precedence can be better described using grouping to show equivalents.
109
+
Concatenation has higher precedence than alernates, such `A B | C D` is equivalent to `(A B) | (C D)`.
110
+
Unary operators have higher precedence than alternates and concatenation, such that `A+ | B+` is equivalent to `(A+) | (B+)`.
111
+
112
+
## Examples
113
+
114
+
The following combines the previous definitions to match a simple, relative path name, describing the individual components:
115
+
116
+
```
117
+
path ::= component ("/" component)*
118
+
component ::= [a-z]+
119
+
```
120
+
121
+
The production "component" is one or more lowercase letters.
122
+
A "path" is then at least one component, possibly followed by zero or more slash-component pairs.
123
+
The above can be converted into the following regular expression:
Copy file name to clipboardExpand all lines: descriptor.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -66,14 +66,14 @@ If the _digest_ can be communicated in a secure manner, one can verify content f
66
66
The value of the `digest` property is a string consisting of an _algorithm_ portion and an _encoded_ portion.
67
67
The _algorithm_ specifies the cryptographic hash function and encoding used for the digest; the _encoded_ portion contains the encoded result of the hash function.
68
68
69
-
A digest string MUST match the following grammar:
69
+
A digest string MUST match the following [grammar](considerations.md#ebnf):
0 commit comments