From 369fd8aef1a38373151e23a6a0da33baa7621f6d Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:34:23 +0530 Subject: [PATCH 01/13] abnf: :art: minor style changes --- README.md | 8 +++----- toml.abnf | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dd999419..941ceba1 100644 --- a/README.md +++ b/README.md @@ -125,8 +125,6 @@ as strings. **Quoted keys** follow the exact same rules as either basic strings or literal strings and allow you to use a much broader set of key names. Best practice is to use bare keys except when absolutely necessary. - - ```toml key = "value" bare_key = "value" @@ -149,8 +147,8 @@ discouraged). '' = 'blank' # VALID but discouraged ``` -Values must be of the following types: String, Integer, Float, Boolean, Datetime, -Array, or Inline Table. Unspecified values are invalid. +Values must be of the following types: String, Integer, Float, Boolean, +Datetime, Array, or Inline Table. Unspecified values are invalid. ```toml key = # INVALID @@ -327,6 +325,7 @@ flt6 = -2E-2 # both flt7 = 6.626e-34 ``` + A fractional part is a decimal point followed by one or more digits. An exponent part is an E (upper or lower case) followed by an integer part @@ -409,7 +408,6 @@ timezone. ```toml lt1 = 07:32:00 lt2 = 00:32:00.999999 - ``` The precision of fractional seconds is implementation specific, but at least diff --git a/toml.abnf b/toml.abnf index 002dd470..52fd018b 100644 --- a/toml.abnf +++ b/toml.abnf @@ -57,7 +57,7 @@ table = std-table / array-table ;; Standard Table -std-table = std-table-open key *( table-key-sep key) std-table-close +std-table = std-table-open key *( table-key-sep key ) std-table-close std-table-open = %x5B ws ; [ Left square bracket std-table-close = ws %x5D ; ] Right square bracket @@ -65,7 +65,7 @@ table-key-sep = ws %x2E ws ; . Period ;; Array Table -array-table = array-table-open key *( table-key-sep key) array-table-close +array-table = array-table-open key *( table-key-sep key ) array-table-close array-table-open = %x5B.5B ws ; [[ Double left square bracket array-table-close = ws %x5D.5D ; ]] Double right quare bracket @@ -123,7 +123,7 @@ ml-basic-string = ml-basic-string-delim ml-basic-body ml-basic-string-delim ml-basic-string-delim = 3quotation-mark -ml-basic-body = *( ml-basic-char / newline / ( escape ws newline )) +ml-basic-body = *( ml-basic-char / newline / ( escape ws newline ) ) ml-basic-char = ml-basic-unescaped / escaped ml-basic-unescaped = %x20-5B / %x5D-10FFFF @@ -165,7 +165,7 @@ time-secfrac = "." 1*DIGIT time-numoffset = ( "+" / "-" ) time-hour ":" time-minute time-offset = "Z" / time-numoffset -partial-time = time-hour ":" time-minute ":" time-second [time-secfrac] +partial-time = time-hour ":" time-minute ":" time-second [ time-secfrac ] full-date = date-fullyear "-" date-month "-" date-mday full-time = partial-time time-offset From f2688253edf5c8111c67cdba258a8bccdad90540 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:02:51 +0530 Subject: [PATCH 02/13] abnf: Restructure to match README's flow --- toml.abnf | 94 +++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/toml.abnf b/toml.abnf index 52fd018b..92083f15 100644 --- a/toml.abnf +++ b/toml.abnf @@ -12,7 +12,7 @@ ;; ml-basic-unescaped = basic-unescaped ;; ml-literal-char = literal-char -;; TOML +;; Overall Structure toml = expression *( newline expression ) @@ -21,11 +21,6 @@ expression = ( ( ws comment ) / ( ws table ws [ comment ] ) / ws ) -;; Newline - -newline = ( %x0A / ; LF - %x0D.0A ) ; CRLF - ;; Whitespace ws = *wschar @@ -33,6 +28,11 @@ ws = *wschar wschar = ( %x20 / ; Space %x09 ) ; Horizontal tab +;; Newline + +newline = ( %x0A / ; LF + %x0D.0A ) ; CRLF + ;; Comment comment-start-symbol = %x23 ; # @@ -51,47 +51,6 @@ keyval-sep = ws %x3D ws ; = val = string / boolean / array / inline-table / date-time / float / integer -;; Table - -table = std-table / array-table - -;; Standard Table - -std-table = std-table-open key *( table-key-sep key ) std-table-close - -std-table-open = %x5B ws ; [ Left square bracket -std-table-close = ws %x5D ; ] Right square bracket -table-key-sep = ws %x2E ws ; . Period - -;; Array Table - -array-table = array-table-open key *( table-key-sep key ) array-table-close - -array-table-open = %x5B.5B ws ; [[ Double left square bracket -array-table-close = ws %x5D.5D ; ]] Double right quare bracket - -;; Integer - -integer = [ minus / plus ] int - -minus = %x2D ; - -plus = %x2B ; + - -int = DIGIT / digit1-9 1*( DIGIT / underscore DIGIT ) -digit1-9 = %x31-39 ; 1-9 -underscore = %x5F ; _ - -;; Float - -float = integer ( frac / ( frac exp ) / exp ) - -frac = decimal-point zero-prefixable-int -decimal-point = %x2E ; . -zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT ) - -exp = e integer -e = %x65 / %x45 ; e E - ;; String string = ml-basic-string / basic-string / ml-literal-string / literal-string @@ -144,6 +103,28 @@ ml-literal-string-delim = 3apostrophe ml-literal-body = *( ml-literal-char / newline ) ml-literal-char = %x09 / %x20-10FFFF +;; Integer + +integer = [ minus / plus ] int + +minus = %x2D ; - +plus = %x2B ; + + +int = DIGIT / digit1-9 1*( DIGIT / underscore DIGIT ) +digit1-9 = %x31-39 ; 1-9 +underscore = %x5F ; _ + +;; Float + +float = integer ( frac / ( frac exp ) / exp ) + +frac = decimal-point zero-prefixable-int +decimal-point = %x2E ; . +zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT ) + +exp = e integer +e = %x65 / %x45 ; e E + ;; Boolean boolean = true / false @@ -200,6 +181,18 @@ array-sep = ws %x2C ws ; , Comma ws-newline = *( wschar / newline ) ws-newlines = newline *( wschar / newline ) +;; Table + +table = std-table / array-table + +;; Standard Table + +std-table = std-table-open key *( table-key-sep key ) std-table-close + +std-table-open = %x5B ws ; [ Left square bracket +std-table-close = ws %x5D ; ] Right square bracket +table-key-sep = ws %x2E ws ; . Period + ;; Inline Table inline-table = inline-table-open inline-table-keyvals inline-table-close @@ -212,6 +205,13 @@ inline-table-keyvals = [ inline-table-keyvals-non-empty ] inline-table-keyvals-non-empty = ( key keyval-sep val inline-table-sep inline-table-keyvals-non-empty ) / ( key keyval-sep val ) +;; Array Table + +array-table = array-table-open key *( table-key-sep key ) array-table-close + +array-table-open = %x5B.5B ws ; [[ Double left square bracket +array-table-close = ws %x5D.5D ; ]] Double right quare bracket + ;; Built-in ABNF terms, reproduced here for clarity ALPHA = %x41-5A / %x61-7A ; A-Z / a-z From 10707ac7aff80dc9c49657130e49286b6afd5869 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:08:45 +0530 Subject: [PATCH 03/13] abnf: cleanup initial definitions Use the incremental alternatives syntax --- toml.abnf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/toml.abnf b/toml.abnf index 92083f15..29d5a7fc 100644 --- a/toml.abnf +++ b/toml.abnf @@ -16,27 +16,27 @@ toml = expression *( newline expression ) -expression = ( ( ws comment ) / - ( ws keyval ws [ comment ] ) / - ( ws table ws [ comment ] ) / - ws ) +expression = ws [ comment ] +expression =/ ws keyval ws [ comment ] +expression =/ ws table ws [ comment ] ;; Whitespace ws = *wschar - -wschar = ( %x20 / ; Space - %x09 ) ; Horizontal tab +wschar = %x20 ; Space +wschar =/ %x09 ; Horizontal tab ;; Newline -newline = ( %x0A / ; LF - %x0D.0A ) ; CRLF +newline = %x0A ; LF +newline =/ %x0D.0A ; CRLF ;; Comment comment-start-symbol = %x23 ; # -non-eol = %x09 / %x20-10FFFF +non-eol = %x09 +non-eol =/ %x20-10FFFF + comment = comment-start-symbol *non-eol ;; Key-Value pairs From 33ca3da94d6a09ddd8f2a075a9ef19902b3ea4f6 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:41:16 +0530 Subject: [PATCH 04/13] abnf: restructure definition of string escapes --- toml.abnf | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/toml.abnf b/toml.abnf index 29d5a7fc..263b293b 100644 --- a/toml.abnf +++ b/toml.abnf @@ -63,18 +63,19 @@ quotation-mark = %x22 ; " basic-char = basic-unescaped / escaped basic-unescaped = %x20-21 / %x23-5B / %x5D-10FFFF -escaped = escape ( %x22 / ; " quotation mark U+0022 - %x5C / ; \ reverse solidus U+005C - %x2F / ; / solidus U+002F - %x62 / ; b backspace U+0008 - %x66 / ; f form feed U+000C - %x6E / ; n line feed U+000A - %x72 / ; r carriage return U+000D - %x74 / ; t tab U+0009 - %x75 4HEXDIG / ; uXXXX U+XXXX - %x55 8HEXDIG ) ; UXXXXXXXX U+XXXXXXXX - -escape = %x5C ; \ +escaped = escape escape-seq-char + +escape = %x5C ; \ +escape-seq-char = escape %x22 ; " quotation mark U+0022 +escape-seq-char =/ escape %x5C ; \ reverse solidus U+005C +escape-seq-char =/ escape %x2F ; / solidus U+002F +escape-seq-char =/ escape %x62 ; b backspace U+0008 +escape-seq-char =/ escape %x66 ; f form feed U+000C +escape-seq-char =/ escape %x6E ; n line feed U+000A +escape-seq-char =/ escape %x72 ; r carriage return U+000D +escape-seq-char =/ escape %x74 ; t tab U+0009 +escape-seq-char =/ escape %x75 4HEXDIG ; uXXXX U+XXXX +escape-seq-char =/ escape %x55 8HEXDIG ; UXXXXXXXX U+XXXXXXXX ;; Multiline Basic String From 25019279450141a048fb38d6c904bc4475ee1996 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:42:15 +0530 Subject: [PATCH 05/13] abnf: U+007F is an escape character --- toml.abnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml.abnf b/toml.abnf index 263b293b..36787d8f 100644 --- a/toml.abnf +++ b/toml.abnf @@ -62,7 +62,7 @@ basic-string = quotation-mark *basic-char quotation-mark quotation-mark = %x22 ; " basic-char = basic-unescaped / escaped -basic-unescaped = %x20-21 / %x23-5B / %x5D-10FFFF +basic-unescaped = %x20-21 / %x23-5B / %x5D-7E / %x80-10FFFF escaped = escape escape-seq-char escape = %x5C ; \ From d9e5bdb07d2fce4002547b03eff0ef34c0164b47 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:35:58 +0530 Subject: [PATCH 06/13] readme: U+007F is an escape character --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 941ceba1..eb2b9582 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ multi-line literal. All strings must contain only valid UTF-8 characters. **Basic strings** are surrounded by quotation marks. Any Unicode character may be used except those that must be escaped: quotation mark, backslash, and the -control characters (U+0000 to U+001F). +control characters (U+0000 to U+001F, U+007F). ```toml str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF." From 81141f559f760bb1ced7afe79f086948bd250709 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:12:19 +0530 Subject: [PATCH 07/13] abnf: quoted keys can be any basic string This was inconsistent with the specification text. Changed to match text --- toml.abnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml.abnf b/toml.abnf index 36787d8f..65bb2d79 100644 --- a/toml.abnf +++ b/toml.abnf @@ -45,7 +45,7 @@ keyval = key keyval-sep val key = unquoted-key / quoted-key unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _ -quoted-key = quotation-mark 1*basic-char quotation-mark ; See Basic Strings +quoted-key = basic-string keyval-sep = ws %x3D ws ; = From 237b20ec93241f00cdd48b9eee047e0098faa117 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:13:27 +0530 Subject: [PATCH 08/13] abnf: use optionals syntax in inline table defn --- toml.abnf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/toml.abnf b/toml.abnf index 65bb2d79..2d1323b9 100644 --- a/toml.abnf +++ b/toml.abnf @@ -203,8 +203,7 @@ inline-table-close = ws %x7D ; } inline-table-sep = ws %x2C ws ; , Comma inline-table-keyvals = [ inline-table-keyvals-non-empty ] -inline-table-keyvals-non-empty = ( key keyval-sep val inline-table-sep inline-table-keyvals-non-empty ) / - ( key keyval-sep val ) +inline-table-keyvals-non-empty = key keyval-sep val [ inline-table-sep inline-table-keyvals-non-empty ] ;; Array Table From e4e9527edf0204be812989529b6bfb23abbccffb Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:24:40 +0530 Subject: [PATCH 09/13] abnf: use a literal string RFC 5234 specifies that string literals are case insensitive. --- toml.abnf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/toml.abnf b/toml.abnf index 2d1323b9..0782f9c9 100644 --- a/toml.abnf +++ b/toml.abnf @@ -123,8 +123,7 @@ frac = decimal-point zero-prefixable-int decimal-point = %x2E ; . zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT ) -exp = e integer -e = %x65 / %x45 ; e E +exp = "e" integer ;; Boolean From ef44ff432dde6283c01cc30a97517a5a46bd1f96 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:29:42 +0530 Subject: [PATCH 10/13] abnf: update the broken link --- toml.abnf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toml.abnf b/toml.abnf index 0782f9c9..3a9b7316 100644 --- a/toml.abnf +++ b/toml.abnf @@ -4,8 +4,8 @@ ;; This is an attempt to define TOML in ABNF according to the grammar defined ;; in RFC 5234 (http://www.ietf.org/rfc/rfc5234.txt). -;; You can try out this grammar interactively via the online ABNF tool at -;; http://www.coasttocoastresearch.com/interactiveapg +;; You can try out this grammar using https://www.npmjs.com/package/apg-html + ;; Note that due to the limitations of ABNF parsers, in order for multi-line ;; strings to work in that tool, the following rules must be ammended to ;; disallow the use of unescaped double- or single-quotes: From 8b358a558071fcc4bd1a6bdb80c2225fb2b5a337 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:37:07 +0530 Subject: [PATCH 11/13] readme: specify bare keys are ASCII --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index eb2b9582..fe3bbd79 100644 --- a/README.md +++ b/README.md @@ -118,12 +118,12 @@ on the same line (though some values can be broken over multiple lines). key = "value" ``` -Keys may be either bare or quoted. **Bare keys** may only contain letters, -numbers, underscores, and dashes (`A-Za-z0-9_-`). Note that bare keys are -allowed to be composed of only digits, e.g. `1234`, but are always interpreted -as strings. **Quoted keys** follow the exact same rules as either basic strings -or literal strings and allow you to use a much broader set of key names. Best -practice is to use bare keys except when absolutely necessary. +Keys may be either bare or quoted. **Bare keys** may only contain ASCII letters, +ASCII digits, underscores, and dashes (`A-Za-z0-9_-`). Note that bare keys are +allowed to be composed of only ASCII digits, e.g. `1234`, but are always +interpreted as strings. **Quoted keys** follow the exact same rules as either +basic strings or literal strings and allow you to use a much broader set of key +names. Best practice is to use bare keys except when absolutely necessary. ```toml key = "value" From 73cb5471993a6b49a0764cc08db28e067abc32ca Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 14 Nov 2017 19:37:55 +0530 Subject: [PATCH 12/13] readme: underscores are between digits --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fe3bbd79..7c098f8e 100644 --- a/README.md +++ b/README.md @@ -287,8 +287,8 @@ int3 = 0 int4 = -17 ``` -For large numbers, you may use underscores to enhance readability. Each -underscore must be surrounded by at least one digit. +For large numbers, you may use underscores between digits to enhance +readability. Each underscore must be surrounded by at least one digit. ```toml int5 = 1_000 From c961e6c7fd9969d718f4c58b624fa56426b74a7c Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Fri, 17 Nov 2017 18:29:45 +0530 Subject: [PATCH 13/13] abnf: quoted keys can be literal strings --- toml.abnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml.abnf b/toml.abnf index 3a9b7316..0f9360ca 100644 --- a/toml.abnf +++ b/toml.abnf @@ -45,7 +45,7 @@ keyval = key keyval-sep val key = unquoted-key / quoted-key unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _ -quoted-key = basic-string +quoted-key = basic-string / literal-string keyval-sep = ws %x3D ws ; =