Hiding certain text

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Hiding certain text

Postby javagrendel » Thu Jun 13, 2013 4:31 pm

Hi, first time poster. Just want to start off by saying I love this project - kudos, Robert!

I'm implementing a tokenizer for the Modelica language (http://www.modelica.org). One of the features I'd like to implement is to have a way to conditionally filter out the 'annotation' construct. Annotations in Modelica have the following basic structure:

keyword "annotation", followed by a bunch of stuff enclosed by brackets:

I would like to be able to filter out such constructs conditionally. Yes, I can (and will) implement folding for such annotations, but is there a way to completely suppress them?

One approach I've tried is to have a method in the token maker that returns a boolean indicating whether or not annotations should be "hidden". I've added two states M_ANNOT and M_ANNOT_HIDDEN, and I can conditionally switch to the appropriate state during tokenization.
I've attempted to define M_ANNOT_HIDDEN like so:
Code: Select all
    ;            { addToken(Token.SEPARATOR); yybegin(YYINITIAL); }
    .            { /*Do nothing*/ }

There is also a set of rules for <M_ANNOT>, one of which is the same as in M_ANNOT_HIDDEN to mark the end of the annotation, which is a semi-colon.
In YYINITIAL, I switch to one of the two annotation states conditionally:

Code: Select all
        "annotation"     {
                  if( hideAnnotations() )  yybegin(M_ANNOT_HIDDEN);
                  else {

This works, insofar as not rendering the content is concerned - instead, I get a whole bunch of blank space. Also, there are exceptions if I click with the mouse anywhere in the text area.

Is it possible to filter out parts of the source code?
Posts: 2
Joined: Wed Jun 12, 2013 7:29 pm

Re: Hiding certain text

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

I don't think this is possible; as you've seen, simply ignoring text in the document will cause exceptions in viewToModel()/modelToView() calls. I do not know of a way around this, unfortunately.
User avatar
Posts: 760
Joined: Sat May 10, 2008 5:16 pm

Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests