From 8d40fbb4fb8d57890cbf02013aa2344b9894c9f2 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 27 Mar 2013 00:24:28 +0100 Subject: cleanup; rewrite directives; update manual --- mod/tex/context/third/rst/rst_parser.lua | 71 ++++++++++++++++---------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'mod/tex/context/third/rst/rst_parser.lua') diff --git a/mod/tex/context/third/rst/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua index 6e7c225..a397f55 100644 --- a/mod/tex/context/third/rst/rst_parser.lua +++ b/mod/tex/context/third/rst/rst_parser.lua @@ -4,8 +4,8 @@ -- USAGE: refer to doc/documentation.rst -- DESCRIPTION: https://bitbucket.org/phg/context-rst/overview -- AUTHOR: Philipp Gesang (Phg), --- VERSION: 0.5 --- CHANGED: 2012-06-05 22:17:18+0200 +-- VERSION: 0.6 +-- CHANGED: 2013-03-26 22:45:59+0100 -------------------------------------------------------------------------------- -- @@ -30,6 +30,7 @@ rst.crlf = true helpers.rst_debug = false local iowrite = io.write +local ioopen = io.open local stringformat = string.format local stringlen = string.len local stringstrip = string.strip @@ -184,19 +185,19 @@ local parser = P{ directive = V"explicit_markup_start" * C(((V"escaped_colon" + (1 - V"colon" - V"eol")) - - V"substitution_text")^1) + - V"substitution_text")^1) --> directive name * V"double_colon" - * (V"directive_block_multi" + V"directive_block_single") + * Ct(V"directive_block_multi" + V"directive_block_single") --> content / rst.directive , - directive_block_multi = C((1 - V"eol")^0) -- name + directive_block_multi = Cg((1 - V"eol")^0, "name") -- name * V"eol" - * V"blank_line"^-1 -- how many empty lines are permitted? + * V"blank_line"^0 -- how many empty lines are permitted? * V"directive_indented_lines" , - directive_block_single = C((1 - V"eol")^1) * V"eol", + directive_block_single = Ct(C((1 - V"eol")^1)) * V"eol", -------------------------------------------------------------------------------- -- Substitution definition block @@ -217,18 +218,18 @@ local parser = P{ * V"bar" , - data_directive_block = V"data_directive_block_long" - + V"data_directive_block_short" + data_directive_block = V"data_directive_block_multi" + + V"data_directive_block_single" , - data_directive_block_short = C((1 - V"eol")^0) * V"eol", + data_directive_block_single = Ct(C((1 - V"eol")^0)) * V"eol", - data_directive_block_long = C((1 - V"eol")^0) * V"eol" - * V"directive_indented_lines" - , + data_directive_block_multi = Cg((1 - V"eol")^0, "first") * V"eol" + * V"directive_indented_lines" + , - directive_indented_lines = V"directive_indented_first" - * V"directive_indented_other"^0 - * (V"blank_line"^1 * V"directive_indented_other"^1)^1 + directive_indented_lines = Ct(V"directive_indented_first" + * V"directive_indented_other"^0) + * (V"blank_line"^1 * Ct(V"directive_indented_other"^1))^0 , @@ -241,7 +242,11 @@ local parser = P{ , directive_indented_other = Cmt(V"space"^1, function(s,i,indent) - warn("sub-m", #state.currentindent <= #indent, #indent, #state.currentindent, i) + warn("sub-m", + #state.currentindent <= #indent, + #indent, + #state.currentindent, + i) return #state.currentindent <= #indent end) * C((1 - V"eol")^1) * V"eol" @@ -1384,7 +1389,7 @@ function file_helpers.crlf (raw) end local function load_file (name) - f = assert(io.open(name, "r"), "Not a file!") + f = assert(ioopen(name, "r"), "Not a file!") if not f then return 1 end local tmp = f:read("*all") f:close() @@ -1403,7 +1408,7 @@ local function load_file (name) end local function save_file (name, data) - f = assert(io.open(name, "w"), "Could not open file "..name.." for writing! Check its permissions") + f = assert(ioopen(name, "w"), "Could not open file "..name.." for writing! Check its permissions") if not f then return 1 end f:write(data) f:close() @@ -1411,17 +1416,15 @@ local function save_file (name, data) end local function get_setups (inline) - local optional_setups = optional_setups -- might expect lots of calls + local optional_setups = optional_setups local setups = "" if not inline then setups = setups .. [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%{ Setups }% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%+-------------------------------------------------------------+% +%| Setups |% +%+-------------------------------------------------------------+% % General % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% ]] end @@ -1450,11 +1453,9 @@ local function get_setups (inline) setups = setups .. [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%{ Main }% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%+-------------------------------------------------------------+% +%| Main |% +%+-------------------------------------------------------------+% \starttext ]] @@ -1473,11 +1474,9 @@ function thirddata.rst.standalone (infile, outfile) \stoptext -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%{ End of Document }% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%+-------------------------------------------------------------+% +%| End of Document |% +%+-------------------------------------------------------------+% % vim:ft=context:tw=65:shiftwidth=2:tabstop=2:set expandtab ]] -- cgit v1.2.3