lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Feb 14, 2012 at 23:13, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> In particular we want to find the string concatenations in loops:
>>
>> local foo = ...
>> for ... do
>>   ...
>>   foo = something .. foo .. something .. else
>>   ...
>> end
>
> Wouldn't be easier to find string concatenations used with accumulators?
> I guess the following pattern (for plain Lua pattern matching),
> applied at each line of the program, would be a good filter:
>
>  p = "^%s*([a-zA-Z_][a-zA-Z0-9_]*)%s*=.*%1%s*%.%."
>
> You may also need this other one:
>
>  p = "^%s*([a-zA-Z_][a-zA-Z0-9_]*)%s*=.*%.%.%s*%1"
>
> (You may need to change it something if you want to detect accumulation
> over a table field, like a.x = a.x .. something...)

This approach would work for me, and will give even results closer to
what I need, thank you for the insight!

Alexander.