Hello everybody,

The following code highlights prolog code statically making use of
PPTextHighlighter, I leave the code to share with the community since it
might be of help to someone else.

Could someone point out how can this be converted to its dynamic
counterpart?; The keystroke handler for GLMTextPresentation and what model
is currently being used for instance to highlight smalltalk code would be
very much appreciated.

>From http://bergel.eu/download/Dyla2010/dyla10_submission_4.pdf I know that
it might be neccesary a fuzzy highlighter as is written at the end of the
code, and it is probably the right object to use but I can not figure out
where to plug it.

Thank beforehand,

Jesus

| text textRenderer textShower |

text := 'p(Q,R):-q(R), unify_st(X, smalltalk_code), r(T).
q(Q):-d(R).
q(Q).'.

textRenderer := [
PPTextHighlighter new
parser: PPPrologParser new;
color: 'small_atom' with: Color blue muchDarker;
bold: 'small_atom';
color: 'unify_st' with: Color green muchDarker;
bold: 'unify_st';
color: 'string' with: Color gray muchDarker;
color: 'number' with: Color gray muchDarker;
color: 'boolean' with: Color gray muchDarker;
highlight: text asText.
].
"                __
                   |
         <Renders IN>
   |
  W
GLMTextPresentation
    |
   <Renders IN>
   |
 W
GLMMorphicRenderer
"

textShower := GLMMorphicRenderer new.
(textShower open: (
GLMTextPresentation new display: textRenderer; renderGlamorouslyOn:
textShower; yourself )) window title: 'Prolog Editor'.



"Here I created a highlighter through the transform method of the grammar"

grammar := PPPrologParser new.
highlighter := grammar transform: [ :parser |
Transcript show: parser.
parser class = TokenParser
ifTrue: [ parser ==> [ :token |
textShower model highlight: token style range: token interval ] ]
ifFalse: [ parser ] ].

text := 'p(Q,R):-q(R), unify_st(X, smalltalk_code), r(T).
q(Q):-d(R).
q(Q).'.

pp := highlighter parse: text asText.

Reply via email to