Skip to content

Commit

Permalink
tidy up - move SP to utils.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
hansonchar committed Jun 18, 2024
1 parent ede57a2 commit 5f1b1b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 6 additions & 7 deletions doc/generic/pgf/lib/examplewithoptionfinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ if UNIT_TESTING then
end

local lpeg = require("lpeg")
local loc = lpeg.locale()
local u = require("utils")
local SP = u.SP
local str = require("stringmatcher")
local C, Ct, P, V = lpeg.C, lpeg.Ct, lpeg.P, lpeg.V
local C, P, V, Ct, Cf, Cg = lpeg.C, lpeg.P, lpeg.V, lpeg.Ct, lpeg.Cf, lpeg.Cg

local t = {}
local SP = loc.space ^ 0


-- Grammar to extract code from function call to "example" with a table parameter
t.grammar =
Expand All @@ -29,12 +29,12 @@ t.grammar =
example = V "example_begin" * V "content" * V "example_end",
example_begin = P "\n" ^ -1 * "example({" * SP,
example_end = "\n})" * SP,
content = Ct(lpeg.Cf(Ct "" * V "options" ^ -1 * V "code", u.set)),
content = Ct(Cf(Ct "" * V "options" ^ -1 * V "code", u.set)),
anything = (1 - V "example") ^ 0,
options = SP * (V "optionskv") ^ -1 * (P ",") ^ -1,
optionskv = lpeg.Cg(C("options") * SP * "=" * str),
optionskv = Cg(C("options") * SP * "=" * str),
code = SP * V "codekv",
codekv = lpeg.Cg(C("code") * SP * "=" * str)
codekv = Cg(C("code") * SP * "=" * str)
}

local function preamble(options)
Expand Down Expand Up @@ -97,7 +97,6 @@ example({
]]
)
)
os.exit()
end

return t
8 changes: 7 additions & 1 deletion doc/generic/pgf/lib/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ function u.strip_braces(str)
return str:match "^{?(.-)}?$"
end

local loc = lpeg.locale()

-- optional whitespace
u.ws = lpeg.S " \t\n\r" ^ 0
u.SP = loc.space ^ 0

-- for backward compatibility
-- u.ws = lpeg.S " \t\n\r" ^ 0
u.ws = u.SP

-- match string literal
function u.lit(str)
Expand Down

0 comments on commit 5f1b1b4

Please sign in to comment.