[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] Gel 0.2
- From: "Remo Dentato" <rdentato@...>
- Date: Wed, 20 Aug 2003 15:45:03 +0200
An update version of gel is available at http://gel-tool.sourceforge.net.
This version has a "gema-like" interface and no longer a Lua interpreter
interface.
I've also added a little bit of documentation.
To make you, hopefully, a little bit more interested here is an example.
Let's imagine we have to solve the following problem:
<< Collect identifiers from a file and sourround them with "<id>" and
"</id>" tags. If it's not the first time you encounter that identifers, add
the attribute "first" to the id tag with the line where you first
encountered it as value. At the end, write a sorted index of identifiers
with the line where they first appear.>>
Here is a possible solution in gel:
----8<---- cut -----8<---- cut -----8<---- cut -----8<----
![
id_ln={}; n_id={}; table.setn(n_id,0)
function check_id(id,ln)
local t=""
if id_ln[id] then
t=" first=\""..id_ln[id].."\""
else
id_ln[id]=ln
table.insert(n_id,id)
end
return "<id"..t..">"..id.."</id>"
end
function sort_id()
table.sort(n_id)
gel.write("\n")
for n,id in pairs(n_id) do
gel.write(id.." "..id_ln[id].."\n")
end
end
!]
<I>=@lua{return check_id("$0",@line)}
\Z=@lua{sort_id()}
----8<---- cut -----8<---- cut -----8<---- cut -----8<----
Short enough, isn't it?
Enjoy,
Remo