From 9b1389520701dbce2bebf451f0e5d719264928ea Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 5 Jun 2012 22:13:43 +0200 Subject: coding style --- mod/tex/context/third/rst/rst_context.lua | 48 +++++++++++++++------------- mod/tex/context/third/rst/rst_directives.lua | 28 ++++++++-------- mod/tex/context/third/rst/rst_helpers.lua | 36 +++++++++++---------- mod/tex/context/third/rst/rst_parser.lua | 30 +++++++++-------- 4 files changed, 74 insertions(+), 68 deletions(-) (limited to 'mod') diff --git a/mod/tex/context/third/rst/rst_context.lua b/mod/tex/context/third/rst/rst_context.lua index 823bd9b..3faa66a 100644 --- a/mod/tex/context/third/rst/rst_context.lua +++ b/mod/tex/context/third/rst/rst_context.lua @@ -8,11 +8,11 @@ -------------------------------------------------------------------------------- -- --- TODO --- - Find an appropriate way to handle generic tables irrespective of the grid --- settings. The problem is: --- http://archive.contextgarden.net/message/20100912.112605.8a1aaf13.en.html --- Seems we'll have to choose either the grid or split tables as default. Not --- good. +--- Find an appropriate way to handle generic tables irrespective of the grid +--- settings. The problem is: +--- http://archive.contextgarden.net/message/20100912.112605.8a1aaf13.en.html +--- Seems we'll have to choose either the grid or split tables as default. Not +--- good. local helpers = helpers or thirddata and thirddata.rst_helpers @@ -26,8 +26,10 @@ local iowrite = io.write local dbg_write = helpers.dbg_writef -local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct, P, R, S, V, match = - lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match +local C, Cb, Cc, Cg, Cmt, Cp, + Cs, Ct, P, R, S, V, match + = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, + lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match -- This one should ignore escaped spaces. do @@ -42,8 +44,8 @@ do return stripper:match(str) or "" end end -local stringstrip = string.strip -local fmt = string.format +local stringstrip = string.strip +local stringformat = string.format local err = function(str) if str then @@ -106,8 +108,8 @@ do end end --- So we can use crefs[n][2] to refer to the place where the reference was --- created. +--- So we can use crefs[n][2] to refer to the place where the reference was +--- created. local function get_context_reference (str) local crefs = rst_context.context_references local srefs = rst_context.structure_references @@ -164,9 +166,9 @@ rst_context.roles.color = function(color, str) local definition = color:match("^color_(.+)$") if definition:match("^rgb_") then -- assume rgb local rgb = p.rgbvalues:match(definition) - definition = fmt([[r=%s,g=%s,b=%s]], rgb[1], rgb[2], rgb[3]) + definition = stringformat([[r=%s,g=%s,b=%s]], rgb[1], rgb[2], rgb[3]) end - return fmt([[\\colored[%s]{%s}]], definition, str) + return stringformat([[\\colored[%s]{%s}]], definition, str) end -------------------------------------------------------------------------------- @@ -195,7 +197,7 @@ end -- wrong if you can! Or go tell those digital publishers and their willing -- subordinates, the authors, who think they can save a few pennys, -- substituting the typesetter and editor by some fancy software. Keep in mind --- that zapf.tex is not just random dummy text. Now, where was I? +-- that zapf.tex is not just random dummy text. function rst_context.roles.ctsh(str) -- shorthand rst_context.addsetups("citator") @@ -283,7 +285,7 @@ function rst_context.anon_reference (str) str = str:match("^`?([^`]+)`?__$") rst_context.anonymous_links[#rst_context.anonymous_links+1] = str link = "__target_anon_" .. #rst_context.anonymous_links - return fmt([[\\RSTchoosegoto{%s}{%s}]], link, str) + return stringformat([[\\RSTchoosegoto{%s}{%s}]], link, str) end local whitespace = S" \n\t\v" @@ -642,7 +644,7 @@ function rst_context.paragraph (data) else str = data end - return fmt([[ + return stringformat([[ \\startparagraph %s @@ -692,7 +694,7 @@ function rst_context.section (...) -- TODO general cleanup; move validity ref = get_context_reference (str) - str = fmt("\n\\\\%s[%s]{%s}\n", sectionlevels[level], ref, str) + str = stringformat("\n\\\\%s[%s]{%s}\n", sectionlevels[level], ref, str) else return [[{\\bf fix your sectioning!}\\endgraf}]] end @@ -815,7 +817,7 @@ function rst_context.bullet_item (tab) -- just leave it alone elseif helpers.list.greater(itemtype, li[current_itemdepth]) then local itemnum = tonumber(stringstrip(itemtype)) or helpers.list.get_decimal(itemtype) - result = result .. fmt([[ + result = result .. stringformat([[ \\setnumber[itemgroup:itemize]{%s} ]], itemnum) end @@ -898,7 +900,7 @@ end function rst_context.field (tab) local name, body = tab[1], tab[2] - return fmt([[ + return stringformat([[ \\RSTfieldname{%s} \\RSTfieldbody{%s} @@ -910,7 +912,7 @@ function rst_context.line_comment (str) end function rst_context.block_comment (str) - return fmt([[ + return stringformat([[ \iffalse %% start block comment %s\fi %% stop block comment @@ -938,7 +940,7 @@ function rst_context.option_list (str) end function rst_context.option_item (tab) - return fmt([[\\bTR\\bTC %s \\eTC\\bTC %s \\eTC\\eTR + return stringformat([[\\bTR\\bTC %s \\eTC\\bTC %s \\eTC\\eTR ]], tab[1], tab[2]) end @@ -1164,7 +1166,7 @@ function rst_context.simple_table(tab) dbg_write("%7s | ", cell.content) local celltext = inline_parser:match(cell.content) if cell.span then - head = head .. fmt([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, celltext or "") + head = head .. stringformat([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, celltext or "") else head = head .. [[\\bTH ]] .. celltext .. [[\\eTH]] end @@ -1203,7 +1205,7 @@ function rst_context.simple_table(tab) dbg_write("%7s | ", cell.content) local celltext = inline_parser:match(cell.content) if cell.span then - body = body .. fmt([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, celltext or "") + body = body .. stringformat([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, celltext or "") else body = body .. [[\\bTC ]] .. celltext .. [[\\eTC]] end diff --git a/mod/tex/context/third/rst/rst_directives.lua b/mod/tex/context/third/rst/rst_directives.lua index 8ee0582..4491ebb 100644 --- a/mod/tex/context/third/rst/rst_directives.lua +++ b/mod/tex/context/third/rst/rst_directives.lua @@ -18,8 +18,8 @@ local rst_directives = { } thirddata.rst_directives = rst_directives local rst_context = thirddata.rst -local stringstrip = string.strip -local fmt = string.format +local stringstrip = string.strip +local stringformat = string.format rst_directives.anonymous = 0 rst_directives.images = {} @@ -108,19 +108,19 @@ rst_directives.image = function(name, data) local images_done = rd.images.done if not anon then if not images_done[name] then - img = img .. fmt([[ + img = img .. stringformat([[ \useexternalfigure[%s][%s][] ]], name, data) images_done[name] = true end - img = img .. fmt([[ + img = img .. stringformat([[ \def\RSTsubstitution%s{%% \placefigure[here]{%s}{\externalfigure[%s]%s} } ]], name, rst_context.escape(inline_parser:match(properties.caption)), name, properties.setup) else -- image won't be referenced but used instantly - img = img .. fmt([[ + img = img .. stringformat([[ \placefigure[here]{%s}{\externalfigure[%s]%s} ]], rst_context.escape(inline_parser:match(properties.caption)), data, properties.setup) @@ -145,7 +145,7 @@ rst_directives.caution = function(raw) end end text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text))) - return fmt([[ + return stringformat([[ \startRSTcaution %s \stopRSTcaution @@ -169,7 +169,7 @@ rst_directives.danger = function(raw) end end text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text))) - return fmt([[ + return stringformat([[ \startRSTdanger %s \stopRSTdanger @@ -182,7 +182,7 @@ rst_directives.DANGER = function(addendum) for _,str in ipairs(addendum) do result = result .. (stringstrip(str)) end - return fmt([[ + return stringformat([[ %% The Rabbit of Caerbannog \startlinecorrection @@ -213,12 +213,12 @@ rst_directives.DANGER = function(addendum) end rst_directives.mp = function(name, data) - local mpcode = fmt([[ + local mpcode = stringformat([[ \startreusableMPgraphic{%s} %s \stopreusableMPgraphic ]], name, data) - mpcode = mpcode .. fmt([[ + mpcode = mpcode .. stringformat([[ \def\RSTsubstitution%s{%% \reuseMPgraphic{%s}%% } @@ -230,7 +230,7 @@ end --- implementation. --- http://archive.contextgarden.net/message/20111108.175913.1d994624.en.html rst_directives.ctx = function(name, data) - local ctx = fmt([[ + local ctx = stringformat([[ \startbuffer[%s]%% %s\stopbuffer @@ -242,7 +242,7 @@ rst_directives.ctx = function(name, data) end rst_directives.lua = function(name, data) - local luacode = fmt([[ + local luacode = stringformat([[ \startbuffer[%s]%% \startluacode @@ -273,7 +273,7 @@ rst_directives.math = function (name, data) i = i + 1 end end - return fmt([[ + return stringformat([[ \startformula %s \stopformula @@ -285,7 +285,7 @@ end -------------------------------------------------------------------------------- rst_directives.replace = function(name, data) - return fmt([[ + return stringformat([[ \def\RSTsubstitution%s{%s} ]], name, data) diff --git a/mod/tex/context/third/rst/rst_helpers.lua b/mod/tex/context/third/rst/rst_helpers.lua index 9f388c1..d2d7221 100644 --- a/mod/tex/context/third/rst/rst_helpers.lua +++ b/mod/tex/context/third/rst/rst_helpers.lua @@ -11,8 +11,10 @@ local P, R, S, V, match = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match -local C, Carg, Cb, Cc, Cg, Cmt, Cp, Cs, Ct - = lpeg.C, lpeg.Carg, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct +local C, Carg, Cb, Cc, Cg, + Cmt, Cp, Cs, Ct + = lpeg.C, lpeg.Carg, lpeg.Cb, lpeg.Cc, lpeg.Cg, + lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct local helpers helpers = thirddata.rst_helpers @@ -22,12 +24,12 @@ helpers.cell = {} local utf = unicode.utf8 local utflen = utf.len -local stringstrip = string.strip -local fmt = string.format +local stringstrip = string.strip +local stringformat = string.format function helpers.dbg_writef(...) if helpers.rst_debug then - io.write(fmt(...)) + io.write(stringformat(...)) end end @@ -69,14 +71,14 @@ do [1] = "cells", cells = p.celldelim * (C(V"in_cell") - * (V"matchwidth" * C(V"in_cell")) ^1), + * (V"matchwidth" * C(V"in_cell"))^1), in_cell = p.cellcontent^1 + (p.dash - p.cellcontent)^1, matchwidth = Cmt(C(p.celldelim) * Carg(1), function(s,i,del, layout) local pos = 1 - local lw = layout.widths + local lw = layout.widths for n=1, #lw do pos = pos + lw[n] + 1 if (i - 1) == pos then return true end @@ -166,14 +168,14 @@ end function helpers.table.create(raw) local newtab = {} - newtab.rows = {} + newtab.rows = {} newtab.layout = set_layout(raw[1]) local p = helpers.patterns newtab.resolve_parent = function(row, col, array) local array = array or newtab.rows - local cell = array[row][col] + local cell = array[row][col] local par_row, par_col = row, col if cell.parent then par_row, par_col = newtab.resolve_parent(cell.parent.y, cell.parent.x) @@ -592,9 +594,9 @@ end helpers.string = {} do - -- This grammar inside the function is slightly faster than the same as an upvalue - -- with the value of “width” repeatedly given via lpeg.Carg(). This holds - -- for repeated calls as well. + --- This grammar inside the function is slightly faster than the + --- same as an upvalue with the value of “width” repeatedly given + --- via lpeg.Carg(). This holds for repeated calls as well. local ulen = utflen function helpers.string.wrapat (str, width) local width = width or 65 @@ -608,11 +610,11 @@ do typing = P[[\\type{]] * (1 - P"}")^0 * P"}", typingenv = P[[\\starttyping]] * (1 - P[[\\stoptyping]])^0 * P[[\\stoptyping]], ignore = V"typing" + V"typingenv", - -- the initial whitespace of the “other” pattern must not be - -- enforced (“^1”) as it will break the exceptions (“ignore” - -- pattern)! In general it is better to have the wrapper ignore some - -- valid breaks than to not have it matching some valid strings at - -- all. + --- the initial whitespace of the “other” pattern must not + --- be enforced (“^1”) as it will break the exceptions + --- (“ignore” pattern)! In general it is better to have the + --- wrapper ignore some valid breaks than to not have it + --- matching some valid strings at all. other = Cmt(V"whitespace"^0 * (V"ignore" + (1 - V"whitespace")^1), function(s,i,w) linelength = linelength + ulen(w) return true diff --git a/mod/tex/context/third/rst/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua index 1f3a257..0a94f05 100644 --- a/mod/tex/context/third/rst/rst_parser.lua +++ b/mod/tex/context/third/rst/rst_parser.lua @@ -23,18 +23,18 @@ local rst = thirddata.rst local helpers = thirddata.rst_helpers local optional_setups = thirddata.rst_setups -rst.strip_BOM = false -rst.expandtab = false +rst.strip_BOM = true +rst.expandtab = true rst.shiftwidth = 4 rst.crlf = true helpers.rst_debug = false -local iowrite = io.write -local fmt = string.format -local stringlen = string.len -local stringstrip = string.strip -local utf = unicode.utf8 -local utflen = utf.len +local iowrite = io.write +local stringformat = string.format +local stringlen = string.len +local stringstrip = string.strip +local utf = unicode.utf8 +local utflen = utf.len local warn do @@ -44,7 +44,7 @@ do ndebug = ndebug + 1 local slen = #str + 3 --str = "*["..str.."]" - str = fmt("*[%4d][%s]", ndebug, str) + str = stringformat("*[%4d][%s]", ndebug, str) for i,j in ipairs({...}) do if 80 - i * 8 - slen < 0 then local indent = "" @@ -53,15 +53,17 @@ do end str = str .. "\n" .. indent end - str = str .. fmt(" |%6s", stringstrip(tostring(j))) + str = str .. stringformat(" |%6s", stringstrip(tostring(j))) end iowrite(str .. " |\n") return 0 end end -local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct - = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct +local C, Cb, Cc, Cg, + Cmt, Cp, Cs, Ct + = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, + lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct local P, R, S, V, match = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match @@ -1510,7 +1512,7 @@ function thirddata.rst.do_rst_inclusion (iname, fname) local setups = get_setups(true) local incnr = #rst_incsetups + 1 - local tmp_file = tex.jobname .. fmt("–rst_inclusion-%d.tex.tmp", incnr) + local tmp_file = tex.jobname .. stringformat("–rst_inclusion-%d.tex.tmp", incnr) if processed then processed = strip_comments:match(processed) @@ -1532,7 +1534,7 @@ function thirddata.rst.get_rst_inclusion (iname) if rst_inclusions[iname] then context.input(rst_inclusions[iname]) else - context(fmt("{\\bf File for inclusion “%s” not found.}\par ", iname)) + context(stringformat("{\\bf File for inclusion “%s” not found.}\par ", iname)) end end -- cgit v1.2.3