summaryrefslogtreecommitdiff
path: root/src/luaotfload-parsers.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2016-02-19 21:57:24 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2016-02-19 21:57:29 +0100
commit9e04cce348b4de350b2e0612698c81311e6e6e9d (patch)
tree2b945670113f0c9fa620e40d3633f45f091c6bc7 /src/luaotfload-parsers.lua
parent128b005cd8b44483ce2a58bd0cf078318663c696 (diff)
downloadluaotfload-9e04cce348b4de350b2e0612698c81311e6e6e9d.tar.gz
[parsers] rework combo syntax
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)"
Diffstat (limited to 'src/luaotfload-parsers.lua')
-rw-r--r--src/luaotfload-parsers.lua44
1 files changed, 27 insertions, 17 deletions
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)