Re: [code] [textadept] Intermixed highlighting

From: Mitchell <m.att.foicica.com>
Date: Tue, 5 May 2015 15:35:05 -0400 (EDT)

Hi Toba,

On Tue, 5 May 2015, Balint Torok wrote:

> Hello,
>
> I have a text which has blocks that start with the @@@block marker, and end
> with the block@@@ marker. Within these blocks I have certain markers like
> @@@.C_like_identifier. For exampel
>
> some text...
> @@@block
> in the block
> maker in the block @@@.mark1
> more text
> @@@.marker2
> block@@@
>
> I have created a lexer that highlights the block start/end markers and the
> block content with this rule
>
> local block = token('block', '@@@block' * (l.any - 'code@@@'))^0 * P('block@
> @@')^-1)
>
> Is it possible to highlight the marks within the blocks with some other
> color? I have tried to modify the pattern above, but without any success. I
> mostly run into some kind of an infinite loop that blocked textadept so I
> had to kill the process.

This is tricky and the solution depends on how accurate you want the lexer
to be. If you absolutely must have '@@@something' sequences only highlight
within '@@@block' and 'block@@@' delimiters, you should use embedded
lexers. If you're willing to overlook that and highlight '@@@something'
anywhere, then you should just highlight '@@@block' and 'block@@@'
separately.

For embedded lexers, you'd have something like this (untested):

   -- embedded lexer
   local M = {_NAME = '...'}
   ...
   local marker = token('marker', '@@@' * ...)
   ...
   M._rules = {
     ...
     {'marker', marker},
     ...
   }

   -- parent lexer
   local embedded = lexer.load('...')
   local start_block = token('block', '@@@block')
   local end_block = token('block', 'block@@@')
   lexer.embed_lexer(M, embedded, start_block, end_block)

For the simple way:

   local start_block = token('block', '@@@block')
   local end_block = token('block', 'block@@@')
   local marker = token('marker', '@@@' * ...)
   ...
   M._rules = {
     ...
     {'block', start_block + end_block},
     {'marker', marker},
     ...
   }

I hope this helps.

Cheers,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Tue 05 May 2015 - 15:35:05 EDT

This archive was generated by hypermail 2.2.0 : Wed 06 May 2015 - 06:39:35 EDT