code completion help...
christopher j bottaro
cjb at cs.utexas.edu
Tue Feb 13 00:42:06 GMT 2001
accually, i've abandoned my old method (trying to work magic with regular
expressions). whoever posted about this topic before was right, if i really
want to do it right, i have to come up with a context free grammer for a
portion of c++. so now my strategy has changed. i am currently using flex++
and bison++. flex has made it easy to elegantly remove c comments and
strings broken up upon multiple lines. and combined with bison++, i wrote a
little grammer to match/parse method signatures and method bodies. weird
thing though...i can get bison to match and discard while loops of the form:
while (expression) codeblock
but for some reason it chokes on
while (identifier) codeblock
also, i think people want QT classes to work with code completion, and i
thought they would because i thought i saw somewhere in the ClassParser code
that QT and KDE classes were stored preparsed and loaded into the class store
or something.
the two current problems i'm facing now is getting bison++ to work with 2
lexers in the source. it doesn't like the other flexlexer that the
classparser uses. and also, my grammer has one shift/reduce conflict because
of the "dangling else" ambiguity. so far that hasn't caused any problems
though.
other than that, its pretty fast. it can scan a 3000 line source file
without making the cursor even flinch.
oh well, i'm still kinda feeling this out, i.e. whether or not it can be done
well pretty easily. hopefully i'll have a patch soon.
my initial goals are to get it working with the following deficiencies:
1) it completely relies on the classstore, if a class isn't parsed by the
classparser and put in the classstore, the code completion code isn't going
to find its methods/variables.
2) code completion will only work in the scope of methods defined outside
the class declaration (i.e. method definitions with :: in the signature)
3) it won't recognize scope inside a method, like variables declared inside
loops or if statements
thanks for the info and comments,
christopher
> > > Sounds good. I'd be very interesting in seeing what you have,
> > > especially if you are working on kdevelop1.4.
> >
> > so far the way it works is, it uses a QStack to push/pop curly braces to
> > find the begining and end lines of the method definition and the method
> > signature that the cursor is in. then when you hit a '.' or '->' it
> > grabs the last word you typed and method signature and looks up the class
> > that the method belongs to, then searches the class store for the class
> > to see if it has the "last word" was defined in it.
> >
> > so far, for the sake of wanting to get something working quickly, i broke
> > modularity all over the place i think. i made CEditWidget a friend of
> > KWriteDoc and KWriteView and vice versa. i made a few select class vars
> > public, etc. i'll change all that and make proper public interfaces once
> > its ready for presentation.
> >
> > there are two things that would help me out a lot.
> > 1) whats a regular expression definition that would match a c++ method
> > signature? i.e. match something like "QStringList*
> > CCodeCompletion::getMethods(const QString& aClassVar) {"
> > 2) some algorithm to convert someone's method signature they type in a
> > .cpp file to match the string required by
> > CParsedContainer::getMethodByNameAndArg(). i think i'll work on this
> > today, but once thats done, the code completion class should recognize
> > method params as well as class vars.
>
> I'll pass on this - hopefully someone else can give you pointers here
>
> jbb
-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«
More information about the KDevelop
mailing list