summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2012-11-22 18:09:00 +0100
committerHans Hagen <pragma@wxs.nl>2012-11-22 18:09:00 +0100
commit0a53837307e4b27c2b6543e3cab740c661d24481 (patch)
tree2a273394c4d9308fbf75e1074b32bcf6c96cef76 /scripts
parent777dbe48211e3165847bcb7352217c7445cba1a4 (diff)
downloadcontext-0a53837307e4b27c2b6543e3cab740c661d24481.tar.gz
beta 2012.11.22 18:09
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtxrun.lua27
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua27
-rwxr-xr-xscripts/context/stubs/unix/mtxrun27
3 files changed, 81 insertions, 0 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 897c39260..5e924b07d 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -6008,6 +6008,33 @@ end
-- inspect(lpeg.match(pattern,[[key="value"]]))
+local newline = S('\r\n')
+
+function parsers.csvsplitter(specification)
+ specification = specification or { }
+ local separator = specification.separator
+ local quotechar = specification.quote
+ local separator = S(separator ~= "" and separator or ",")
+ local whatever = C((1 - separator - newline)^0)
+ if quotechar and quotechar ~= "" then
+ local quotedata = nil
+ for chr in gmatch(quotechar,".") do
+ local quotechar = P(chr)
+ local quoteword = quotechar * C((1 - quotechar)^0) * quotechar
+ if quotedata then
+ quotedata = quotedata + quoteword
+ else
+ quotedata = quoteword
+ end
+ end
+ whatever = quotedata + whatever
+ end
+ local parser = Ct((Ct(whatever * (separator * whatever)^0) * S("\n\r"))^0 )
+ return function(data)
+ return lpegmatch(parser,data)
+ end
+end
+
end -- of closure
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index 897c39260..5e924b07d 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -6008,6 +6008,33 @@ end
-- inspect(lpeg.match(pattern,[[key="value"]]))
+local newline = S('\r\n')
+
+function parsers.csvsplitter(specification)
+ specification = specification or { }
+ local separator = specification.separator
+ local quotechar = specification.quote
+ local separator = S(separator ~= "" and separator or ",")
+ local whatever = C((1 - separator - newline)^0)
+ if quotechar and quotechar ~= "" then
+ local quotedata = nil
+ for chr in gmatch(quotechar,".") do
+ local quotechar = P(chr)
+ local quoteword = quotechar * C((1 - quotechar)^0) * quotechar
+ if quotedata then
+ quotedata = quotedata + quoteword
+ else
+ quotedata = quoteword
+ end
+ end
+ whatever = quotedata + whatever
+ end
+ local parser = Ct((Ct(whatever * (separator * whatever)^0) * S("\n\r"))^0 )
+ return function(data)
+ return lpegmatch(parser,data)
+ end
+end
+
end -- of closure
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index 897c39260..5e924b07d 100755
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -6008,6 +6008,33 @@ end
-- inspect(lpeg.match(pattern,[[key="value"]]))
+local newline = S('\r\n')
+
+function parsers.csvsplitter(specification)
+ specification = specification or { }
+ local separator = specification.separator
+ local quotechar = specification.quote
+ local separator = S(separator ~= "" and separator or ",")
+ local whatever = C((1 - separator - newline)^0)
+ if quotechar and quotechar ~= "" then
+ local quotedata = nil
+ for chr in gmatch(quotechar,".") do
+ local quotechar = P(chr)
+ local quoteword = quotechar * C((1 - quotechar)^0) * quotechar
+ if quotedata then
+ quotedata = quotedata + quoteword
+ else
+ quotedata = quoteword
+ end
+ end
+ whatever = quotedata + whatever
+ end
+ local parser = Ct((Ct(whatever * (separator * whatever)^0) * S("\n\r"))^0 )
+ return function(data)
+ return lpegmatch(parser,data)
+ end
+end
+
end -- of closure