How to "hide" portions of the character stream?

Questions on using RSyntaxTextArea should go here.

Moderator: robert

How to "hide" portions of the character stream?

Postby javagrendel » Wed Jun 12, 2013 8:07 pm


(I'm using v2.0.7 of RSyntaxTextArea)

I'm implementing a custom tokenizer and I want to add the ability to conditionally hide portions of text.
I can do this by conditionally switching states. Although the characters are hidden, RSyntaxTextArea still computes the number of lines based on what text *would* have been there - in other words, the text is not rendered, but there are large swathes of blank space displayed. I'd like to be able to just cause the hidden text to be "removed" from the character stream altogether.

Basically, in the language, there is a construct like

Code: Select all
            keyword(...);//note: content between ( and ) can include newlines.

I want to be able to hide everything but the semi-colon.

So in my flex definition, I have something like:

Code: Select all
<A> {
   ;              {
              /*end of state A*/
 //Other rules for state A
   ;              {
              /*end of state A_HIDDEN*/
   .              {/*Do nothing*/}
   "keyword" {
          if( hide() ) { yybegin(A_HIDDEN); }
          else { addToken(Token.RESERVED_WORD); yybegin(A); }

This does accomplish part of what I'm aiming for; however, I want the space represented by the hidden characters to be removed. I believe this is why I'm getting a null pointer exception when I click in the text area

Code: Select all
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at org.fife.ui.rsyntaxtextarea.WrappedSyntaxView$WrappedLine.viewToModel(
   at org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.viewToModel(
   at javax.swing.plaf.basic.BasicTextUI$RootView.viewToModel(
   at javax.swing.plaf.basic.BasicTextUI.viewToModel(
   at javax.swing.text.DefaultCaret.positionCaret(
   at javax.swing.text.DefaultCaret.adjustCaret(
   at javax.swing.text.DefaultCaret.adjustCaretAndFocus(
   at javax.swing.text.DefaultCaret.mousePressed(
   at org.fife.ui.rtextarea.ConfigurableCaret.mousePressed(
   at java.awt.AWTEventMulticaster.mousePressed(
Posts: 2
Joined: Wed Jun 12, 2013 7:29 pm

Re: How to "hide" portions of the character stream?

Postby robert » Mon Jun 17, 2013 2:12 am

I don't think this is possible with RSTA. It expects all text in the document to be represented with Tokens, otherwise you'll get exceptions in viewToModel() and/or modelToView(), as you've seen.
User avatar
Posts: 852
Joined: Sat May 10, 2008 5:16 pm

Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest