Hello Julia,

Julia Lawall wrote:
> On Mon, 13 Feb 2012, Michael Stefaniuc wrote:
>> Julia Lawall wrote:
>>> Here is a patch that imports expression lists into python as an instance
>> many thanks! The patch seems to work (needs a indentation change for
>> python/coccilib/elems.py on rc9).
>>
>>> of the class ExpressionList, having the methods __getitem__ and __str__.
>>> you can thus write eg:
>> Would it be possible to add a __len__ attribute too? Expression lists
>> can be empty and nicest way to check for that is that len(es) > 0.
> 
> OK, I'll do that.  I guess that you can already get that information
> from es.elements?
I didn't check es.elements; that one has the length.
So please ignore my request. For a split second I thought that for
consistency reasons it makes sense to add the __len__ too. But that
would be confusing as len can mean the number of entries in the list but
also the length of the flat expression list string.

bye
        michael

>>> @r@
>>> expression list es;
>>> @@
>>>
>>> f(es)
>>>
>>> @script:python@
>>> es << r.es;
>>> @@
>>>
>>> print "%s" % es
>>> print "%s" % es[1]
>>>
>>> --------------------
>>>
>>> The elements of the expression list are stored in the "elements" field
>>> of the ExpressionList structure, and thus is it also possible to say eg
>>> es.elements[1].  The elements list does not contain the commas between
>>> the elements.  They have disappeared completely.  The elements are just
>> Sure, the comma isn't part of the expressions.
>>
>>> ordinary strings, not Expression structures.  Maybe making them
>>> Expression structures would be a good idea.  But maybe getting rid of
>>> Expression structures would be better, since they don't offer any
>>> information other than the string representation.
>> I guess that making the expression a string should be fine; I never
>> needed more than the string from python.
>>
>>> Suggestions are welcome.  If this seems to be what is desired, I will do
>>> the same for the other list types.
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to