2021-08-16 08:22:24 +00:00
|
|
|
#!/usr/bin/env lua
|
2019-09-12 14:11:52 +00:00
|
|
|
-- vim: set noexpandtab tabstop=3 :miv --
|
|
|
|
|
|
|
|
local ansicolors = require 'ansicolors'
|
|
|
|
local lpeg = require 'lpeg'
|
|
|
|
|
|
|
|
local colors = { 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan' }
|
|
|
|
|
|
|
|
local function uncase(str)
|
|
|
|
local p = lpeg.P(0)
|
|
|
|
for char in str:gmatch('.') do
|
|
|
|
p = p * (lpeg.P(char:upper()) + lpeg.P(char:lower()))
|
|
|
|
end
|
|
|
|
return p
|
|
|
|
end
|
|
|
|
|
|
|
|
local pattern = lpeg.P(false)
|
|
|
|
for i=1, select('#', ...) do
|
|
|
|
pattern = pattern + uncase(select(i, ...)) / function(capture) return ansicolors('%{'..colors[(i-1)%#colors+1]..' underline}'..capture) end
|
|
|
|
end
|
|
|
|
|
|
|
|
pattern = lpeg.Cs((pattern + lpeg.P(1)) ^ 1)
|
|
|
|
|
|
|
|
for line in io.stdin:lines() do
|
|
|
|
print(pattern:match(line) or '')
|
|
|
|
end
|