On Fri, 16 Mar 2012, Mansour Moufid wrote:

Hello,

Is it possible to access the local indentation character(s), i.e. tab
or whatever number of spaces, from coccilib in Python?

I'd like to print lines of code underlined with carets, a la clang,
from within a @script:python@.

What is accessible in python is the value of metavariable, and metavariables are bound to terms without information about their spacing so that they can match to other terms that look the same but have different spacing.

What you can do is put a position variable on the first token in your pattern. Then the starting column will indicate the indentation. But the indentation will be the number of characters, which might be spaces or might be tabs. It could be possible to store the preceding whitespace in a position variable.

I'm not familiar with what clang does. Is the goal to highlight matched code? Perhaps tere is some separate highlighting tool you can use that will take as input the position information? I use org mode in emacs.

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to