Is it possible to add a new reserved word for a java syntax?

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Is it possible to add a new reserved word for a java syntax?

Postby Gilberto... » Sun Dec 23, 2012 3:34 am

I want to add a few reserved words like:
    type, then, func, proc
, in my project using rSyntaxTextArea, is that possible?
Gilberto...
 

Re: Is it possible to add a new reserved word for a java syn

Postby robert » Mon Dec 24, 2012 3:10 pm

There is unfortunately no way out-of-the-box to do this. There are two approaches you can take:

  • If all you literally need is to add keywords, but all other syntax is still Java syntax, you can try doing what I suggest in this post in another thread. For Java, you'd have to override a different addToken() method:

java code:

public void addToken(char[] array, int start, int end, int tokenType,
int startOffset, boolean hyperlink) {
if (tokenType==Token.IDENTIFIER) { // Assuming all of your new highlighted words are currently "identifiers"
int value = myWordsToHighlight.get(array, start, end);
if (value != -1) {
tokenType = value;
}
}
super.addToken(array, start,end, tokenType, startOffset, hyperlink);
}


  • You can use TokenMakerMakr to create your own TokenMaker class for your language. You can easily recreate the basic syntax rules of a simpler language like Java, and define your own keywords. As discussed in that blog post though, you'll have to check this out from the trunk of SVN; there's no actual download for it currently.

Good luck!
User avatar
robert
 
Posts: 786
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron