more code completion fun!

Roland Krause rokrau at yahoo.com
Fri Mar 9 05:12:03 GMT 2001


I've got a question, this maybe a stupid one. 

This is all to parse the file the user is currently working in, right?

So the goal is to find out what the user is trying to do. Then what
happens if the current file is full of nonsense e.g. 
I start a method definition:

namespace mynamespace {

myclass::mymethod (int myarg1, int myarg2) {
   myarg2=myarg1-3


and i forget to close the damn function scope and maybe also forget the
semicolon in the function or make other errors.

Then i go on with next method

myclass::mymethod2 (int myarg1, int myarg2) {
   myarg2=myarg1;

  
}


Will this all then work in myclass::mymethod2 at all? Will mymethod1
also be available for code completion already? 

Roland

--- christopher j bottaro <cjb at cs.utexas.edu> wrote:
> phew, after attempting it with regular expressions, then moving on to
> lex and 
> yacc, i've finally gotten somewhere after ditching all that and
> writing an 
> LL(k) grammer for use with ANTLR 2.0.  so far the grammer can parse
> method 
> definitions include parameter and local variable declarations.  the
> grammer 
> recognizes scope and parses to remember the scope where the var was
> defined.  
> for example...
> 
> virtual const char* SomeClass::AnotherClass::AMethod(int& x, char y)
> {
> 
> 	// scope 1a
> 	{
> 		QString var;
> 	}
> 
> 	// scope 1b
> 	{
> 		QPoint var;
> 		
> 		// scope 2a
> 		{
> 			QRect var;
> 		}
> 	}
> 
> }
> 
> the method will be parsed, including its return type, qualified name,
> and 
> parameters.  then codeblocks will be parsed including their begin and
> end 
> lines and all variable declarations enclosed in them will be parsed.
> 
> after the parsing, it shouldn't be too hard to determine the line
> number that 
> the cursor is currently on, determine what scope that falls in, then
> search 
> the QDict of that scope for what ever variable you want completion
> for, get 
> its type, look up its type in KDevelop's classstore, then populate a
> listbox 
> full of members.
> 
> so far i've just tested it by building a parser outta the grammer and
> running 
> it in a console program on kwview.cpp which is 70k.  it parses and
> prints out 
> the results to cout in less than a second on a p2 600.
> 
> i suppose the real challenge is resolving function calls and pointer
> derefs?  
> anyone have any suggestions?
> 
> also, when i compile my grammer, i get like over a page of
> non-determinisms, 
> but they don't seem to matter at all...  here are some of the ones
> that 
> bother me...
> 
> primary_expr
> 	:	(scope)? IDENTIFIER
> 	|	INTEGER (DOT INTEGER)?  // non-determinism here
> 	|	STRING_LIT
> 	|	CHAR_LIT
> 	|	OP expression CP
> 	;
> 
> // this rule is fine...
> postfix_expr
> 	:	primary_expr	(	(OP (arg_expr_list)? CP)
> 				|	(OSB expression CSB)
> 				)?
> 				(	((DOT|PTR) postfix_expr)
> 				)?
> 	;
> 
> // this whole thing apperent causes a lot of non determinisms
> unary_expr
> 	:	(unary_op|INCR|DECR)* postfix_expr
> 	|	"sizeof" OP returntype CP
> 	|	"sizeof" postfix_expr
> 	;
> 
> cast_expr
> 	:	(OP returntype CP)? unary_expr  // non determinism here
> 	;
> 
> anyways, antlr is great, maybe the class parser should be rewritten
> using it. 
>  its cool how rules can have return types and take arguments and
> throw 
> exceptions and such.  its a lot more pleasureable writing an LL(k)
> grammer 
> also.  god, i wish i hadn't have dropped my automata theory class.
> 
> tell me what you all think...potentially useful?
> 
> christopher
> 
> -
> to unsubscribe from this list send an email to
> kdevelop-request at kdevelop.org with the following body:
> unsubscribe »your-email-address«


=====
--
Roland Krause
In the garage of life there are mechanics and 
there are drivers. Mechanics wanted!

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

-
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