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

Hi,

(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*/
             addToken(Token.RESERVED_WORD_2);
             yybegin(YYINITIAL);
   }
 //Other rules for state A
}
<A_HIDDEN> {
   ;              {
              /*end of state A_HIDDEN*/
             addToken(Token.RESERVED_WORD_2);
             yybegin(YYINITIAL);
   }
   .              {/*Do nothing*/}
}
<YYINITIAL>{
   "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(WrappedSyntaxView.java:1310)
   at org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.viewToModel(WrappedSyntaxView.java:1007)
   at javax.swing.plaf.basic.BasicTextUI$RootView.viewToModel(BasicTextUI.java:1540)
   at javax.swing.plaf.basic.BasicTextUI.viewToModel(BasicTextUI.java:1089)
   at javax.swing.text.DefaultCaret.positionCaret(DefaultCaret.java:290)
   at javax.swing.text.DefaultCaret.adjustCaret(DefaultCaret.java:495)
   at javax.swing.text.DefaultCaret.adjustCaretAndFocus(DefaultCaret.java:483)
   at javax.swing.text.DefaultCaret.mousePressed(DefaultCaret.java:473)
   at org.fife.ui.rtextarea.ConfigurableCaret.mousePressed(ConfigurableCaret.java:371)
   at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)
javagrendel
 
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
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 5 guests

cron