From 948a8de35dfd7af2908f7f579d68eee2836a3930 Mon Sep 17 00:00:00 2001 From: torkleyy Date: Wed, 17 Jan 2018 17:36:44 +0100 Subject: [PATCH 1/2] Add grammar specification --- docs/extensions.md | 3 ++ docs/grammar.md | 118 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 docs/extensions.md create mode 100644 docs/grammar.md diff --git a/docs/extensions.md b/docs/extensions.md new file mode 100644 index 00000000..6e8a55ac --- /dev/null +++ b/docs/extensions.md @@ -0,0 +1,3 @@ +## RON extensions + +TODO diff --git a/docs/grammar.md b/docs/grammar.md new file mode 100644 index 00000000..016950c9 --- /dev/null +++ b/docs/grammar.md @@ -0,0 +1,118 @@ +# RON grammar + +This file describes the structure of a RON file in [EBNF notation][ebnf]. +If extensions are enabled, some rules will be replaced. For that, see the +[extensions document][exts] which describes all extensions and what they override. + +[ebnf]: https://en.wikipedia.org/wiki/Extended_Backus–Naur_form +[exts]: ./extensions.md + +## RON file + +```ebnf +RON = [extensions], ws, value, ws +``` + +## Whitespace and comments + +```ebnf +ws = { ws_single, comment } +ws_single = "\n" | "\t" | "\r" | " " +comment = ["//", { no_newline }, "\n"] +``` + +## Commas + +```ebnf +comma = ws, ",", ws +``` + +## Extensions + +```ebnf +extensions = { "#", ws, "!", ws, "[", ws, extensions_inner, ws, "]", ws } +extensions_inner = "enable", ws, "(", extension_name, { comma, extension_name }, [comma], ws, ")" +``` + +For the extension names see the [`extensions.md`][exts] document. + +## Value + +```ebnf +value = unsigned | signed | float | string | char | bool | option | list | map | tuple | struct | enum_variant +``` + +## Numbers + +```ebnf +digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" +unsigned = digit, { digit } +signed = ["+" | "-"], unsigned +float = float_std | float_frac +float_std = ["+" | "-"], digit, { digit }, ".", {digit}, [float_exp] +float_frac = ".", digit, {digit}, [float_exp] +float_exp = ("e" | "E"), digit, {digit} +``` + +## String + +```ebnf +string = "\"", { no_double_quotation_marks | string_escape }, "\"" +string_escape = "\\", ("\"" | "\\" | "b" | "f" | "n" | "r" | "t" | ("u", unicode_hex)) +``` + +## Char + +```ebnf +char = "'", (no_apostrophe | "\\\\" | "\\'"), "'" +``` + +## Boolean + +```ebnf +bool = "true" | "false" +``` + +## Optional + +```ebnf +option = "Some", ws, "(", ws, value, ws, ")" +``` + +## List + +```ebnf +list = "[", [value, { comma, value }, [comma]], "]" +``` + +## Map + +```ebnf +map = "{", [map_entry, { comma, map_entry }, [comma]], "}" +map_entry = value, ws, ":", ws, value +``` + +## Tuple + +```ebnf +tuple = "(", [value, { comma, value }, [comma]], ")" +``` + +## Struct + +```ebnf +struct = unit_struct | tuple_struct | named_struct +unit_struct = ident | "()" +tuple_struct = [ident], ws, tuple +named_struct = [ident], ws, "(", [named_field, { comma, named_field }, [comma]], ")" +named_field = ident, ws, ":", value +``` + +## Enum + +```ebnf +enum_variant = enum_variant_unit | enum_variant_tuple | enum_variant_named +enum_variant_unit = ident +enum_variant_tuple = ident, ws, tuple +enum_variant_named = ident, ws, "(", [named_field, { comma, named_field }, [comma]], ")" +``` From 0cc75148e27c5659d8f2ece7f8a6ab0a9442186f Mon Sep 17 00:00:00 2001 From: torkleyy Date: Wed, 17 Jan 2018 19:32:54 +0100 Subject: [PATCH 2/2] Add semicolons --- docs/grammar.md | 66 ++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/grammar.md b/docs/grammar.md index 016950c9..8ebe51bb 100644 --- a/docs/grammar.md +++ b/docs/grammar.md @@ -10,28 +10,28 @@ If extensions are enabled, some rules will be replaced. For that, see the ## RON file ```ebnf -RON = [extensions], ws, value, ws +RON = [extensions], ws, value, ws; ``` ## Whitespace and comments ```ebnf -ws = { ws_single, comment } -ws_single = "\n" | "\t" | "\r" | " " -comment = ["//", { no_newline }, "\n"] +ws = { ws_single, comment }; +ws_single = "\n" | "\t" | "\r" | " "; +comment = ["//", { no_newline }, "\n"]; ``` ## Commas ```ebnf -comma = ws, ",", ws +comma = ws, ",", ws; ``` ## Extensions ```ebnf -extensions = { "#", ws, "!", ws, "[", ws, extensions_inner, ws, "]", ws } -extensions_inner = "enable", ws, "(", extension_name, { comma, extension_name }, [comma], ws, ")" +extensions = { "#", ws, "!", ws, "[", ws, extensions_inner, ws, "]", ws }; +extensions_inner = "enable", ws, "(", extension_name, { comma, extension_name }, [comma], ws, ")"; ``` For the extension names see the [`extensions.md`][exts] document. @@ -39,80 +39,80 @@ For the extension names see the [`extensions.md`][exts] document. ## Value ```ebnf -value = unsigned | signed | float | string | char | bool | option | list | map | tuple | struct | enum_variant +value = unsigned | signed | float | string | char | bool | option | list | map | tuple | struct | enum_variant; ``` ## Numbers ```ebnf -digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" -unsigned = digit, { digit } -signed = ["+" | "-"], unsigned -float = float_std | float_frac -float_std = ["+" | "-"], digit, { digit }, ".", {digit}, [float_exp] -float_frac = ".", digit, {digit}, [float_exp] -float_exp = ("e" | "E"), digit, {digit} +digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; +unsigned = digit, { digit }; +signed = ["+" | "-"], unsigned; +float = float_std | float_frac; +float_std = ["+" | "-"], digit, { digit }, ".", {digit}, [float_exp]; +float_frac = ".", digit, {digit}, [float_exp]; +float_exp = ("e" | "E"), digit, {digit}; ``` ## String ```ebnf -string = "\"", { no_double_quotation_marks | string_escape }, "\"" -string_escape = "\\", ("\"" | "\\" | "b" | "f" | "n" | "r" | "t" | ("u", unicode_hex)) +string = "\"", { no_double_quotation_marks | string_escape }, "\""; +string_escape = "\\", ("\"" | "\\" | "b" | "f" | "n" | "r" | "t" | ("u", unicode_hex)); ``` ## Char ```ebnf -char = "'", (no_apostrophe | "\\\\" | "\\'"), "'" +char = "'", (no_apostrophe | "\\\\" | "\\'"), "'"; ``` ## Boolean ```ebnf -bool = "true" | "false" +bool = "true" | "false"; ``` ## Optional ```ebnf -option = "Some", ws, "(", ws, value, ws, ")" +option = "Some", ws, "(", ws, value, ws, ")"; ``` ## List ```ebnf -list = "[", [value, { comma, value }, [comma]], "]" +list = "[", [value, { comma, value }, [comma]], "]"; ``` ## Map ```ebnf -map = "{", [map_entry, { comma, map_entry }, [comma]], "}" -map_entry = value, ws, ":", ws, value +map = "{", [map_entry, { comma, map_entry }, [comma]], "}"; +map_entry = value, ws, ":", ws, value; ``` ## Tuple ```ebnf -tuple = "(", [value, { comma, value }, [comma]], ")" +tuple = "(", [value, { comma, value }, [comma]], ")"; ``` ## Struct ```ebnf -struct = unit_struct | tuple_struct | named_struct -unit_struct = ident | "()" -tuple_struct = [ident], ws, tuple -named_struct = [ident], ws, "(", [named_field, { comma, named_field }, [comma]], ")" -named_field = ident, ws, ":", value +struct = unit_struct | tuple_struct | named_struct; +unit_struct = ident | "()"; +tuple_struct = [ident], ws, tuple; +named_struct = [ident], ws, "(", [named_field, { comma, named_field }, [comma]], ")"; +named_field = ident, ws, ":", value; ``` ## Enum ```ebnf -enum_variant = enum_variant_unit | enum_variant_tuple | enum_variant_named -enum_variant_unit = ident -enum_variant_tuple = ident, ws, tuple -enum_variant_named = ident, ws, "(", [named_field, { comma, named_field }, [comma]], ")" +enum_variant = enum_variant_unit | enum_variant_tuple | enum_variant_named; +enum_variant_unit = ident; +enum_variant_tuple = ident, ws, tuple; +enum_variant_named = ident, ws, "(", [named_field, { comma, named_field }, [comma]], ")"; ```