diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/third/rst/rst_context.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/third/rst/rst_context.lua | 138 |
1 files changed, 72 insertions, 66 deletions
diff --git a/Master/texmf-dist/tex/context/third/rst/rst_context.lua b/Master/texmf-dist/tex/context/third/rst/rst_context.lua index 6a5aa05daaf..e7637b3bf52 100644 --- a/Master/texmf-dist/tex/context/third/rst/rst_context.lua +++ b/Master/texmf-dist/tex/context/third/rst/rst_context.lua @@ -3,16 +3,16 @@ -- FILE: rst_context.lua -- USAGE: called by rst_parser.lua -- DESCRIPTION: Complement to the reStructuredText parser --- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com> --- CHANGED: 2011-08-28 13:46:46+0200 +-- AUTHOR: Philipp Gesang (Phg), <phg42.2a@gmail.com> +-- CHANGED: 2012-06-05 22:18:11+0200 -------------------------------------------------------------------------------- -- --- 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 @@ -40,10 +42,10 @@ do } function string.strip(str) return stripper:match(str) or "" - end + 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. </rant> 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" @@ -368,7 +370,7 @@ do skip2 = P"\\type" * V"balanced", skip3 = P"\\mathematics" * V"balanced", skip = V"skip1" + V"skip2" + V"skip3", - --literal = Cs(P"\\" / "") * 1 + --literal = Cs(P"\\" / "") * 1 } function rst_context.escape (str) @@ -393,13 +395,13 @@ local corresponding = { local inline_parser = P{ [1] = "block", - block = Cs(V"inline_as_first"^-1 * (V"except" + V"inline_element" + 1)^0), + block = Cs(V"inline_as_first"^-1 * (V"except" + V"inline_element" + V"normal_char")^0), inline_element = V"precede_inline" - * Cs(V"inline_do_elements") - * #V"succede_inline" - + V"footnote_reference" - , + * Cs(V"inline_do_elements") + * #V"succede_inline" + + V"footnote_reference" + , -- Ugly but needed in case the first element of a paragraph is inline -- formatted. @@ -410,15 +412,15 @@ local inline_parser = P{ , inline_do_elements = V"strong_emphasis" - + V"substitution_reference" - + V"anon_reference" - + V"inline_literal" - + V"reference" - + V"emphasis" - + V"interpreted_text" - + V"inline_internal_target" - + V"link_standalone" - , + + V"substitution_reference" + + V"anon_reference" + + V"inline_literal" + + V"reference" + + V"emphasis" + + V"interpreted_text" + + V"inline_internal_target" + + V"link_standalone" + , precede_inline = V"spacing" + V"eol" @@ -489,15 +491,19 @@ local inline_parser = P{ lparenthesis = P"(", rparenthesis = P")", - lsquare = P"[", - rsquare = P"]", - lbrace = P"{", - rbrace = P"}", + lsquare = P"[" / [[{\\letterleftbracket}]], + rsquare = P"]" / [[{\\letterrightbracket}]], + lbrace = P"{" / [[{\\letterleftbrace}]], + rbrace = P"}" / [[{\\letterrightbrace}]], less = P"<", greater = P">", leftpar = V"lparenthesis" + V"lsquare" + V"lbrace" + V"less", rightpar = V"rparenthesis" + V"rsquare" + V"rbrace" + V"greater", + normal_char = V"lbrace" + V"rbrace" + V"lsquare" + V"rsquare" -- escape those if in input + + 1 + , + --groupchars = S"()[]{}", groupchars = V"leftpar" + V"rightpar", apostrophe = P"’" + P"'", @@ -512,47 +518,47 @@ local inline_parser = P{ letter = R"az" + R"AZ", punctuation = V"apostrophe" - + V"colon" - + V"comma" + + V"colon" + + V"comma" + V"dashes" - + V"dot" + + V"dot" + V"ellipsis" + V"exclamationmark" + V"guillemets" + V"hyphen" + V"interpunct" + V"interrobang" - + V"questionmark" + + V"questionmark" + V"quotationmarks" - + V"semicolon" + + V"semicolon" + V"slash" + V"solidus" + V"underscore" , - emphasis = (V"asterisk" - V"double_asterisk") - * Cs((1 - V"spacing" - V"eol" - V"asterisk") - * ((1 - (1 * V"asterisk"))^0 - * (1 - V"spacing" - V"eol" - V"asterisk"))^-1) - * V"asterisk" + emphasis = (V"asterisk" - V"double_asterisk") + * Cs((V"normal_char" - V"spacing" - V"eol" - V"asterisk") + * ((V"normal_char" - (V"normal_char" * V"asterisk"))^0 + * (V"normal_char" - V"spacing" - V"eol" - V"asterisk"))^-1) + * V"asterisk" / rst_context.emphasis, - strong_emphasis = V"double_asterisk" - * Cs((1 - V"spacing" - V"eol" - V"asterisk") - * ((1 - (1 * V"double_asterisk"))^0 - * (1 - V"spacing" - V"eol" - V"asterisk"))^-1) - * V"double_asterisk" + strong_emphasis = V"double_asterisk" + * Cs((V"normal_char" - V"spacing" - V"eol" - V"asterisk") + * ((V"normal_char" - (V"normal_char" * V"double_asterisk"))^0 + * (V"normal_char" - V"spacing" - V"eol" - V"asterisk"))^-1) + * V"double_asterisk" / rst_context.strong_emphasis, inline_literal = V"double_bareia" * C ((V"escaped_bareia" - V"spacing" - V"eol" - V"bareia") - * ((V"escaped_bareia" - (1 * V"double_bareia"))^0 + * ((V"escaped_bareia" - (V"normal_char" * V"double_bareia"))^0 * (V"escaped_bareia" - V"spacing" - V"eol" - V"bareia"))^-1) * V"double_bareia" / rst_context.literal, - interpreted_single_char = (1 - V"spacing" - V"eol" - V"bareia") * #V"bareia", - interpreted_multi_char = (1 - V"spacing" - V"eol" - V"bareia") * (1 - (1 * V"bareia"))^0 * (1 - V"spacing" - V"eol" - V"bareia"), + interpreted_single_char = (V"normal_char" - V"spacing" - V"eol" - V"bareia") * #V"bareia", + interpreted_multi_char = (V"normal_char" - V"spacing" - V"eol" - V"bareia") * (V"normal_char" - (1 * V"bareia"))^0 * (1 - V"spacing" - V"eol" - V"bareia"), interpreted_text = C(V"role_marker"^-1) * (V"bareia" - V"double_bareia") @@ -586,9 +592,9 @@ local inline_parser = P{ * V"bareia" * V"underscore" , - footnote_reference = V"lsquare" - * Cs(V"footnote_label" + V"citation_reference_label") - * V"rsquare" + footnote_reference = V"lsquare" + * Cs(V"footnote_label" + V"citation_reference_label") + * V"rsquare" * V"underscore" / rst_context.footnote_reference , @@ -638,7 +644,7 @@ function rst_context.paragraph (data) else str = data end - return fmt([[ + return stringformat([[ \\startparagraph %s @@ -688,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 @@ -811,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 @@ -894,7 +900,7 @@ end function rst_context.field (tab) local name, body = tab[1], tab[2] - return fmt([[ + return stringformat([[ \\RSTfieldname{%s} \\RSTfieldbody{%s} @@ -906,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 @@ -934,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 @@ -1160,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 @@ -1199,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 |