Hi @ all,
Is it possible to create own syntax highlighting schemes for RSyntaxTextArea?
Greetz Taneeda
Moderator: robert

AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
atmf.putMapping("a key string denoting your style", "fully.qualified.classNameOfYourSyntaxStyle");
TokenMakerFactory.setDefaultInstance(atmf);
RSyntaxTextArea.setSyntaxEditingStyle("a key string denoting your style");
getTokenList(...)Method in the lexer file to keep track of the state transitions. For that it is best to define own tokens that start with the int value -1 and grow negatively to not clash with the ones defined in RSyntaxTextArea. Look at the XML Token Marker for a good example how and where to return own tokens and how to implement the transitions in the method mentioned above.
hookahey wrote:Hi
I have just gone through the process of creating an own syntax scheme, so I will tell shortly about my experience.
First have a look at JFlex http://jflex.de/manual.html and some tutorials http://www.javaranch.com/journal/2008/04/handling-file-formats-introducing-lexers.html and maybe http://bmrc.berkeley.edu/courseware/cs164/spring98/proj/jlex/tutorial.html to become accustomed to it. Luckily if the language is popular you may even find an already existing implementation for it in JFlex. Then you will only need to change it to return the RSyntaxTextArea Tokens.
Then have a look into the already provided examples that come with the source of RSyntaxTextArea in the ui.rsyntaxtextarea.modes package and take one of these as a start (copy over the java methods! and maybe some of the regex macros or just copy everything). With a quite symple language you just need to look at the predefined tokens in the Token class and play around to return the right ones for the elements in the language by returning them in the action associated with the regex for your language element. A more complicated syntax needs different states in JFlex and a logic to change from one to the other.
Next you need to translate the file with the help of JFlex to a Java file and follow the instructions in the class javadoc of the already existent syntax styles (e.g. remove the zzRefill() and yyreset() generated by JFlex). Don't forget to declare the right package in the lexer file. That's it, mostly. Now you can compile the file and test it by adding it to your RSyntaxTextArea with this code:
- Code: Select all
AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
atmf.putMapping("a key string denoting your style", "fully.qualified.classNameOfYourSyntaxStyle");
TokenMakerFactory.setDefaultInstance(atmf);
RSyntaxTextArea.setSyntaxEditingStyle("a key string denoting your style");
So far if you have a simple language! It gets a bit more complicated as soon as you want to use states with JFlex as then you have to change the switch in theMethod in the lexer file to keep track of the state transitions. For that it is best to define own tokens that start with the int value -1 and grow negatively to not clash with the ones defined in RSyntaxTextArea. Look at the XML Token Marker for a good example how and where to return own tokens and how to implement the transitions in the method mentioned above.
- Code: Select all
getTokenList(...)
The weird thing when using states in JFlex with RSyntaxTextArea is that there seems to not exist a BOL (beginning of line) and EOL (end of line) but EOF (end of file) is returned instead. Or then maybe I didn't get it right but that was a big annoyance because in JFlex normal mode it worked but not in RSyntaxTextArea.
Hope that helped
Hookahey
syntax keyword additions wrote:would i need to recreate a complete new language parser to add these keywords to those of the java parser
or by using the gui you intend to create to generate the java files could i just add the new keyword additions?
other than this one tiny limitation this component is a perfect solution for my needs.
The last post on this subject is recent, and i checked the blog, but has there been any additional coding that has gone it this effort?
Users browsing this forum: Google [Bot] and 0 guests