From: Baptiste L. <gai...@fr...> - 2003-05-15 19:30:31
|
----- Original Message ----- From: "Andre Baresel" <and...@gm...> To: "CppTool Mailing List" <Cpp...@li...> Sent: Thursday, May 15, 2003 6:22 PM Subject: Re: [Cpptool-develop] astdump runner... > Baptiste Lepilleur wrote: > >One idea I had was something like that: > > > >CStringView classDecl, className; > >// parser for: 'class' class-name : > >const Xtl::MiniParser &parser2 = (Xtl::StringMiniParser( "class " ) > > >> > >Xtl::CppIdentifierMiniParser()[className] > > >> Xtl::CharMiniParser( > >':' ))[classDecl]; > > > >But this would not work when working with repetition parser (for example, to > >match the repetition of ('::' id) ). Any ideas ? > > > Well - it should work if the repeatition parser does some look ahead and > allows only "::" to be 'eaten' I not clear in my question. I was not refering to 'how to get the (::id)* pattern to work' (the mini-parser has infinite look-ahead, but how to store the matched results. When this pattern is matched, you will want the range of each matched 'token' (:: or id), and the range of the matched pattern. That same pattern can be part of a much larger one (the begining of a class declaration). The resulting matched range can be seen as a list, but the user will need the tree structure to use them. For example, if you match something like 'class' +(::Id) ?( '{' ... '}') ';', the resulting would look like something like this: + ['class' range] + [+(::Id) range] |-+['::'] |-+[Id] |-+['::'] |-+[Id] + ['{' ... '}'] // may not be present + [';'] The user need to be able to request a given matched range easily, but I not found a simple way to do that yet. The tree structure and optional element make this difficult, and I'm not even getting into the presence of alternative... > (than it will stop at a single colon). > Apart from that: > is it possible to declare a class like this > class XXX::class_name : public C { > }; Yes, and it's fairly common (pimpl idiom): class Main { class Impl; }; class Main::Impl : public BaseImpl { }; > The miniparser stuff sounds good - seems to go into the direction of the > boost parser but a little > bit more lightweight. I like this idea, since much code of the > declaration parser is not very easy to > understand and I do feel that this could make some things easier. Its strongly inspired from Boost.Spirit, but I took all the thing we don't need out, prefering simplicity over flexibility (we can have only one scanner, but it's enough for us). I started experimental with after fixing a few parsing issues with class declaration. There so much things that could be optional and different but similar alternative that the code was getting fairly complicated. The parser would solve this if we could get the matched ranges out, as well as the matched alternative. Baptiste. |