Hello John, Joel, I didn't mean to knock your work with that last email John, it might have come across badly, it was meant more as a compliment to spirit and a reference to the fact that it 'appears' to fit the bill for what I want to do better, not to bash regex, I like regex too. For the record it needn't be 'perfect' indexing of the C++ code, I don't mind if I get two hits for the same classname for example. I used regex for a tool to index the C++ and C files themselves, so I could quickly search for file names using regular expressions, it works great! So thank you both, no offence caused I hope. So, will spirit be the best way then? Glad to hear its already a part of boost btw, congratulations mate. Cheers! Gaz -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of John Maddock Sent: 30 September 2004 11:33 To: Subject: Re: [Boost-users] Boost:regex and C++ Parsing - Clarification
Thank you Caleb and Hartmut for your replies. You both seem to think regex is a bad way to go, I will explain better what I want to write just to be clear.
I want to write a tool (cli probably) where I can say, here you go, here is a large folder full of code, go and parse it. I will store the results in XML format somewhere, then, I can do say, "<myapp> class someclass" and the program will go and find where that class is declared/defined using its database, saving me headache.
So I thought I could use one of the C++ expat wrappers, and boost regex looked powerful enough to do the parsing if only I were handy enough with regular expression syntax.
Anyway, I don't know if that better explanation will make any difference to you recommendations, I look forward to reading you opinions.
Oh, and the example I looked at is here Hartmut: http://boost.org/libs/regex/example/snippets/regex_search_example.cpp - that is what got me thinking I might actually be able to take on this challenge.
It depends what you want to do: if you want to use a "real" C++ parser then you will also have to preprocess the code (including the includes) and then parse the code. In theory this gives you a "perfect" result, but only if you know what include paths to use, and what predefined macros should be set (think about conditional code blocks). Regexes on the other hand, don't require you to preprocess the code, but can get confused by macros and the like. So you have to choose the way that best meets your expectations, and live with the defects either which way ;-) To solve your problem BTW, why not scan through the file for line starts (keeping count obviously!), and at each line start see if it's also the start of the regex you are interested in (one that matches a class definition for example), if you do this don't forget to either: prefix your expression with \A or Pass the match_continuous flag to regex_search, Either will anchor the search at the start of the line you are checking, and prevent the whole text being searched. John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi Gareth,
So, will spirit be the best way then? Glad to hear its already a part of boost btw, congratulations mate.
there might be another option. The gcc-xml project (http://www.gccxml.org) lets you use gcc for parsing. Volker -- Volker Börchers TECON Systems AG, http://www.tecon.de
On Thu, Sep 30, 2004 at 04:29:52PM +0200, Volker Boerchers wrote:
Hi Gareth,
So, will spirit be the best way then? Glad to hear its already a part of boost btw, congratulations mate.
there might be another option. The gcc-xml project (http://www.gccxml.org) lets you use gcc for parsing.
Or doxygen might serve as a useful example. http://www.doxygen.org/ Justin
Justin Findlay
On Thu, Sep 30, 2004 at 04:29:52PM +0200, Volker Boerchers wrote:
Hi Gareth,
So, will spirit be the best way then? Glad to hear its already a part of boost btw, congratulations mate.
there might be another option. The gcc-xml project (http://www.gccxml.org) lets you use gcc for parsing.
Or doxygen might serve as a useful example.
See also http://article.gmane.org/gmane.comp.lib.boost.devel/111012 -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
So thank you both, no offence caused I hope.
None taken: use the right tool for the right job (but obviously I'm biased!). Probably it just depends on whether you're happier writing a regex or a spirit-parser, and whether your app is already using one or the other of these, Regards, John.
participants (5)
-
David Abrahams
-
Foster, Gareth
-
John Maddock
-
Justin Findlay
-
Volker Boerchers