From 1cc2bd29d90b5f8e60e3e51976666999dfbeabfa Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 4 Sep 2010 01:07:17 +0200 Subject: generic field lists --- rst_parser.lua | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'rst_parser.lua') diff --git a/rst_parser.lua b/rst_parser.lua index a88a263..5b6a1e9 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -15,7 +15,7 @@ require "lpeg" rst = require "rst_context" ---local rst_debug = true +local rst_debug = true local warn = function(str, ...) if not rst_debug then return false end @@ -49,7 +49,7 @@ tracklists.bullets = {} -- mapping bullet forms to depth tracklists.bullets.max = 0 tracklists.lastbullet = "" tracklists.roman_cache = {} -- storing roman numerals that were already converted -tracklists.currentindent = "" -- used in definition lists +tracklists.currentindent = "" -- used in definition lists and elsewhere --n = 0 @@ -207,7 +207,53 @@ local parser = P{ --+ V"definition_list", list = V"definition_list" - + V"bullet_list", + + V"bullet_list" + + V"field_list", + +-------------------------------------------------------------------------------- +-- Field lists (for bibliographies etc.) +-------------------------------------------------------------------------------- + + field_list = Cs(V"field"^1) + * V"blank_line"^1 + / rst.field_list, + + field = Ct(V"field_marker" + * V"whitespace" + * V"field_body") + / rst.field, + + field_marker = V"colon" + * C(V"field_name") + * V"colon", + + field_name = (V"escaped_colon" + (1 - V"colon"))^1, + + field_body = C(V"rest_of_line" * V"eol" + * V"indented_lines"^-1), + + indented_lines = V"indented_first" + * (V"indented_other" + - V"field_marker")^0, + + indented_first = Cmt(V"space"^1, function (s, i, indent) + warn("idt-f", indent, i) + if not indent or + indent == "" then + return false + end + tracklists.currentindent = indent + return true + end) + * V"rest_of_line" + * V"eol", + + indented_other = Cmt(V"space"^1, function (s, i, indent) + warn("idt-m", indent, tracklists.currentindent, indent == tracklists.currentindent, i) + return indent == tracklists.currentindent + end) + * V"rest_of_line" + * V"eol", -------------------------------------------------------------------------------- -- Definition lists @@ -611,6 +657,7 @@ local parser = P{ spacing = V"whitespace"^1, blank_line = V"space"^0 * V"eol", + rest_of_line = (1 - V"eol")^1, eol = P"\n", eof = V"eol"^0 * -P(1), @@ -631,7 +678,7 @@ local parser = P{ enclosed_close = S[['")]}>]], } -f = io.open("deflist.rst", "r") +f = io.open("fieldlist.rst", "r") testdata = f:read("*all") f:close() -- cgit v1.2.3