Re: extract c/cpp include file with regular expression

2009-07-23 Thread tiefeng wu
Thanks, Philip Semanchuk and Nick Craig-Wood! My goal is gather informations from cpp sources and generate cross referenced html files (as more detail as fine) So I think " missing some unusual cases" might be acceptable, but informations you introduced make me more interests to dig things out :) I

Re: extract c/cpp include file with regular expression

2009-07-23 Thread Nick Craig-Wood
tiefeng wu wrote: > I need to parse c/cpp source files, one requirement is to extract > included header file name. If you are serious about parsing C code then you'll want to investigate gcc-xml http://www.gccxml.org/HTML/Index.html This runs the gcc frontend over the code but instead of prod

Re: extract c/cpp include file with regular expression

2009-07-23 Thread Philip Semanchuk
On Jul 23, 2009, at 12:36 PM, tiefeng wu wrote: 2009/7/24 Philip Semanchuk : I know this will sound like a sarcastic comment, but it is sincere: my suggestion is that if you want to parse C/C++ (or Python, or Perl, or Fortran, etc.), use a real parser, not regexes unless you're willing t

Re: extract c/cpp include file with regular expression

2009-07-23 Thread tiefeng wu
2009/7/24 Philip Semanchuk : > > I know this will sound like a sarcastic comment, but it is sincere: my > suggestion is that if you want to parse C/C++ (or Python, or Perl, or > Fortran, etc.), use a real parser, not regexes unless you're willing to > sacrifice some accuracy. Sooner or later you'll

Re: extract c/cpp include file with regular expression

2009-07-23 Thread tiefeng wu
MRAB wrote: > I'd probably do: > p = re.compile(r'#\s*include\s+(?:<([^>]*)>|"([^"]*)")') m = p.search('#include ') m.group(1) or m.group(2) > 'header.h' > yes, it's easier to understand. thanks, MRAB! I always make things complicated :P tiefeng wu 2009-07-23 -- http://mail.python

Re: extract c/cpp include file with regular expression

2009-07-23 Thread MRAB
tiefeng wu wrote: Hi all! I need to parse c/cpp source files, one requirement is to extract included header file name. here is my solution: p = re.compile(r'#\s*include\s+(?:(<)|("))(.*)(?(1)>)(?(2)")') m = re.search(p, '#include ') m.group(3) 'header.h' m = re.search(p, '#include "header.h"')

Re: extract c/cpp include file with regular expression

2009-07-23 Thread Philip Semanchuk
On Jul 23, 2009, at 11:46 AM, tiefeng wu wrote: Hi all! I need to parse c/cpp source files, one requirement is to extract included header file name. here is my solution: p = re.compile(r'#\s*include\s+(?:(<)|("))(.*)(?(1)>)(?(2)")') m = re.search(p, '#include ') m.group(3) 'header.h' m = re.

extract c/cpp include file with regular expression

2009-07-23 Thread tiefeng wu
Hi all! I need to parse c/cpp source files, one requirement is to extract included header file name. here is my solution: >>> p = re.compile(r'#\s*include\s+(?:(<)|("))(.*)(?(1)>)(?(2)")') >>> m = re.search(p, '#include ') >>> m.group(3) 'header.h' >>> m = re.search(p, '#include "header.h"') >>> m.