Hiding certain text

Post a reply

:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review

Expand view Topic review: Hiding certain text

Re: Hiding certain text

Post by 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.

Hiding certain text

Post by 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?