Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. regex parsing C++

regex parsing C++

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++wpfregexjson
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alex barylski
    wrote on last edited by
    #1

    I'm a newbie to regex so please take it easy on me. What would be the best approach for parsing C++ templates (inline functions only) and extracting some comments so I can generat a bit of documentation? I'm interested in the approach (or regex if you feel generous) in parsing source code and generating primitive docs from it, NOT in finding an already made solution like the many source code doc generators out there already...so please don't send me links to DOxygen or anything....unless it outlines the techniques they used :) I basically want to use a special commment like // TODO: Blah blah to generate todo lists and also extract class interfaces (including private and protected) Any ideas??? Cheers :) How do I print my voice mail?

    E S 2 Replies Last reply
    0
    • A alex barylski

      I'm a newbie to regex so please take it easy on me. What would be the best approach for parsing C++ templates (inline functions only) and extracting some comments so I can generat a bit of documentation? I'm interested in the approach (or regex if you feel generous) in parsing source code and generating primitive docs from it, NOT in finding an already made solution like the many source code doc generators out there already...so please don't send me links to DOxygen or anything....unless it outlines the techniques they used :) I basically want to use a special commment like // TODO: Blah blah to generate todo lists and also extract class interfaces (including private and protected) Any ideas??? Cheers :) How do I print my voice mail?

      E Offline
      E Offline
      Erik Thompson
      wrote on last edited by
      #2

      A regular expression would be simple to do the "// TODO:" searches and output the results to wherever. But I think VS.NET already does this for you in their tasklist addin. And also just doing a strstr would be faster and less involved then using a regex set. As for parsing C++ templates you'd have to incorporate into your regex parser the grammer for C++ templates which most people would probably just pull out of gcc and use flexx/bison (lex/yacc) to build up what they needed to parse the c++ templates which would do the regular expressions for you. Then you just plug into the grammer where needed to generate what you wanted at the times you wanted it. As for printing your voice mail. Hook your VMail system up to a Speech to Text(S2T) system and then connect your S2T sytem to a parrellel port that connects to your printer. Then push your VMail into the S2T the output of the S2T into the printer to get your vmail to paper and thus printed. Cheers, -Erik

      A 1 Reply Last reply
      0
      • A alex barylski

        I'm a newbie to regex so please take it easy on me. What would be the best approach for parsing C++ templates (inline functions only) and extracting some comments so I can generat a bit of documentation? I'm interested in the approach (or regex if you feel generous) in parsing source code and generating primitive docs from it, NOT in finding an already made solution like the many source code doc generators out there already...so please don't send me links to DOxygen or anything....unless it outlines the techniques they used :) I basically want to use a special commment like // TODO: Blah blah to generate todo lists and also extract class interfaces (including private and protected) Any ideas??? Cheers :) How do I print my voice mail?

        S Offline
        S Offline
        Snyp
        wrote on last edited by
        #3

        Well you probably would have to make a parser yourself, probably search a specified file(s)/folder(s) and then search through them for '//TODO:' and then use getline or copy the contents until you come up to a \n Actual Linux Penguins were harmed in the creation of this message.

        1 Reply Last reply
        0
        • E Erik Thompson

          A regular expression would be simple to do the "// TODO:" searches and output the results to wherever. But I think VS.NET already does this for you in their tasklist addin. And also just doing a strstr would be faster and less involved then using a regex set. As for parsing C++ templates you'd have to incorporate into your regex parser the grammer for C++ templates which most people would probably just pull out of gcc and use flexx/bison (lex/yacc) to build up what they needed to parse the c++ templates which would do the regular expressions for you. Then you just plug into the grammer where needed to generate what you wanted at the times you wanted it. As for printing your voice mail. Hook your VMail system up to a Speech to Text(S2T) system and then connect your S2T sytem to a parrellel port that connects to your printer. Then push your VMail into the S2T the output of the S2T into the printer to get your vmail to paper and thus printed. Cheers, -Erik

          A Offline
          A Offline
          alex barylski
          wrote on last edited by
          #4

          Erik Thompson wrote: But I think VS.NET already does this for you in their tasklist addin It's actually not for C++ it's for PHP and the editor I use doesn't support VS addins i'm afraid :) The TODO I already have figured out :) Erik Thompson wrote: As for parsing C++ templates you'd have to incorporate into your regex parser the grammer for C++ templates which most people would probably just pull out of gcc and use flexx/bison (lex/yacc) to build up what they needed to parse the c++ templates which would do the regular expressions for you. Then you just plug into the grammer where needed to generate what you wanted at the times you wanted it. I'm looking for simplicity in development and I have a helluva time understanding parsing grammers...i've already looked into Spirit and i'm not exactly blown away by it's ease of use...I need just a simple doc gen so i care not if it's inefficient... I want to use regex because I figured it would be easier to do something like: 1) Find any TODO: which folows directly after // or /* and continues until end of line or corresponding */ is found (if applicable) 2) Find all characters after TODO: and before EOL or */ Thats my TODO list :) As for finding classes (im thinking): 1) find class cls_name{} 2) Extract the class name and store in vector 3) Get any comments preceeding class declaration which have a \brief switch directly after // or /* 4) Extract each of classes member functions and variables 5) Pull comments about each member as well Once i've complied a couple vectors with this information I figure I could easily generate HTML docs :) And i'd be happy :) Erik Thompson wrote: As for printing your voice mail. Hook your VMail system up to a Speech to Text(S2T) system and then connect your S2T sytem to a parrellel port that connects to your printer. Then push your VMail into the S2T the output of the S2T into the printer to get your vmail to paper and thus printed. That was actually a .... IT pet peeves list??? of the ten most annoying questions asked by complete idiots or something along those lines...when I read it...I laughed, thought it was funny so I use it as my sig :) To bad I didn't keep that link I could send them your answer so they can finally answer their clients :) Cheers How do I print my voice mail?

          A 1 Reply Last reply
          0
          • A alex barylski

            Erik Thompson wrote: But I think VS.NET already does this for you in their tasklist addin It's actually not for C++ it's for PHP and the editor I use doesn't support VS addins i'm afraid :) The TODO I already have figured out :) Erik Thompson wrote: As for parsing C++ templates you'd have to incorporate into your regex parser the grammer for C++ templates which most people would probably just pull out of gcc and use flexx/bison (lex/yacc) to build up what they needed to parse the c++ templates which would do the regular expressions for you. Then you just plug into the grammer where needed to generate what you wanted at the times you wanted it. I'm looking for simplicity in development and I have a helluva time understanding parsing grammers...i've already looked into Spirit and i'm not exactly blown away by it's ease of use...I need just a simple doc gen so i care not if it's inefficient... I want to use regex because I figured it would be easier to do something like: 1) Find any TODO: which folows directly after // or /* and continues until end of line or corresponding */ is found (if applicable) 2) Find all characters after TODO: and before EOL or */ Thats my TODO list :) As for finding classes (im thinking): 1) find class cls_name{} 2) Extract the class name and store in vector 3) Get any comments preceeding class declaration which have a \brief switch directly after // or /* 4) Extract each of classes member functions and variables 5) Pull comments about each member as well Once i've complied a couple vectors with this information I figure I could easily generate HTML docs :) And i'd be happy :) Erik Thompson wrote: As for printing your voice mail. Hook your VMail system up to a Speech to Text(S2T) system and then connect your S2T sytem to a parrellel port that connects to your printer. Then push your VMail into the S2T the output of the S2T into the printer to get your vmail to paper and thus printed. That was actually a .... IT pet peeves list??? of the ten most annoying questions asked by complete idiots or something along those lines...when I read it...I laughed, thought it was funny so I use it as my sig :) To bad I didn't keep that link I could send them your answer so they can finally answer their clients :) Cheers How do I print my voice mail?

            A Offline
            A Offline
            Andrew Walker
            wrote on last edited by
            #5

            Hockey wrote: It's actually not for C++ it's for PHP I'm a bit confused - so If I've got it wrong and you actually want to parse PHP please forgive me :-O. If it is C++ that you want to parse my suggestion is that you don't even try. It's far too hard - use something else someone has already done. Even doxygen, which is brilliant at what it does, clearly states that there are problems with the parser (I've never seen them, but I'm sure that the Doxygen team would know). Doxygen does however ship with source, and with some (rather large) tweaks i'm sure you could get it to output what you needed. If you've looked at spirit it might be worth looking at boost::regex which contains at least a partial scan of a C++ file for keywords and classes, but I doubt that's what you're looking for. If you need to get more information than doxygen (especially the XML output of doxygen) can provide, I strongly suggest you at least check out GCC-XML[^] which outputs the GCC compiler database to XML - everything except for method bodies (which you didn't ask for) and comments (which you seem to have sorted anyway) are included in the output. GCCXML was a pain to set it up to work inside VS.NET but it works quite well unless you use huge numbers of templates (eg/ the boost libraries) and then the problem comes down to the (albeit small) differences in the way Microsoft and GCC compilers parse code. The output files from GCCXML are enormous, so finding good ways to filter out the data that you don't want is critical. Good Luck!


            If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

            A 1 Reply Last reply
            0
            • A Andrew Walker

              Hockey wrote: It's actually not for C++ it's for PHP I'm a bit confused - so If I've got it wrong and you actually want to parse PHP please forgive me :-O. If it is C++ that you want to parse my suggestion is that you don't even try. It's far too hard - use something else someone has already done. Even doxygen, which is brilliant at what it does, clearly states that there are problems with the parser (I've never seen them, but I'm sure that the Doxygen team would know). Doxygen does however ship with source, and with some (rather large) tweaks i'm sure you could get it to output what you needed. If you've looked at spirit it might be worth looking at boost::regex which contains at least a partial scan of a C++ file for keywords and classes, but I doubt that's what you're looking for. If you need to get more information than doxygen (especially the XML output of doxygen) can provide, I strongly suggest you at least check out GCC-XML[^] which outputs the GCC compiler database to XML - everything except for method bodies (which you didn't ask for) and comments (which you seem to have sorted anyway) are included in the output. GCCXML was a pain to set it up to work inside VS.NET but it works quite well unless you use huge numbers of templates (eg/ the boost libraries) and then the problem comes down to the (albeit small) differences in the way Microsoft and GCC compilers parse code. The output files from GCCXML are enormous, so finding good ways to filter out the data that you don't want is critical. Good Luck!


              If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

              A Offline
              A Offline
              alex barylski
              wrote on last edited by
              #6

              Andrew Walker wrote: If you've looked at spirit it might be worth looking at boost::regex which contains at least a partial scan of a C++ file for keywords and classes, but I doubt that's what you're looking for. I'm using boost actually but I couldn't find the C++ scan example??? I'll have to look again...i'm not actually parsing C++ just extracting some details like DOxygen... probably a little less How do I print my voice mail?

              A 1 Reply Last reply
              0
              • A alex barylski

                Andrew Walker wrote: If you've looked at spirit it might be worth looking at boost::regex which contains at least a partial scan of a C++ file for keywords and classes, but I doubt that's what you're looking for. I'm using boost actually but I couldn't find the C++ scan example??? I'll have to look again...i'm not actually parsing C++ just extracting some details like DOxygen... probably a little less How do I print my voice mail?

                A Offline
                A Offline
                Andrew Walker
                wrote on last edited by
                #7

                Have a look at: boost_1_31_0\libs\regex\example\snippets\regex_grep_example_1.cpp but all the examples are pretty good, I think one is even a pretty printer for C++ code


                If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups