Skip to content

Collapse all escape sequence rules into one #743

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

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions spec/message.abnf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
message = simple-message / complex-message

simple-message = [simple-start pattern]
simple-start = simple-start-char / text-escape / placeholder
pattern = *(text-char / text-escape / placeholder)
simple-start = simple-start-char / escaped-char / placeholder
pattern = *(text-char / escaped-char / placeholder)
placeholder = expression / markup

complex-message = *(declaration [s]) complex-body
Expand Down Expand Up @@ -43,7 +43,7 @@ attribute = "@" identifier [[s] "=" [s] (literal / variable)]

variable = "$" name
literal = quoted / unquoted
quoted = "|" *(quoted-char / quoted-escape) "|"
quoted = "|" *(quoted-char / escaped-char) "|"
unquoted = name / number-literal
; number-literal matches JSON number (https://www.rfc-editor.org/rfc/rfc8259#section-6)
number-literal = ["-"] (%x30 / (%x31-39 *DIGIT)) ["." 1*DIGIT] [%i"e" ["-" / "+"] 1*DIGIT]
Expand All @@ -68,7 +68,7 @@ reserved-annotation-start = "!" / "%" / "*" / "+" / "<" / ">" / "?" / "~"
private-use-annotation = private-start [[s] reserved-body]
private-start = "^" / "&"
reserved-body = reserved-body-part *([s] reserved-body-part)
reserved-body-part = reserved-char / reserved-escape / quoted
reserved-body-part = reserved-char / escaped-char / quoted

; Names and identifiers
; identifier matches https://www.w3.org/TR/REC-xml-names/#NT-QName
Expand Down Expand Up @@ -101,10 +101,8 @@ content-char = %x01-08 ; omit NULL (%x00), HTAB (%x09) and LF (%x0A)
/ %xE000-10FFFF

; Character escapes
text-escape = backslash ( backslash / "{" / "}" )
quoted-escape = backslash ( backslash / "|" )
reserved-escape = backslash ( backslash / "{" / "|" / "}" )
backslash = %x5C ; U+005C REVERSE SOLIDUS "\"
escaped-char = backslash ( backslash / "{" / "|" / "}" )
backslash = %x5C ; U+005C REVERSE SOLIDUS "\"

; Whitespace
s = 1*( SP / HTAB / CR / LF / %x3000 )
21 changes: 10 additions & 11 deletions spec/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ An empty string is a valid _simple message_.

```abnf
simple-message = [simple-start pattern]
simple-start = simple-start-char / text-escape / placeholder
simple-start = simple-start-char / escaped-char / placeholder
```

A **_<dfn>complex message</dfn>_** is any _message_ that contains _declarations_,
Expand Down Expand Up @@ -255,7 +255,7 @@ Unless there is an error, resolving a _message_ always results in the formatting
of a single _pattern_.

```abnf
pattern = *(text-char / text-escape / placeholder)
pattern = *(text-char / escaped-char / placeholder)
```
A _pattern_ MAY be empty.

Expand Down Expand Up @@ -291,7 +291,7 @@ U+007B LEFT CURLY BRACKET `{`, and U+007D RIGHT CURLY BRACKET `}`
MUST be escaped as `\\`, `\{`, and `\}` respectively.

In the ABNF, _text_ is represented by non-empty sequences of
`simple-start-char`, `text-char`, and `text-escape`.
`simple-start-char`, `text-char`, and `escaped-char`.
The first of these is used at the start of a _simple message_,
and matches `text-char` except for not allowing U+002E FULL STOP `.`.
The ABNF uses `content-char` as a shared base for _text_ and _quoted literal_ characters.
Expand Down Expand Up @@ -666,7 +666,7 @@ reserved-annotation = reserved-annotation-start [[s] reserved-body]
reserved-annotation-start = "!" / "%" / "*" / "+" / "<" / ">" / "?" / "~"

reserved-body = reserved-body-part *([s] reserved-body-part)
reserved-body-part = reserved-char / reserved-escape / quoted
reserved-body-part = reserved-char / escaped-char / quoted
```

## Markup
Expand Down Expand Up @@ -843,7 +843,7 @@ of number values in _operands_ or _options_, or as _keys_ for _variants_.

```abnf
literal = quoted / unquoted
quoted = "|" *(quoted-char / quoted-escape) "|"
quoted = "|" *(quoted-char / escaped-char) "|"
unquoted = name / number-literal
number-literal = ["-"] (%x30 / (%x31-39 *DIGIT)) ["." 1*DIGIT] [%i"e" ["-" / "+"] 1*DIGIT]
```
Expand Down Expand Up @@ -925,14 +925,13 @@ An **_<dfn>escape sequence</dfn>_** is a two-character sequence starting with
U+005C REVERSE SOLIDUS `\`.

An _escape sequence_ allows the appearance of lexically meaningful characters
in the body of _text_, _quoted_, or _reserved_ (which includes, in this case,
_private-use_) sequences respectively:
in the body of _text_, _quoted_, or _reserved_
(which includes, in this case, _private-use_) sequences.
Each _escape sequence_ represents the literal character immediately following the initial `\`.

```abnf
text-escape = backslash ( backslash / "{" / "}" )
quoted-escape = backslash ( backslash / "|" )
reserved-escape = backslash ( backslash / "{" / "|" / "}" )
backslash = %x5C ; U+005C REVERSE SOLIDUS "\"
escaped-char = backslash ( backslash / "{" / "|" / "}" )
backslash = %x5C ; U+005C REVERSE SOLIDUS "\"
```

### Whitespace
Expand Down