Re: [cocci] Python script interacting with non-matching files?
Julia Lawall <[email protected]> Fri, 13 Mar 2026 15:15:29 +0100 (CET)
| Newsgroups | fr.inria.cocci |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 12 Mar 2026, Alice Lee wrote: > > Hello, > > I am trying to use Coccinelle to search C code bases and I have a few > questions. > > 1. Can a python script within a Coccinelle file somehow access the names of > files that are processed without matching the search? (Maybe there is > some "match all" idiom that would let me get the name of every file and > then move on to the relevant search?) I don't completely understand the question. You can attach a position variable to some matched code and then print the file name associated with that code: @r@ position p; @@ foo@p(); @script:python@ p << r.p; @@ print p[0].file // put proper python code here > 2. Similarly, can a python script tell that parsing failed for a particular > file? No, python doesn't have an access to the information about what could be parsed. There is --verbose-parsing. But parsing rarely fails for a whole file. If it can't parse one thing, it will just move on to the next thing and try from there. julia > Thank you, > Alice Lee   > > >