1 -------------------------------------------------------------------------------
2 -- Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 -- (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 -------------------------------------------------------------------------------
12 create_from_hline
= function(hline
, from
, to
)
18 setmetatable(o
, Text
[".object_meta_table"])
23 return self
.line
:mid(self
.from
, self
.to
)
30 clone
= function(self
)
31 local hline
= self
.line
:extract(self
.from
, self
.to
)
32 return Text
.create_from_hline(hline
, 0, hline
.length
)
36 __call
= function(prototype
, str
)
37 local hline
= HLine(str
)
38 return prototype
.create_from_hline(hline
, 0, hline
.length
)
41 [".object_meta_table"] = {
42 __index
= function(self
, property
)
43 local h
= Text
[".getter_table"][property
]
47 h
= Text
[".method_table"][property
]
56 __newindex
= function(self
, property
, value
)
57 self
.line
["set_" .. property
](self
.line
, self
.from
, self
.to
, value
)
60 __call
= function(self
, from
, to
)
61 if (to
> self
.to
) then
62 error("Index " .. to
.. " is too large")
64 return Text
.create_from_hline(self
.line
, from
+ self
.from
, to
+ self
.from
)
67 __add
= function(self
, other
)
68 local hline
= self
:clone().line
:append(other
.line
, other
.from
, other
.to
)
69 return Text
.create_from_hline(hline
, 0, hline
.length
)
73 setmetatable(Text
, Text
[".meta_table"])
81 __newindex
= function(self
, re
, h
)
86 table.insert(__patterns__
, event
)
88 __call
= function(self
, re
, h
)
93 setmetatable(highlight
, {
94 __newindex
= function(self
, re
, fmt
)
95 local function handler()
96 local function set_property(prop
)
97 if fmt
[prop
] ~= nil then
98 match
[prop
] = fmt
[prop
]
102 set_property("italic")
103 set_property("color")
106 table.insert(__patterns__
, { pattern
= re
, handler
= handler
})
109 __call
= function(self
, re
, fmt
)
115 table.insert(__patterns__
, { pattern
= re
, handler
= function() end})
118 function __run_event__(event
, str
, match
, ref
, state
)
119 env
= getfenv(event
.handler
)
121 env
.match
= env
.line(match
.from
, match
.to
)
123 for i
, r
in ipairs(ref
) do
124 env
.ref
[i
] = env
.line(ref
[i
].from
, ref
[i
].to
)
126 for k
, v
in pairs(state
) do
129 setfenv(event
.handler
, env
)
131 local result
= event
.handler()
133 if result
~= nil then