From bd98935ced1b94ff40cfa8335fdaabf92645676b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 4 Sep 2010 16:00:08 +0200 Subject: quoted literal blocks --- rst_context.lua | 2 +- rst_parser.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/rst_context.lua b/rst_context.lua index f595a27..ee943ab 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -393,7 +393,7 @@ end function rst_context.literal_block (str) local indent = P" "^1 - local stripme = indent:match(str) + local stripme = indent:match(str) or 0 local strip = P{ [1] = "strip", diff --git a/rst_parser.lua b/rst_parser.lua index 99265bd..2aa4e38 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -203,19 +203,33 @@ local parser = P{ -------------------------------------------------------------------------------- -- Literal blocks +-------------------------------------------------------------------------------- + + literal_block = V"unquoted_literal_block" + + V"quoted_literal_block", + +-------------------------------------------------------------------------------- +-- Quoted literal blocks -------------------------------------------------------------------------------- literal_block = V"literal_block_marker" - * Cs(V"literal_block_lines" - * (V"blank_line"^1 * V"literal_block_lines")^0) - * V"blank_line"^0 - / rst.literal_block, + * Cs(V"literal_block_lines" + * (V"blank_line"^1 * V"literal_block_lines")^0) + * V"blank_line"^0 + / rst.literal_block, literal_block_marker = V"double_colon" * V"eol" * V"blank_line", - literal_block_lines = V"literal_block_first" - * (V"literal_block_other" - - V"blank_line")^0, + literal_block_lines = V"unquoted_literal_block_lines" + + V"quoted_literal_block_lines", + + unquoted_literal_block_lines = V"literal_block_first" + * (V"literal_block_other" + - V"blank_line")^0, + + quoted_literal_block_lines = V"quoted_literal_block_first" + * (V"quoted_literal_block_other" + - V"blank_line")^0, literal_block_first = Cmt(V"space"^1, function (s, i, indent) warn("lbk-f", #indent, "", "", i) @@ -240,6 +254,29 @@ local parser = P{ * V"rest_of_line" * V"eol", + quoted_literal_block_first = Cmt(V"adornment_char", function (s, i, indent) + warn("lbk-f", #indent, "", "", i) + if not indent or + indent == "" then + return false + end + tracklists.currentindent = indent + return true + end) + * V"rest_of_line" + * V"eol", + + quoted_literal_block_other = Cmt(V"adornment_char", function (s, i, indent) + warn("lbk-m", + #indent, + #tracklists.currentindent, + #indent >= #tracklists.currentindent, + i) + return #indent >= #tracklists.currentindent + end) + * V"rest_of_line" + * V"eol", + -------------------------------------------------------------------------------- -- Lists -------------------------------------------------------------------------------- -- cgit v1.2.3