[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: New long comments in 5.1
- From: Philippe Lhoste <PhiLho@...>
- Date: Mon, 21 Jun 2004 18:22:53 +0200
Virgil Smith wrote:
OK, I have another proposal:
...
I propose the ultimate flexibility: user defined syntax.
IMHO this is an excellent suggestion (though I personally think it should be
an add-on with a chunk-reader interface rather than part of the core).
The great advantage here is that Lua is typically used "embedded" in an
application, and lot's of Lua integrators are faced with transitioning users
from another (often "home-grown") scripting language. So being able to
"fudge" the syntax a bit is very useful.
Well, I thought of it this evening, it could be fun...
Actually, you can use the same VM, the same bytecode, you just have to
change the lexer... Of course, that's no longer Lua, but you still get
its flexibility, small size, power, etc.
What about:
defFunc Split(toSplit, separator)
local splitted <- <<>>
local i <- 0
'' Regular expression:
'' 0 or more characters differents from separator, followed by 0 or 1
separator
local re <- ~([^~ @ separator @ ~]*)~ @ separator @ ~?~
'' Add a separator to the end, to take in account empty field (if any)
at the end of the line
for part <<| string.gfind(toSplit @ separator, re)
{
i <- i + 1
splitted<i> <- part
}
splitted[i] <- nil
return splitted
endFunc
in place of:
function Split(toSplit, separator)
local splitted = {}
local i = 0
-- Regular expression:
-- 0 or more characters differents from separator, followed by 0 or 1
separator
local re = "([^" .. separator .. "]*)" .. separator .. "?"
-- Add a separator to the end, to take in account empty field (if any)
at the end of the line
for part in string.gfind(toSplit .. separator, re) do
i = i + 1
splitted[i] = part
end
splitted[i] = nil
return splitted
end
Definitively gives a "novel" look, even more if you rename library
functions... The grammar must be careful thought, to avoid ambiguities...
--
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://Phi.Lho.free.fr
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--