Skip to content

Commit

Permalink
Collapse all escape sequence rules into one (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed May 13, 2024
1 parent 6414b6c commit 60c1b1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
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 @@ -158,7 +158,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 @@ -264,7 +264,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 @@ -300,7 +300,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 @@ -675,7 +675,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 @@ -852,7 +852,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 @@ -934,14 +934,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

0 comments on commit 60c1b1f

Please sign in to comment.