summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-10-20 04:00:13 +0300
committerMarius <mariausol@gmail.com>2012-10-20 04:00:13 +0300
commit1fbec75954e7911bd1546a04af666fc1a3827a54 (patch)
tree16f39836f5e13bd1220a2ffc55e11912dde5bd82 /scripts
parentc36e19abdfd15bf6cae6fa379c6ce51f3ef5332d (diff)
downloadcontext-1fbec75954e7911bd1546a04af666fc1a3827a54.tar.gz
beta 2012.10.20 02:07
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtxrun.lua60
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua60
-rw-r--r--scripts/context/stubs/unix/mtxrun60
3 files changed, 66 insertions, 114 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index e6bbbe2b5..b3170f7b2 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -171,7 +171,7 @@ string.itself = function(s) return s end
-- also handy (see utf variant)
-local pattern = Ct(C(1)^0)
+local pattern = Ct(C(1)^0) -- string and not utf !
function string.totable(str)
return lpegmatch(pattern,str)
@@ -330,6 +330,16 @@ local function sortedhashkeys(tab) -- fast one
end
end
+function table.allkeys(t)
+ local keys = { }
+ for i=1,#t do
+ for k, v in next, t[i] do
+ keys[k] = true
+ end
+ end
+ return sortedkeys(keys)
+end
+
table.sortedkeys = sortedkeys
table.sortedhashkeys = sortedhashkeys
@@ -1581,15 +1591,10 @@ end
function lpeg.replacer(one,two)
if type(one) == "table" then
local no = #one
- local p
+ local p = P(false)
if no == 0 then
for k, v in next, one do
- local pp = P(k) / v
- if p then
- p = p + pp
- else
- p = pp
- end
+ p = p + P(k) / v
end
return Cs((p + 1)^0)
elseif no == 1 then
@@ -1599,12 +1604,7 @@ function lpeg.replacer(one,two)
else
for i=1,no do
local o = one[i]
- local pp = P(o[1]) / o[2]
- if p then
- p = p + pp
- else
- p = pp
- end
+ p = p + P(o[1]) / o[2]
end
return Cs((p + 1)^0)
end
@@ -1721,13 +1721,9 @@ lpeg.UP = lpeg.P
if utfcharacters then
function lpeg.US(str)
- local p
+ local p = P(false)
for uc in utfcharacters(str) do
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
return p
end
@@ -1736,13 +1732,9 @@ if utfcharacters then
elseif utfgmatch then
function lpeg.US(str)
- local p
+ local p = P(false)
for uc in utfgmatch(str,".") do
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
return p
end
@@ -1750,13 +1742,9 @@ elseif utfgmatch then
else
function lpeg.US(str)
- local p
+ local p = P(false)
local f = function(uc)
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
lpegmatch((utf8char/f)^0,str)
return p
@@ -1782,13 +1770,9 @@ function lpeg.UR(str,more)
if first == last then
return P(str)
elseif utfchar and last - first < 8 then -- a somewhat arbitrary criterium
- local p
+ local p = P(false)
for i=first,last do
- if p then
- p = p + P(utfchar(i))
- else
- p = P(utfchar(i))
- end
+ p = p + P(utfchar(i))
end
return p -- nil when invalid range
else
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index e6bbbe2b5..b3170f7b2 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -171,7 +171,7 @@ string.itself = function(s) return s end
-- also handy (see utf variant)
-local pattern = Ct(C(1)^0)
+local pattern = Ct(C(1)^0) -- string and not utf !
function string.totable(str)
return lpegmatch(pattern,str)
@@ -330,6 +330,16 @@ local function sortedhashkeys(tab) -- fast one
end
end
+function table.allkeys(t)
+ local keys = { }
+ for i=1,#t do
+ for k, v in next, t[i] do
+ keys[k] = true
+ end
+ end
+ return sortedkeys(keys)
+end
+
table.sortedkeys = sortedkeys
table.sortedhashkeys = sortedhashkeys
@@ -1581,15 +1591,10 @@ end
function lpeg.replacer(one,two)
if type(one) == "table" then
local no = #one
- local p
+ local p = P(false)
if no == 0 then
for k, v in next, one do
- local pp = P(k) / v
- if p then
- p = p + pp
- else
- p = pp
- end
+ p = p + P(k) / v
end
return Cs((p + 1)^0)
elseif no == 1 then
@@ -1599,12 +1604,7 @@ function lpeg.replacer(one,two)
else
for i=1,no do
local o = one[i]
- local pp = P(o[1]) / o[2]
- if p then
- p = p + pp
- else
- p = pp
- end
+ p = p + P(o[1]) / o[2]
end
return Cs((p + 1)^0)
end
@@ -1721,13 +1721,9 @@ lpeg.UP = lpeg.P
if utfcharacters then
function lpeg.US(str)
- local p
+ local p = P(false)
for uc in utfcharacters(str) do
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
return p
end
@@ -1736,13 +1732,9 @@ if utfcharacters then
elseif utfgmatch then
function lpeg.US(str)
- local p
+ local p = P(false)
for uc in utfgmatch(str,".") do
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
return p
end
@@ -1750,13 +1742,9 @@ elseif utfgmatch then
else
function lpeg.US(str)
- local p
+ local p = P(false)
local f = function(uc)
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
lpegmatch((utf8char/f)^0,str)
return p
@@ -1782,13 +1770,9 @@ function lpeg.UR(str,more)
if first == last then
return P(str)
elseif utfchar and last - first < 8 then -- a somewhat arbitrary criterium
- local p
+ local p = P(false)
for i=first,last do
- if p then
- p = p + P(utfchar(i))
- else
- p = P(utfchar(i))
- end
+ p = p + P(utfchar(i))
end
return p -- nil when invalid range
else
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index e6bbbe2b5..b3170f7b2 100644
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -171,7 +171,7 @@ string.itself = function(s) return s end
-- also handy (see utf variant)
-local pattern = Ct(C(1)^0)
+local pattern = Ct(C(1)^0) -- string and not utf !
function string.totable(str)
return lpegmatch(pattern,str)
@@ -330,6 +330,16 @@ local function sortedhashkeys(tab) -- fast one
end
end
+function table.allkeys(t)
+ local keys = { }
+ for i=1,#t do
+ for k, v in next, t[i] do
+ keys[k] = true
+ end
+ end
+ return sortedkeys(keys)
+end
+
table.sortedkeys = sortedkeys
table.sortedhashkeys = sortedhashkeys
@@ -1581,15 +1591,10 @@ end
function lpeg.replacer(one,two)
if type(one) == "table" then
local no = #one
- local p
+ local p = P(false)
if no == 0 then
for k, v in next, one do
- local pp = P(k) / v
- if p then
- p = p + pp
- else
- p = pp
- end
+ p = p + P(k) / v
end
return Cs((p + 1)^0)
elseif no == 1 then
@@ -1599,12 +1604,7 @@ function lpeg.replacer(one,two)
else
for i=1,no do
local o = one[i]
- local pp = P(o[1]) / o[2]
- if p then
- p = p + pp
- else
- p = pp
- end
+ p = p + P(o[1]) / o[2]
end
return Cs((p + 1)^0)
end
@@ -1721,13 +1721,9 @@ lpeg.UP = lpeg.P
if utfcharacters then
function lpeg.US(str)
- local p
+ local p = P(false)
for uc in utfcharacters(str) do
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
return p
end
@@ -1736,13 +1732,9 @@ if utfcharacters then
elseif utfgmatch then
function lpeg.US(str)
- local p
+ local p = P(false)
for uc in utfgmatch(str,".") do
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
return p
end
@@ -1750,13 +1742,9 @@ elseif utfgmatch then
else
function lpeg.US(str)
- local p
+ local p = P(false)
local f = function(uc)
- if p then
- p = p + P(uc)
- else
- p = P(uc)
- end
+ p = p + P(uc)
end
lpegmatch((utf8char/f)^0,str)
return p
@@ -1782,13 +1770,9 @@ function lpeg.UR(str,more)
if first == last then
return P(str)
elseif utfchar and last - first < 8 then -- a somewhat arbitrary criterium
- local p
+ local p = P(false)
for i=first,last do
- if p then
- p = p + P(utfchar(i))
- else
- p = P(utfchar(i))
- end
+ p = p + P(utfchar(i))
end
return p -- nil when invalid range
else