Skip to content

Commit

Permalink
[ABNF] disallow bidi override codepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
bendyarm committed Apr 14, 2022
1 parent cd8ac3b commit 447e50f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 25 deletions.
63 changes: 47 additions & 16 deletions docs/grammar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,26 @@ along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
Lexical Grammar
---------------

<a name="ascii"></a>
```abnf
ascii = %x0-7F
```

<a name="safe-nonascii"></a>
```abnf
safe-nonascii = %x80-2029 / %x202F-2065 / %x2070-D7FF / %xE000-10FFFF
; excludes bidi overrides and high/low surrogates
```

<a name="character"></a>
```abnf
character = %x0-D7FF / %xE000-10FFFF ; Unicode code points decoded from UTF-8
character = ascii / safe-nonascii
; Unicode code points decoded from UTF-8
```

Go to: _[ascii](#user-content-ascii), [safe-nonascii](#user-content-safe-nonascii)_;


<a name="horizontal-tab"></a>
```abnf
horizontal-tab = %x9 ; <HT>
Expand Down Expand Up @@ -58,33 +73,48 @@ single-quote = %x27 ; '

<a name="not-star"></a>
```abnf
not-star = %x0-29 / %x2B-D7FF / %xE000-10FFFF ; anything but *
not-star = %x0-29 / %x2B-7F / safe-nonascii ; anything but *
```

Go to: _[safe-nonascii](#user-content-safe-nonascii)_;


<a name="not-star-or-slash"></a>
```abnf
not-star-or-slash = %x0-29 / %x2B-2E / %x30-D7FF / %xE000-10FFFF
not-star-or-slash = %x0-29 / %x2B-2E / %x30-7F / safe-nonascii
; anything but * or /
```

Go to: _[safe-nonascii](#user-content-safe-nonascii)_;


<a name="not-line-feed-or-carriage-return"></a>
```abnf
not-line-feed-or-carriage-return = %x0-9 / %xB-C / %xE-D7FF / %xE000-10FFFF
not-line-feed-or-carriage-return = %x0-9 / %xB-C / %xE-7F / safe-nonascii
; anything but <LF> or <CR>
```

Go to: _[safe-nonascii](#user-content-safe-nonascii)_;


<a name="not-double-quote-or-backslash"></a>
```abnf
not-double-quote-or-backslash = %x0-21 / %x23-5B / %x5D-D7FF / %xE000-10FFFF
not-double-quote-or-backslash = %x0-21 / %x23-5B / %x5D-7F / safe-nonascii
; anything but " or \
```

Go to: _[safe-nonascii](#user-content-safe-nonascii)_;


<a name="not-single-quote-or-backslash"></a>
```abnf
not-single-quote-or-backslash = %x0-26 / %x28-5B / %x5D-D7FF / %xE000-10FFFF
not-single-quote-or-backslash = %x0-26 / %x28-5B / %x5D-7F / safe-nonascii
; anything but ' or \
```

Go to: _[safe-nonascii](#user-content-safe-nonascii)_;


<a name="line-terminator"></a>
```abnf
line-terminator = line-feed / carriage-return / carriage-return line-feed
Expand Down Expand Up @@ -148,6 +178,7 @@ keyword = %s"address"
/ %s"char"
/ %s"console"
/ %s"const"
/ %s"constant"
/ %s"else"
/ %s"field"
/ %s"for"
Expand Down Expand Up @@ -236,6 +267,15 @@ signed-literal = numeral ( %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128" )
Go to: _[numeral](#user-content-numeral)_;


<a name="integer-literal"></a>
```abnf
integer-literal = unsigned-literal
/ signed-literal
```

Go to: _[signed-literal](#user-content-signed-literal), [unsigned-literal](#user-content-unsigned-literal)_;


<a name="field-literal"></a>
```abnf
field-literal = numeral %s"field"
Expand Down Expand Up @@ -368,15 +408,6 @@ string-literal-element = not-double-quote-or-backslash
Go to: _[ascii-character-escape](#user-content-ascii-character-escape), [not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape), [unicode-character-escape](#user-content-unicode-character-escape)_;


<a name="integer-literal"></a>
```abnf
integer-literal = unsigned-literal
/ signed-literal
```

Go to: _[signed-literal](#user-content-signed-literal), [unsigned-literal](#user-content-unsigned-literal)_;


<a name="atomic-literal"></a>
```abnf
atomic-literal = integer-literal
Expand Down Expand Up @@ -805,7 +836,7 @@ Go to: _[function-parameter](#user-content-function-parameter)_;

<a name="function-parameter"></a>
```abnf
function-parameter = [ %s"public" / %s"const" ] identifier ":" type
function-parameter = [ %s"public" / %s"constant" / %s"const" ] identifier ":" type
```

Go to: _[identifier](#user-content-identifier), [type](#user-content-type)_;
Expand Down
24 changes: 15 additions & 9 deletions docs/grammar/abnf-grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
; Lexical Grammar
; ---------------

character = %x0-D7FF / %xE000-10FFFF ; Unicode code points decoded from UTF-8
ascii = %x0-7F

safe-nonascii = %x80-2029 / %x202F-2065 / %x2070-D7FF / %xE000-10FFFF
; excludes bidi overrides and high/low surrogates

character = ascii / safe-nonascii
; Unicode code points decoded from UTF-8

horizontal-tab = %x9 ; <HT>

Expand All @@ -33,18 +39,18 @@ double-quote = %x22 ; "

single-quote = %x27 ; '

not-star = %x0-29 / %x2B-D7FF / %xE000-10FFFF ; anything but *
not-star = %x0-29 / %x2B-7F / safe-nonascii ; anything but *

not-star-or-slash = %x0-29 / %x2B-2E / %x30-D7FF / %xE000-10FFFF
not-star-or-slash = %x0-29 / %x2B-2E / %x30-7F / safe-nonascii
; anything but * or /

not-line-feed-or-carriage-return = %x0-9 / %xB-C / %xE-D7FF / %xE000-10FFFF
not-line-feed-or-carriage-return = %x0-9 / %xB-C / %xE-7F / safe-nonascii
; anything but <LF> or <CR>

not-double-quote-or-backslash = %x0-21 / %x23-5B / %x5D-D7FF / %xE000-10FFFF
not-double-quote-or-backslash = %x0-21 / %x23-5B / %x5D-7F / safe-nonascii
; anything but " or \

not-single-quote-or-backslash = %x0-26 / %x28-5B / %x5D-D7FF / %xE000-10FFFF
not-single-quote-or-backslash = %x0-26 / %x28-5B / %x5D-7F / safe-nonascii
; anything but ' or \

line-terminator = line-feed / carriage-return / carriage-return line-feed
Expand Down Expand Up @@ -112,6 +118,9 @@ unsigned-literal = numeral ( %s"u8" / %s"u16" / %s"u32" / %s"u64" / %s"u128" )

signed-literal = numeral ( %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128" )

integer-literal = unsigned-literal
/ signed-literal

field-literal = numeral %s"field"

product-group-literal = numeral %s"group"
Expand Down Expand Up @@ -160,9 +169,6 @@ string-literal-element = not-double-quote-or-backslash
/ ascii-character-escape
/ unicode-character-escape

integer-literal = unsigned-literal
/ signed-literal

atomic-literal = integer-literal
/ field-literal
/ product-group-literal
Expand Down

0 comments on commit 447e50f

Please sign in to comment.