From f1786af10f0be9675f83a335581593d45d56836c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 15 Sep 2010 18:06:33 +0200 Subject: multi-line substitution definitions --- rst_context.lua | 3 ++- rst_parser.lua | 55 +++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/rst_context.lua b/rst_context.lua index f9eab29..b85ef2c 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -967,10 +967,11 @@ function rst_context.footnote (label, content) end function rst_context.substitution_definition (subtext, directive, data) + data = table.concat(data, "\n") print(subtext,directive,data) local rs = rst_context.substitutions rs[subtext] = { directive = directive, data = data } - return "\n% substitution definition block\n" + return "" end optional_setups = {} diff --git a/rst_parser.lua b/rst_parser.lua index 1ef0aa0..88c894d 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -143,14 +143,40 @@ local parser = P{ * V"whitespace" * C((1 - V"colon" - V"space" - V"eol")^1) -- directive * V"double_colon" - * C(V"data_directive_block") - * V"blank_line"^-1 + * Ct(V"data_directive_block") + --* V"blank_line"^-1 / rst.substitution_definition , - data_directive_block = V"rest_of_line" * V"eol" - * V"indented_lines"^-1 -- nothing said about definitions - , -- spanning multiple paragraphs + data_directive_block = V"data_directive_block_long" + + V"data_directive_block_short" + , + data_directive_block_short = C((1 - V"eol")^0) * V"eol", + + data_directive_block_long = C((1 - V"eol")^0) * V"eol" + * V"directive_indented_lines" + , + + directive_indented_lines = V"directive_indented_first" + * V"directive_indented_other"^0 + , + + + directive_indented_first = Cmt(V"space"^1, function(s,i,indent) + warn("sub-i", #indent, i) + state.currentindent = indent + return true + end) + * C((1 - V"eol")^1) * V"eol" + , + + directive_indented_other = Cmt(V"space"^1, function(s,i,indent) + warn("sub-m", #state.currentindent <= #indent, #indent, #state.currentindent, i) + return #state.currentindent <= #indent + end) + * C((1 - V"eol")^1) * V"eol" + , + -------------------------------------------------------------------------------- -- Explicit markup footnote block @@ -611,10 +637,11 @@ local parser = P{ -- Lists -------------------------------------------------------------------------------- - list = V"option_list" - + V"bullet_list" - + V"definition_list" - + V"field_list" + list = (V"option_list" + + V"bullet_list" + + V"definition_list" + + V"field_list") + - V"explicit_markup_start" , -------------------------------------------------------------------------------- @@ -1024,10 +1051,10 @@ local parser = P{ indented_first = Cmt(V"space"^1, function (s, i, indent) warn("idt-f", indent, i) - if not indent or - indent == "" then - return false - end + --if not indent or + --indent == "" then + --return false + --end state.currentindent = indent return true end) @@ -1035,7 +1062,7 @@ local parser = P{ * V"eol", indented_other = Cmt(V"space"^1, function (s, i, indent) - warn("idt-m", indent, state.currentindent, indent == state.currentindent, i) + warn("idt-m", #indent, #state.currentindent, #indent == #state.currentindent, i) return indent == state.currentindent end) * (1 - V"eol")^1 -- cgit v1.2.3