Multiple keyword types in scanner
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   nikunj_raghuvanshi
Posted On:   Thursday, March 28, 2002 10:18 AM

Hi all, I am making a highlighting text editor which needs to give different colors to many different varieties of keywords. eg. A class should be given a different color and int a different one. The trouble is that the editor decides the color based on the scan code from the scanner. So I need different scan-codes for different subsets of the KEYWORD set. Since a keyword's scan value is itself obtained by looking at the keywords table which is AUTOMATICALLY generated from the literal strings used in the parser, I can't think of a way to accomplish the above task. Could someone please help. ANY suggestions are welcome...... thanks, -Nikunj    More>>


Hi all,

I am making a highlighting text editor which needs to give different colors to many different varieties of keywords. eg. A class should be given a different color and int a different one.
The trouble is that the editor decides the color based on the scan code from the scanner. So I need different scan-codes for different subsets of the KEYWORD set.
Since a keyword's scan value is itself obtained by looking at the keywords table which is AUTOMATICALLY generated from the literal strings used in the parser, I can't think of a way to accomplish the above task.

Could someone please help. ANY suggestions are welcome......

thanks,

-Nikunj

   <<Less

Re[2]: Multiple keyword types in scanner

Posted By:   Xiang_Sun  
Posted On:   Wednesday, May 22, 2002 05:05 AM

Can you send the sources to me? My E-mail is sunx_mail@yahoo.com.

Thanks

Re: Multiple keyword types in scanner

Posted By:   bogdan_mitu  
Posted On:   Tuesday, May 14, 2002 08:53 AM

I wrote a framework for using ANTLR lexers for syntax highlight and I already used it for several languages. I want to publish it, and even created a Sourceforge project, but never had the time to do it.


If you are interested, I can send you the sources together with some examples.




Regards,


Bogdan

Re: Multiple keyword types in scanner

Posted By:   Monty_Zukowski  
Posted On:   Friday, March 29, 2002 05:34 AM

Sounds like you need to share token type values for certain tokens. You can edit the YourLexerTokenTypes.txt file and then use the 'import' option in the lexer to read that file. Make the values whatever you want, I don't think ANTLR will complain.


Alternately you can write your own little parser which does nothing but assign a type based on what it is. So for instance:


primitiveTypes: ("int" | "float" )
{ ##.setType(2); }

It'll take a little more tweaking than that because I don't know exactly how you interface with your editor's API, but you get the idea.
About | Sitemap | Contact