diff options
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 32 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 32 | ||||
-rw-r--r-- | scripts/context/stubs/unix/mtxrun | 32 | ||||
-rw-r--r-- | tex/context/base/cont-new.mkii | 2 | ||||
-rw-r--r-- | tex/context/base/cont-new.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/context-version.pdf | bin | 4141 -> 4143 bytes | |||
-rw-r--r-- | tex/context/base/context-version.png | bin | 105897 -> 106246 bytes | |||
-rw-r--r-- | tex/context/base/context.mkii | 2 | ||||
-rw-r--r-- | tex/context/base/context.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/m-spreadsheet.lua | 102 | ||||
-rw-r--r-- | tex/context/base/m-spreadsheet.mkiv | 104 | ||||
-rw-r--r-- | tex/context/base/status-files.pdf | bin | 24412 -> 24396 bytes | |||
-rw-r--r-- | tex/context/base/status-lua.pdf | bin | 181114 -> 181146 bytes | |||
-rw-r--r-- | tex/context/base/util-prs.lua | 32 | ||||
-rw-r--r-- | tex/generic/context/luatex/luatex-fonts-merged.lua | 2 |
15 files changed, 263 insertions, 81 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 78cc06e0e..fe2b77139 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -4777,8 +4777,8 @@ if not modules then modules = { } end modules ['util-prs'] = { license = "see context related readme files" } -local P, R, V, C, Ct, Cs, Carg = lpeg.P, lpeg.R, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg -local lpegmatch = lpeg.match +local P, R, V, C, Ct, Cs, Carg, Cc = lpeg.P, lpeg.R, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc +local lpegmatch, patterns = lpeg.match, lpeg.patterns local concat, format, gmatch, find = table.concat, string.format, string.gmatch, string.find local tostring, type, next = tostring, type, next @@ -4794,7 +4794,7 @@ local sortedhash = table.sortedhash local escape, left, right = P("\\"), P('{'), P('}') -lpeg.patterns.balanced = P { +patterns.balanced = P { [1] = ((escape * (left+right)) + (1 - (left+right)) + V(2))^0, [2] = left * V(1) * right } @@ -4810,9 +4810,9 @@ local spaces = space^0 local argument = Cs((lbrace/"") * ((nobrace + nested)^0) * (rbrace/"")) local content = (1-P(-1))^0 -lpeg.patterns.nested = nested -- no capture -lpeg.patterns.argument = argument -- argument after e.g. = -lpeg.patterns.content = content -- rest after e.g = +patterns.nested = nested -- no capture +patterns.argument = argument -- argument after e.g. = +patterns.content = content -- rest after e.g = local value = P(lbrace * C((nobrace + nested)^0) * rbrace) + C((nested + (1-comma))^0) @@ -5005,6 +5005,26 @@ function parsers.listitem(str) return gmatch(str,"[^, ]+") end +-- +local digit = R("09") + +local pattern = Cs { "start", + start = V("one") + V("two") + V("three"), + rest = (Cc(",") * V("thousand"))^0 * (P(".") + P(-1)) * P(1)^0, + thousand = digit * digit * digit, + one = digit * V("rest"), + two = digit * digit * V("rest"), + three = V("thousand") * V("rest"), +} + +patterns.splitthousands = pattern -- maybe better in the parsers namespace ? + +function parsers.splitthousands(str) + return lpegmatch(pattern,str) or str +end + +-- print(parsers.splitthousands("11111111111.11")) + end -- of closure diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 78cc06e0e..fe2b77139 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -4777,8 +4777,8 @@ if not modules then modules = { } end modules ['util-prs'] = { license = "see context related readme files" } -local P, R, V, C, Ct, Cs, Carg = lpeg.P, lpeg.R, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg -local lpegmatch = lpeg.match +local P, R, V, C, Ct, Cs, Carg, Cc = lpeg.P, lpeg.R, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc +local lpegmatch, patterns = lpeg.match, lpeg.patterns local concat, format, gmatch, find = table.concat, string.format, string.gmatch, string.find local tostring, type, next = tostring, type, next @@ -4794,7 +4794,7 @@ local sortedhash = table.sortedhash local escape, left, right = P("\\"), P('{'), P('}') -lpeg.patterns.balanced = P { +patterns.balanced = P { [1] = ((escape * (left+right)) + (1 - (left+right)) + V(2))^0, [2] = left * V(1) * right } @@ -4810,9 +4810,9 @@ local spaces = space^0 local argument = Cs((lbrace/"") * ((nobrace + nested)^0) * (rbrace/"")) local content = (1-P(-1))^0 -lpeg.patterns.nested = nested -- no capture -lpeg.patterns.argument = argument -- argument after e.g. = -lpeg.patterns.content = content -- rest after e.g = +patterns.nested = nested -- no capture +patterns.argument = argument -- argument after e.g. = +patterns.content = content -- rest after e.g = local value = P(lbrace * C((nobrace + nested)^0) * rbrace) + C((nested + (1-comma))^0) @@ -5005,6 +5005,26 @@ function parsers.listitem(str) return gmatch(str,"[^, ]+") end +-- +local digit = R("09") + +local pattern = Cs { "start", + start = V("one") + V("two") + V("three"), + rest = (Cc(",") * V("thousand"))^0 * (P(".") + P(-1)) * P(1)^0, + thousand = digit * digit * digit, + one = digit * V("rest"), + two = digit * digit * V("rest"), + three = V("thousand") * V("rest"), +} + +patterns.splitthousands = pattern -- maybe better in the parsers namespace ? + +function parsers.splitthousands(str) + return lpegmatch(pattern,str) or str +end + +-- print(parsers.splitthousands("11111111111.11")) + end -- of closure diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 78cc06e0e..fe2b77139 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -4777,8 +4777,8 @@ if not modules then modules = { } end modules ['util-prs'] = { license = "see context related readme files" } -local P, R, V, C, Ct, Cs, Carg = lpeg.P, lpeg.R, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg -local lpegmatch = lpeg.match +local P, R, V, C, Ct, Cs, Carg, Cc = lpeg.P, lpeg.R, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc +local lpegmatch, patterns = lpeg.match, lpeg.patterns local concat, format, gmatch, find = table.concat, string.format, string.gmatch, string.find local tostring, type, next = tostring, type, next @@ -4794,7 +4794,7 @@ local sortedhash = table.sortedhash local escape, left, right = P("\\"), P('{'), P('}') -lpeg.patterns.balanced = P { +patterns.balanced = P { [1] = ((escape * (left+right)) + (1 - (left+right)) + V(2))^0, [2] = left * V(1) * right } @@ -4810,9 +4810,9 @@ local spaces = space^0 local argument = Cs((lbrace/"") * ((nobrace + nested)^0) * (rbrace/"")) local content = (1-P(-1))^0 -lpeg.patterns.nested = nested -- no capture -lpeg.patterns.argument = argument -- argument after e.g. = -lpeg.patterns.content = content -- rest after e.g = +patterns.nested = nested -- no capture +patterns.argument = argument -- argument after e.g. = +patterns.content = content -- rest after e.g = local value = P(lbrace * C((nobrace + nested)^0) * rbrace) + C((nested + (1-comma))^0) @@ -5005,6 +5005,26 @@ function parsers.listitem(str) return gmatch(str,"[^, ]+") end +-- +local digit = R("09") + +local pattern = Cs { "start", + start = V("one") + V("two") + V("three"), + rest = (Cc(",") * V("thousand"))^0 * (P(".") + P(-1)) * P(1)^0, + thousand = digit * digit * digit, + one = digit * V("rest"), + two = digit * digit * V("rest"), + three = V("thousand") * V("rest"), +} + +patterns.splitthousands = pattern -- maybe better in the parsers namespace ? + +function parsers.splitthousands(str) + return lpegmatch(pattern,str) or str +end + +-- print(parsers.splitthousands("11111111111.11")) + end -- of closure diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 2325d755c..c36615242 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.06.08 17:18} +\newcontextversion{2012.06.08 21:57} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 7b34e0d51..c275202ac 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.06.08 17:18} +\newcontextversion{2012.06.08 21:57} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex 4f00d0eb6..32721e9d0 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png Binary files differindex cf8687dc0..5f3c1e476 100644 --- a/tex/context/base/context-version.png +++ b/tex/context/base/context-version.png diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii index 53114d821..7470347f5 100644 --- a/tex/context/base/context.mkii +++ b/tex/context/base/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2012.06.08 17:18} +\edef\contextversion{2012.06.08 21:57} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 423b1a0f2..3aee4115a 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -23,7 +23,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2012.06.08 17:18} +\edef\contextversion{2012.06.08 21:57} %D For those who want to use this: diff --git a/tex/context/base/m-spreadsheet.lua b/tex/context/base/m-spreadsheet.lua index 7a74b594b..25bf6be87 100644 --- a/tex/context/base/m-spreadsheet.lua +++ b/tex/context/base/m-spreadsheet.lua @@ -6,8 +6,10 @@ if not modules then modules = { } end modules ['m-spreadsheet'] = { license = "see context related readme files" } -local byte, format, gsub, validstring = string.byte, string.format, string.gsub, string.valid -local R, P, C, Cs, Cc, Carg, lpegmatch = lpeg.R, lpeg.P, lpeg.C, lpeg.Cs, lpeg.Cc, lpeg.Carg, lpeg.match +local byte, format, gsub = string.byte, string.format, string.gsub +local R, P, C, V, Cs, Cc, Carg, lpegmatch = lpeg.R, lpeg.P, lpeg.C, lpeg.V, lpeg.Cs, lpeg.Cc, lpeg.Carg, lpeg.match + +local splitthousands = utilities.parsers.splitthousands local context = context @@ -21,38 +23,69 @@ local data = { } local settings = { - numberseparator = ".", + period = ".", + comma = ",", } spreadsheets.data = data spreadsheets.settings = settings -local stack, current = { }, "default" +local defaultname = "default" +local stack = { } +local current = defaultname -local mt ; mt = { +local d_mt ; d_mt = { __index = function(t,k) local v = { } - setmetatable(v,mt) + setmetatable(v,d_mt) + t[k] = v + return v + end, +} + +local s_mt ; s_mt = { + __index = function(t,k) + local v = settings[k] t[k] = v return v end, } +function spreadsheets.setup(t) + for k, v in next, t do + settings[k] = v + end +end + function spreadsheets.reset(name) - if not name or name == "" then name = "default" end + if not name or name == "" then name = defaultname end local d = { } - setmetatable(d,mt) - data[name] = d + local s = { } + setmetatable(d,d_mt) + setmetatable(s,s_mt) + data[name] = { + name = name, + data = d, + settings = s, + } end -function spreadsheets.start(name) - if not name or name == "" then name = "default" end +function spreadsheets.start(name,s) + if not name or name == "" then name = defaultname end table.insert(stack,current) current = name - if not data[current] then + if data[current] then + setmetatable(s,s_mt) + data[current].settings = s + else local d = { } - setmetatable(d,mt) - data[current] = d + setmetatable(d,d_mt) + setmetatable(s,s_mt) + data[current] = { + name = name, + data = d, + settings = s, + } end end @@ -65,7 +98,7 @@ spreadsheets.reset() local offset = byte("A") - 1 local function assign(s,n) - return format("moduledata.spreadsheets.data['%s'][%s]",n,byte(s)-offset) + return format("moduledata.spreadsheets.data['%s'].data[%s]",n,byte(s)-offset) end -------- datacell(name,a,b,...) @@ -108,54 +141,63 @@ end local template = [[ local spr = moduledata.spreadsheets.functions - local dat = moduledata.spreadsheets.data['%s'] + local dat = moduledata.spreadsheets.data['%s'].data local sum = spr.sum local fmt = spr.fmt %s ]] +-- to be considered: a weak cache + local function execute(name,r,c,str) - if name == "" then name = current if name == "" then name = "default" end end + -- if name == "" then name = current if name == "" then name = defaultname end end str = lpegmatch(pattern,str,1,name) str = format(template,name,str) - -- print(str) local result = loadstring(str) result = result and result() or 0 - data[name][c][r] = result + data[name].data[c][r] = result return result end function spreadsheets.set(name,r,c,str) - if name == "" then name = current if name == "" then name = "default" end end + if name == "" then name = current if name == "" then name = defaultname end end execute(name,r,c,str) end function spreadsheets.get(name,r,c,str) - if name == "" then name = current if name == "" then name = "default" end end + if name == "" then name = current if name == "" then name = defaultname end end + local dname = data[name] if not str or str == "" then - context(data[name][c][r] or 0) + context(dname.data[c][r] or 0) else local result = execute(name,r,c,str) if result then if type(result) == "number" then - data[name][c][r] = result + dname.data[c][r] = result + result = tostring(result) end - local numberseparator = validstring(settings.numberseparator,".") - if numberseparator ~= "." then - result = gsub(tostring(result),"%.",numberseparator) + local settings = dname.settings + local split = settings.split + local period = settings.period + local comma = settings.comma + if split then + result = splitthousands(result) end + if period == "" then period = nil end + if comma == "" then comma = nil end + result = gsub(result,".",{ ["."] = period, [","] = comma }) context(result) end end end function spreadsheets.doifelsecell(name,r,c) - if name == "" then name = current if name == "" then name = "default" end end + if name == "" then name = current if name == "" then name = defaultname end end local d = data[name] - commands.testcase(d and d[c][r]) + commands.testcase(d and d.data[c][r]) end function spreadsheets.show(name) - if name == "" then name = current if name == "" then name = "default" end end - table.print(data[name],name) + if name == "" then name = current if name == "" then name = defaultname end end + table.print(data[name].data,name) end diff --git a/tex/context/base/m-spreadsheet.mkiv b/tex/context/base/m-spreadsheet.mkiv index 45e14ef39..d5ea781fd 100644 --- a/tex/context/base/m-spreadsheet.mkiv +++ b/tex/context/base/m-spreadsheet.mkiv @@ -17,21 +17,76 @@ \unprotect +\ifdefined\c!comma \else \def\c!comma {comma} \fi +\ifdefined\c!period \else \def\c!period{period} \fi + % todo: get(...) set(..) ctx(...) -\unexpanded\def\resetspreadsheet {\dosingleempty\doresetspreadsheet} -\unexpanded\def\doresetspreadsheet [#1]{\ctxlua{moduledata.spreadsheets.reset("#1")}} -\unexpanded\def\startspreadsheet {\dosingleempty\dostartspreadsheet} -\unexpanded\def\dostartspreadsheet [#1]{\ctxlua{moduledata.spreadsheets.start("#1")}} -\unexpanded\def\stopspreadsheet {\ctxlua{moduledata.spreadsheets.stop()}} -\unexpanded\def\showspreadsheet {\dosingleempty\doshowspreadsheet} -\unexpanded\def\doshowspreadsheet [#1]{\ctxlua{moduledata.spreadsheets.show("#1")}} -\unexpanded\def\getspreadsheet {\dosingleempty\dogetspreadsheet} -\unexpanded\def\dosetspreadsheet [#1]#2#3#4{\ctxlua{moduledata.spreadsheets.set ("#1",\number#2,\number#3,"#4")}} -\unexpanded\def\setspreadsheet {\dosingleempty\dosetspreadsheet} -\unexpanded\def\dogetspreadsheet [#1]#2#3#4{\ctxlua{moduledata.spreadsheets.get ("#1",\number#2,\number#3,"#4")}} -\unexpanded\def\doifelsespreadsheetcell {\dosingleempty\dodoifelsespreadsheetcell} -\unexpanded\def\dodoifelsespreadsheetcell[#1]#2#3{\ctxlua{moduledata.spreadsheets.doifelsecell("#1","#2","#3")}} +\installcorenamespace{spreadsheet} + +\installcommandhandler \??spreadsheet {spreadsheet} \??spreadsheet + +\appendtoks + \ctxlua{moduledata.spreadsheets.setup{ % global ! + period = "\spreadsheetparameter\c!period", + comma = "\spreadsheetparameter\c!comma", + split = "\spreadsheetparameter\c!split", + }}% +\to \everysetupspreadsheet + +\setupspreadsheet + [%\c!comma=, + %\c!period=, + \c!split=\v!no] + +\unexpanded\def\resetspreadsheet + {\dosingleempty\doresetspreadsheet} + +\unexpanded\def\doresetspreadsheet[#1]% + {\ctxlua{moduledata.spreadsheets.reset("#1")}} + +\unexpanded\def\startspreadsheet + {\dosingleempty\dostartspreadsheet} + +\unexpanded\def\dostartspreadsheet[#1]% + {\pushmacro\currentspreadsheet + \edef\currentspreadsheet{#1}% + \checkspreadsheetparent + \edef\m_spreadsheet_period{\spreadsheetparameter\c!period}% + \edef\m_spreadsheet_comma {\spreadsheetparameter\c!comma}% + \ctxlua{moduledata.spreadsheets.start("#1", { + period = \!!bs\detokenize\expandafter{\m_spreadsheet_period}\!!es, + comma = \!!bs\detokenize\expandafter{\m_spreadsheet_comma}\!!es, + split = "\spreadsheetparameter\c!split", + })}} + +\unexpanded\def\stopspreadsheet + {\ctxlua{moduledata.spreadsheets.stop()}% + \popmacro\currentspreadsheet} + +\unexpanded\def\showspreadsheet + {\dosingleempty\doshowspreadsheet} + +\unexpanded\def\doshowspreadsheet[#1]% + {\ctxlua{moduledata.spreadsheets.show("#1")}} + +\unexpanded\def\getspreadsheet + {\dosingleempty\dogetspreadsheet} + +\unexpanded\def\dosetspreadsheet[#1]#2#3#4% + {\ctxlua{moduledata.spreadsheets.set("#1",\number#2,\number#3,"#4")}} + +\unexpanded\def\setspreadsheet + {\dosingleempty\dosetspreadsheet} + +\unexpanded\def\dogetspreadsheet[#1]#2#3#4% + {\ctxlua{moduledata.spreadsheets.get("#1",\number#2,\number#3,"#4")}} + +\unexpanded\def\doifelsespreadsheetcell + {\dosingleempty\dodoifelsespreadsheetcell} + +\unexpanded\def\dodoifelsespreadsheetcell[#1]#2#3% + {\ctxlua{moduledata.spreadsheets.doifelsecell("#1","#2","#3")}} \def\TABLEsetspreadsheet#1{\ctxlua{moduledata.spreadsheets.set("",\number\tblrow+1,\number\tblcol,\!!bs#1\!!es)}} \def\TABLEgetspreadsheet#1{\ctxlua{moduledata.spreadsheets.get("",\number\tblrow+1,\number\tblcol,\!!bs#1\!!es)}} @@ -47,11 +102,11 @@ \unexpanded\def\dostartspreadsheettable[#1]% {\bgroup - \startspreadsheet[#1]%% + \dostartspreadsheet[#1]%% \def\startrow{\bTR}% \def\stoprow {\eTR}% \def\startcell##1\stopcell{\bTD\getspr{##1}\eTD}% - \bTABLE[\c!align=flushright]} + \bTABLE[\c!align=\v!flushright]} \unexpanded\def\stopspreadsheettable {\eTABLE @@ -86,6 +141,8 @@ \eTR \eTABLE +\setupspreadsheet[mysheet] + \startspreadsheet[mysheet] \bTABLE[align=middle] @@ -93,7 +150,7 @@ \bTD \getspr{100} \eTD \bTD test \setspr{30} \eTD \eTR \bTR - \bTD \getspr{20} \eTD \bTD \getspr{4+3} \eTD + \bTD \getspr{20} \eTD \bTD \getspr{4+3.5} \eTD \eTR \bTR \bTD \getspr{A[1] + A[2]} \eTD @@ -106,17 +163,20 @@ \stopspreadsheet -\startspreadsheettable +\blank + +% \definespreadsheet[test] +\setupspreadsheet[test][period={{\bf\middlered .}},comma={{\bf\middlegreen ,}},split=yes] + +\startspreadsheettable[test] \startrow - \startcell 3 \stopcell - \startcell 9 \stopcell + \startcell 123456.78 \stopcell + \startcell 1234567.89 \stopcell \startcell A[1] + B[1] \stopcell \stoprow \stopspreadsheettable -bla bla \getspreadsheet[mysheet]{2}{2}{} - -bla bla \getspreadsheet[mysheet]{4}{1}{} +\blank % \showspreadsheet % \showspreadsheet[mysheet] diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex 85ef46ca9..00adca956 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex 6c62c37d2..f732ccfa6 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/util-prs.lua b/tex/context/base/util-prs.lua index 392117f0c..66ada23fd 100644 --- a/tex/context/base/util-prs.lua +++ b/tex/context/base/util-prs.lua @@ -6,8 +6,8 @@ if not modules then modules = { } end modules ['util-prs'] = { license = "see context related readme files" } -local P, R, V, C, Ct, Cs, Carg = lpeg.P, lpeg.R, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg -local lpegmatch = lpeg.match +local P, R, V, C, Ct, Cs, Carg, Cc = lpeg.P, lpeg.R, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc +local lpegmatch, patterns = lpeg.match, lpeg.patterns local concat, format, gmatch, find = table.concat, string.format, string.gmatch, string.find local tostring, type, next = tostring, type, next @@ -23,7 +23,7 @@ local sortedhash = table.sortedhash local escape, left, right = P("\\"), P('{'), P('}') -lpeg.patterns.balanced = P { +patterns.balanced = P { [1] = ((escape * (left+right)) + (1 - (left+right)) + V(2))^0, [2] = left * V(1) * right } @@ -39,9 +39,9 @@ local spaces = space^0 local argument = Cs((lbrace/"") * ((nobrace + nested)^0) * (rbrace/"")) local content = (1-P(-1))^0 -lpeg.patterns.nested = nested -- no capture -lpeg.patterns.argument = argument -- argument after e.g. = -lpeg.patterns.content = content -- rest after e.g = +patterns.nested = nested -- no capture +patterns.argument = argument -- argument after e.g. = +patterns.content = content -- rest after e.g = local value = P(lbrace * C((nobrace + nested)^0) * rbrace) + C((nested + (1-comma))^0) @@ -233,3 +233,23 @@ end function parsers.listitem(str) return gmatch(str,"[^, ]+") end + +-- +local digit = R("09") + +local pattern = Cs { "start", + start = V("one") + V("two") + V("three"), + rest = (Cc(",") * V("thousand"))^0 * (P(".") + P(-1)) * P(1)^0, + thousand = digit * digit * digit, + one = digit * V("rest"), + two = digit * digit * V("rest"), + three = V("thousand") * V("rest"), +} + +patterns.splitthousands = pattern -- maybe better in the parsers namespace ? + +function parsers.splitthousands(str) + return lpegmatch(pattern,str) or str +end + +-- print(parsers.splitthousands("11111111111.11")) diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 82237d6de..bc823a1d1 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 06/08/12 17:18:04 +-- merge date : 06/08/12 21:57:11 do -- begin closure to overcome local limits and interference |