Skip to content

Commit

Permalink
More 2119 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Oct 18, 2023
1 parent 414d5fc commit dcd5d19
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ A [=component=] has an associated <dfn for=component>group name list</dfn>, a [=
1. If |options|'s [=options/ignore case=] is true then set |flags| to "`vi`".
1. Otherwise set |flags| to "`v`"
1. Let |regular expression| be [$RegExpCreate$](|regular expression string|, |flags|). If this throws an exception, catch it, and throw a {{TypeError}}.
<p class="note">The specification uses regular expressions to perform all matching, but this is not required. Implementations are free to perform matching directly against the [=/part list=] when possible; e.g. when there are no custom regexp matching groups. If there are custom regular expressions, however, its important that they be immediately evaluated in the [=compile a component=] algorithm so an error can be thrown if they are invalid.
<p class="note">The specification uses regular expressions to perform all matching, but this is not mandated. Implementations are free to perform matching directly against the [=/part list=] when possible; e.g. when there are no custom regexp matching groups. If there are custom regular expressions, however, its important that they be immediately evaluated in the [=compile a component=] algorithm so an error can be thrown if they are invalid.
1. Let |pattern string| be the result of running [=generate a pattern string=] given |part list| and |options|.
1. Return a new [=component=] whose [=component/pattern string=] is |pattern string|, [=component/regular expression=] is |regular expression|, and [=component/group name list=] is |name list|.
</div>
Expand Down Expand Up @@ -523,12 +523,10 @@ To <dfn>parse a constructor string</dfn> given a string |input|:
</div>
1. [=While=] |parser|'s [=constructor string parser/token index=] is less than |parser|'s [=constructor string parser/token list=] [=list/size=]:
1. Set |parser|'s [=constructor string parser/token increment=] to 1.
<p class="note allow-2119">On every iteration of the parse loop the |parser|'s [=constructor string parser/token index=] will be incremented by its [=constructor string parser/token increment=] value. Typically this means incrementing by 1, but at certain times it is set to zero. The [=constructor string parser/token increment=] is then always reset back to 1 at the top of the loop.
<p class="note">On every iteration of the parse loop the |parser|'s [=constructor string parser/token index=] will be incremented by its [=constructor string parser/token increment=] value. Typically this means incrementing by 1, but at certain times it is set to zero. The [=constructor string parser/token increment=] is then always reset back to 1 at the top of the loop.
1. If |parser|'s [=constructor string parser/token list=][|parser|'s [=constructor string parser/token index=]]'s [=token/type=] is "<a for=token/type>`end`</a>" then:
1. If |parser|'s [=constructor string parser/state=] is "<a for="constructor string parser/state">`init`</a>":
<div class=note>
<p class=allow-2119>If we reached the end of the string in the "<a for="constructor string parser/state">`init`</a>" [=constructor string parser/state=], then we failed to find a protocol terminator and this must be a relative URLPattern constructor string.
</div>
<p class="note">If we reached the end of the string in the "<a for="constructor string parser/state">`init`</a>" [=constructor string parser/state=], then we failed to find a protocol terminator and this has to be a relative URLPattern constructor string.
1. Run [=rewind=] given |parser|.
<p class=note>We next determine at which component the relative pattern begins. Relative pathnames are most common, but URLs and URLPattern constructor strings can begin with the search or hash components as well.
1. If the result of running [=is a hash prefix=] given |parser| is true, then run [=change state=] given |parser|, "<a for="constructor string parser/state">`hash`</a>" and 1.
Expand Down Expand Up @@ -813,7 +811,7 @@ It can be [=parse a pattern string|parsed=] to produce a [=/part list=] which de

A regular expression can also be used instead, so the pathname pattern "`/blog/:year(\\d+)/:month(\\d+)`" will match "`/blog/2012/02`".

A group can also be made <span class=allow-2119>optional</span>, or repeated, by using a modifier. For example, the pathname pattern "`/products/:id?"` will match both "`/products`" and "`/products/2`" (but not "`/products/`"). In the pathname specifically, groups automatically require a leading `/`; to avoid this, the group can be explicitly deliminated, as in the pathname pattern "`/products/{:id}?`".
A group can also be made <span class="allow-2119">optional</span>, or repeated, by using a modifier. For example, the pathname pattern "`/products/:id?"` will match both "`/products`" and "`/products/2`" (but not "`/products/`"). In the pathname specifically, groups automatically require a leading `/`; to avoid this, the group can be explicitly deliminated, as in the pathname pattern "`/products/{:id}?`".

A full wildcard `*` can also be used to match as much as possible, as in the pathname pattern "`/products/*`".
</div>
Expand Down Expand Up @@ -1157,7 +1155,7 @@ To <dfn>parse a pattern string</dfn> given a [=/pattern string=] |input|, [=/opt
1. [=Continue=].
1. Let |open token| be the result of running [=try to consume a token=] given |parser| and "<a for=token/type>`open`</a>".
<div class="example" id="parsing-example-2">
<p>Next we look for the sequence `<open><char prefix><name><regexp><char suffix><close><modifier>`. The open and close are necessary, but the other tokens are optional.
<p>Next we look for the sequence `<open><char prefix><name><regexp><char suffix><close><modifier>`. The open and close are necessary, but the other tokens are not.
<dl>
<dt>"`{a:foo(bar)b}?`"</dt>
<dd>All [=tokens=] are present.
Expand Down Expand Up @@ -1335,7 +1333,7 @@ To <dfn export>generate a regular expression and name list</dfn> from a given [=
1. Otherwise if |part|'s [=part/type=] is "<a for=part/type>`full-wildcard`</a>", then set |regexp value| to [=full wildcard regexp value=].
1. If |part|'s [=part/prefix=] is the empty string and |part|'s [=part/suffix=] is the empty string:
<div class=note>
<p class=allow-2119>If there is no [=part/prefix=] or [=part/suffix=] then generation depends on the modifier. If there is no modifier or just the optional modifier, it uses the following simple form:
<p>If there is no [=part/prefix=] or [=part/suffix=] then generation depends on the modifier. If there is no modifier or just the <span class="allow-2119">optional</span> modifier, it uses the following simple form:
<p>`(<regexp value>)<modifier>`
<p>If there is a repeating modifier, however, we will use the more complex form:
<p>`((?:<regexp value>)<modifier>)`
Expand Down Expand Up @@ -1369,7 +1367,7 @@ To <dfn export>generate a regular expression and name list</dfn> from a given [=
1. [=Assert=]: |part|'s [=part/modifier=] is "<a for=part/modifier>`zero-or-more`</a>" or "<a for=part/modifier>`one-or-more`</a>".
1. [=Assert=]: |part|'s [=part/prefix=] is not the empty string or |part|'s [=part/suffix=] is not the empty string.
<div class=note>
<p class=allow-2119>Repeating parts with a [=part/prefix=] or [=part/suffix=] are dramatically more complicated. We want to exclude the initial [=part/prefix=] and the final [=part/suffix=], but include them between any repeated elements. To achieve this we provide a separate initial expression that excludes the [=part/prefix=]. Then the expression is duplicated with the [=part/prefix=]/[=part/suffix=] values included in an optional repeating element. If zero values are permitted then a final optional modifier may be appended. The resulting form is as follows.
<p>Repeating parts with a [=part/prefix=] or [=part/suffix=] are dramatically more complicated. We want to exclude the initial [=part/prefix=] and the final [=part/suffix=], but include them between any repeated elements. To achieve this we provide a separate initial expression that excludes the [=part/prefix=]. Then the expression is duplicated with the [=part/prefix=]/[=part/suffix=] values included in an <span class="allow-2119">optional</span> repeating element. If zero values are permitted then a final <span class="allow-2119">optional</span> modifier can be appended. The resulting form is as follows.
<p>`(?:<prefix>((?:<regexp value>)(?:<suffix><prefix>(?:<regexp value>))*)<suffix>)?`
</div>
1. Append "`(?:`" to the end of |result|.
Expand Down

0 comments on commit dcd5d19

Please sign in to comment.