From 97aa5f28b096e2439d87a617c17eae52171e80d6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 4 Sep 2010 13:43:48 +0200 Subject: option lists --- rst_context.lua | 25 ++++++++++++++++ rst_parser.lua | 90 ++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 95 insertions(+), 20 deletions(-) diff --git a/rst_context.lua b/rst_context.lua index ff3851d..57725ed 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -366,4 +366,29 @@ function rst_context.block_comment (str) ]], str) end +function rst_context.option_list (str) + return [[ +\\setupTABLE[c][first] [background=color, backgroundcolor=grey, style=\tt] +\\setupTABLE[c][each] [frame=off] +\\setupTABLE[r][each] [frame=off] +\\bTABLE[split=repeat,option=stretch] +\\bTABLEhead +\\bTR + \\bTH Option \\eTH + \\bTH Description \\eTH +\\eTR +\\eTABLEhead +\\bTABLEbody +]] .. str .. [[ + +\\eTABLEbody +\\eTABLE +]] +end + +function rst_context.option_item (tab) + return string.format([[\\bTR\\bTC %s \\eTC\\bTC %s \\eTC\\eTR +]], tab[1], tab[2]) +end + return rst_context diff --git a/rst_parser.lua b/rst_parser.lua index 6466b81..7b739bd 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -204,12 +204,59 @@ local parser = P{ -- Lists -------------------------------------------------------------------------------- - --list = V"bullet_list" - --+ V"definition_list", - - list = V"definition_list" + list = V"option_list" + + V"definition_list" + V"bullet_list" - + V"field_list", + + V"field_list" + , + +-------------------------------------------------------------------------------- +-- Option lists +-------------------------------------------------------------------------------- + + option_list = Cs((V"option_list_item" + * V"blank_line"^-1)^1) + /rst.option_list, + + option_list_item = Ct(C(V"option_group") + * C(V"option_description")) + / rst.option_item, + + option_description = V"option_desc_next" + + V"option_desc_more" + + V"option_desc_single", + + option_desc_single = V"space"^2 + * V"rest_of_line" + * V"eol", + + option_desc_more = V"space"^2 + * V"rest_of_line" + * V"eol" + * V"indented_lines" + * (V"blank_line" * V"indented_lines")^0, + + option_desc_next = V"eol" + * V"indented_lines", + + option_group = V"option" + * (V"comma" * V"space" * V"option")^0, + + option = (V"option_posixlong" + + V"option_posixshort" + + V"option_dos_vms") + * V"option_arg"^-1, + + option_arg = (V"equals" + V"space") * V"letter"^1, + + option_posixshort = V"dash" * (V"letter" + V"digit"), + + option_posixlong = V"double_dash" + * V"letter" + * (V"letter" + V"digit" + V"dash")^1, + + option_dos_vms = V"slash" + * V"letter"^1, -------------------------------------------------------------------------------- -- Field lists (for bibliographies etc.) @@ -452,7 +499,7 @@ local parser = P{ * V"bareia") * V"colon", - target_name = V"doubledot" + target_name = V"double_dot" * V"space" * V"underscore" * (V"tname_bareia" + V"tname_normal"), @@ -469,7 +516,7 @@ local parser = P{ * (V"target_indentmatch" * C(1 - V"whitespace" - V"eol")^1)^0) * V"eol" * #(1 - V"whitespace" - "eol")) / rst.joinindented - + C((1 - V"eol")^1) * V"eol" * #(V"doubledot" + V"eol") + + C((1 - V"eol")^1) * V"eol" * #(V"double_dot" + V"eol") + (1 - V"endpar")^0 * Cc("make me constant!"), target = Ct((V"target_name" * (V"space"^0 * V"eol" * V"target_name")^0) @@ -477,7 +524,7 @@ local parser = P{ * V"target_link") / rst.target, - anonymous_prefix = (V"doubledot" * V"space" * V"double_underscore" * V"colon") + anonymous_prefix = (V"double_dot" * V"space" * V"double_underscore" * V"colon") + (V"double_underscore"), anonymous_target = V"anonymous_prefix" @@ -492,7 +539,7 @@ local parser = P{ -- Paragraphs * Inline Markup -------------------------------------------------------------------------------- - paragraph = -(V"doubledot" + V"double_underscore") -- + V"bullet_indent") + paragraph = -(V"double_dot" + V"double_underscore") -- + V"bullet_indent") * Cs((V"enclosed_inline" + V"inline_elements" + V"word" @@ -564,7 +611,7 @@ local parser = P{ * C(V"role_marker"^-1) / rst.interpreted_text, - role_marker = V"colon" * (V"letters" + V"dash" + V"underscore" + V"dot")^1 * V"colon", + role_marker = V"colon" * (V"letter" + V"dash" + V"underscore" + V"dot")^1 * V"colon", link_standalone = C(V"uri") / rst.link_standalone, @@ -580,13 +627,13 @@ local parser = P{ comment = V"block_comment" + V"line_comment", - block_comment = V"doubledot" * V"whitespace"^0 * V"eol" + block_comment = V"double_dot" * V"whitespace"^0 * V"eol" * Cs(V"indented_lines") * V"eol"^0 --* V"blank_line"^0 / rst.block_comment, - line_comment = V"doubledot" * V"whitespace"^0 + line_comment = V"double_dot" * V"whitespace"^0 * Cs((1 - V"eol")^0 * V"eol") / rst.line_comment, @@ -652,7 +699,7 @@ local parser = P{ colon = P":", escaped_colon = V"backslash" * V"colon", dot = P".", - doubledot = V"dot" * V"dot", + double_dot = V"dot" * V"dot", semicolon = P";", questionmark = P"?", exclamationmark = P"!", @@ -662,7 +709,10 @@ local parser = P{ underscore = P"_", double_underscore = V"underscore" * V"underscore", dash = P"-", - letters = R"az" + R"AZ", + double_dash = V"dash" * V"dash", + letter = R"az" + R"AZ", + + equals = P"=", space = P" ", spaces = V"space"^1, @@ -676,11 +726,11 @@ local parser = P{ eof = V"eol"^0 * -P(1), endpar = V"eol" * (V"blank_line"^1 + V"eof"), - delimiters = P"‐" + P"‑" + P"‒" + P"–" + P"—" + V"space", - - adornment_char = S[[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]] + P[[\\]], - - bullet_char = S"*+-" + P"•" + P"‣" + P"⁃", + -- diverse markup character sets + delimiters = P"‐" + P"‑" + P"‒" + P"–" + P"—" + V"space", -- inline markup + adornment_char = S[[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]] + P[[\\]], -- headings + bullet_char = S"*+-" + P"•" + P"‣" + P"⁃", -- bullet lists + argument_char = V"double_dash" * V"dash" * V"slash", -- option lists digit = R"09", roman_numeral = S"ivxlcdm"^1, @@ -691,7 +741,7 @@ local parser = P{ enclosed_close = S[['")]}>]], } -f = io.open("fieldlist.rst", "r") +f = io.open("option_lists.rst", "r") testdata = f:read("*all") f:close() -- cgit v1.2.3