From 9e04cce348b4de350b2e0612698c81311e6e6e9d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 19 Feb 2016 21:57:24 +0100 Subject: [parsers] rework combo syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use arrows to emphasise what’s mapped. Allow whitespace to visually separate items. Also allow optional grouping with parentheses. Now it’s possible to define a combination as follows: \font \f = "combo: 1 -> 42; 2 -> 1337, U+0042-U+0084; 3 -> (55, 0x54 * 0x45 * 0x58)" --- src/luaotfload-parsers.lua | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'src/luaotfload-parsers.lua') diff --git a/src/luaotfload-parsers.lua b/src/luaotfload-parsers.lua index 0f87256..71e539d 100644 --- a/src/luaotfload-parsers.lua +++ b/src/luaotfload-parsers.lua @@ -565,19 +565,21 @@ local modifier_list = Cg(Ct(modifier^0), "modifiers") --- combining --------------------------------------------------------- --- ---- \font \three = combo:1/42,2/99/0xdeadbeef,3/1/U+2a-U+1337*42 ---- v +~ v +~ +~~~~~~~~~ v v +~~~ +~~~~~ +~ ---- | | | | | | | | | | ---- | | | | | | | | | | ---- idx : --+-÷--+-÷--÷----------+ | +----+ | ---- | | | | | | ---- id : ----+----+--÷------------+ +-----------+ ---- | | ---- chars : ------------+--------------+ +--- \font \three = combo: 1->42; 2->99,0xdeadbeef; 3->(1,U+2a-U+1337*42) +--- v +~ v +~ +~~~~~~~~~ v v +~~~ +~~~~~ +~ +--- | | | | | | | | | | +--- | | | | | | | | | | +--- idx : ---+--÷---+--÷--÷-----------+ | +----+ | +--- | | | | | | +--- id : ------+------+--÷---------------+ +-----------+ +--- | | +--- chars : ----------------+-----------------+ --- -local comborowsep = ws * comma * ws -local combocolsep = ws * slash * ws -local comborangesep = ws * asterisk * ws +local comborowsep = ws * semicolon * ws +local combomapsep = ws * P"->" * ws +local combodefsep = ws * comma * ws +local comborangesep = ws * asterisk * ws + local combohex = hex / tonumber local combouint = digit^1 / tonumber local tonumber16 = function (s) return tonumber (s, 16) end @@ -585,12 +587,20 @@ local combouni = P"U+" * (digit^1 / tonumber16) local combonum = combohex + combouni + combouint local comborange = Ct(combonum * dash * combonum) + combonum local combochars = comborange * (comborangesep * comborange)^0 -local combodef1 = Ct( Cg(combouint, "idx") --> no chars - * combocolsep * Cg(combouint, "id" )) -local combodef = Ct( Cg(combouint, "idx" ) - * combocolsep * Cg(combouint, "id" ) - * combocolsep * Cg(Ct(combochars^1), "chars")) +local parenthesized = function (p) return P"(" * ws * p * ws * P")" end + +local comboidxpat = Cg(combouint, "idx") +local comboidpat = Cg(combouint, "id" ) +local combocharspat = comboidpat * combodefsep * Cg(Ct(combochars^1), "chars") + +local comboidx = parenthesized (comboidxpat ) + comboidxpat +local comboid = parenthesized (comboidpat ) + comboidpat +local comboidchars = parenthesized (combocharspat) + combocharspat + +local combodef1 = Ct(comboidx * combomapsep * comboid) --> no chars +local combodef = Ct(comboidx * combomapsep * comboidchars) local combolist = Ct(combodef1 * (comborowsep * combodef)^1) + --- lookups ----------------------------------------------------------- local fontname = C((1-S":(/")^1) --- like luatex-fonts local unsupported = Cmt((1-S":(")^1, check_garbage) -- cgit v1.2.3