Re: [code] [textadept] Intermixed highlighting

From: Balint Torok <12toba.att.gmail.com>
Date: Tue, 5 May 2015 23:51:12 +0200

Hi Mitchell,

Thank you for such a fast response :)

I would be quite happy with your second proposal, that is to highlight the
@@@.something markers anywhere in the file. Trying out your solution made
me realize that I wasn't precise enough. It is not just the block start and
end markers that I want to highlight, but the whole block; the block
start/end markers and the text between these markers. And then I would like
to highlight the @@@.something with some other color may it be inside or
outside of a block.
Sort of like having the whole block (the markers and the content) in blue,
but the @@@.something would be red no matter if it is inside or outside of
a block.
Can this be done?

Kind Regards,
Toba

On Tue, May 5, 2015 at 9:35 PM, Mitchell <m.att.foicica.com> wrote:

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

-- 
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 - 17:51:12 EDT

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