diff --git a/.gitignore b/.gitignore index d741dbbc2..cb19a30b0 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ build/* **/*.o **/*.so +tex/generic/pgf/pgf.revision.tex diff --git a/doc/generic/pgf/lib/examplescasfinder.lua b/doc/generic/pgf/lib/examplescasfinder.lua index 39f1b2939..ad1832020 100644 --- a/doc/generic/pgf/lib/examplescasfinder.lua +++ b/doc/generic/pgf/lib/examplescasfinder.lua @@ -25,7 +25,7 @@ local C, P, V, Ct, Cf, Cg = lpeg.C, lpeg.P, lpeg.V, lpeg.Ct, lpeg.Cf, lpeg.Cg -- end -- ) -local tostring = UNIT_TESTING and require "ml".tstring or nil +-- local tostring = UNIT_TESTING and require "ml".tstring or nil local finder = {} @@ -74,18 +74,8 @@ finder.grammar = exentry = str * P(",") ^ -1 } -local function preamble(options) - local p = SP * P "preamble" * SP * "=" * SP * C(P(1) ^ 1) - local matches = p:match(u.get_string(options)) - local table = {} - if matches then - table.preamble = matches - end - return table -end - function finder.get_options(e) - return e.options and preamble(e.options) or {} + return e.options and u.preamble(e.options) or {} end function finder.get_content(e) @@ -184,10 +174,11 @@ local test_case4 = do local matches = finder.grammar:match(test_case4) assert(#matches == 2) - assert( - u.strip(u.get_string(matches[1].options)) == - [[preamble={\usetikzlibrary{graphs,graphdrawing} \usegdlibrary{force}}]] - ) + local expected_options = [[preamble={\usetikzlibrary{graphs,graphdrawing} \usegdlibrary{force}}]] + assert(u.strip(u.get_string(matches[1].options)) == expected_options) + local t = u.preamble(expected_options) + assert(t.preamble == [[\usetikzlibrary{graphs,graphdrawing} \usegdlibrary{force}]]) + assert( u.strip(u.get_string(matches[1].code)) == [[\tikz \graph [spring electrical layout, horizontal=0 to 1] diff --git a/doc/generic/pgf/lib/examplesfinder.lua b/doc/generic/pgf/lib/examplesfinder.lua index c36f095b7..1916246a7 100644 --- a/doc/generic/pgf/lib/examplesfinder.lua +++ b/doc/generic/pgf/lib/examplesfinder.lua @@ -81,18 +81,8 @@ finder.grammar = codekv = Cg(C("code") * SP * "=" * str) } -local function preamble(options) - local p = SP * P "preamble" * SP * "=" * SP * C(P(1) ^ 1) - local matches = p:match(u.get_string(options)) - local table = {} - if matches then - table.preamble = matches - end - return table -end - function finder.get_options(e) - return e.options and preamble(e.options) or {} + return e.options and u.preamble(e.options) or {} end function finder.get_content(e) diff --git a/doc/generic/pgf/lib/examplewithoptionfinder.lua b/doc/generic/pgf/lib/examplewithoptionfinder.lua index 87068ae9c..c9ca11c28 100644 --- a/doc/generic/pgf/lib/examplewithoptionfinder.lua +++ b/doc/generic/pgf/lib/examplewithoptionfinder.lua @@ -64,7 +64,7 @@ local function preamble(options) local matches = p:match(options) local table = {} if matches then - table.preamble = matches + table.preamble = u.strip_braces(matches) end return table end @@ -135,7 +135,7 @@ example { do local matches = finder.grammar:match(test_case2) - print("#matches:", #matches) + assert(#matches == 2) assert(u.strip(finder.get_options(matches[1]).preamble) == [[first example preamble]]) assert(u.strip(finder.get_content(matches[1])) == [[first example code]]) assert(not finder.get_options(matches[2]).preamble) diff --git a/doc/generic/pgf/lib/utils.lua b/doc/generic/pgf/lib/utils.lua index 0ce0b80c2..7d8898e32 100644 --- a/doc/generic/pgf/lib/utils.lua +++ b/doc/generic/pgf/lib/utils.lua @@ -207,4 +207,14 @@ function u.walk(sourcedir, targetdir, finder) end end +function u.preamble(options) + local p = u.SP * lpeg.P "preamble" * u.SP * "=" * u.SP * lpeg.C(lpeg.P(1) ^ 1) + local matches = p:match(u.get_string(options)) + local table = {} + if matches then + table.preamble = u.strip_braces(matches) + end + return table +end + return utils