Re: [code] Lexer creation problem.

From: Michael Richter <ttmrichter.att.gmail.com>
Date: Sat, 7 Nov 2015 23:10:07 +0800

Is there any way to have a pattern that highlights two different parts and
ignores boilerplate? Maybe some trick with grammars and captures? I'm not
sure what the relationship between LPeg and the lexers is just yet.

As an example of what I mean:

In the string " :S(LABEL1)F(LABEL2)\n" I want LABEL1 and LABEL2
highlighted, but not ":S(", ")F(", or ")".

On 7 November 2015 at 22:59, Michael Richter <ttmrichter.att.gmail.com> wrote:

> Ah yes. Obvious in retrospect. I feel a bit dumb now. :) Thanks,
> Mitchell!
>
> On 7 November 2015 at 22:19, Mitchell <m.att.foicica.com> wrote:
>
>> Hi Michael,
>>
>> On Sat, 7 Nov 2015, Michael Richter wrote:
>>
>> lexer.word_match() acts in a way that's a bit puzzling to me and I'm
>>> trying
>>> to work out how to get around it. The issue is this: if I have a token
>>> defined as, say lexer.word_match({"NE"}), this works as expected. "NE"
>>> is
>>> properly highlighted in my file. FOO BAR NE BAZ has FOO, BAR, and BAZ
>>> not
>>> highlighted and NE highlighted. Perfect. Until I feed it FOO BAR FINE
>>> BAZ. Then NE is again highlighted. Which is really not how one
>>> generally
>>> wants for keyword highlighting.
>>>
>>> So ... how do I nicely have keywords that are highlighted only when
>>> they're
>>> standing alone?
>>>
>>
>> You need to have another rule that matches whole words, typically an
>> "identifier" rule. Make sure your keyword rule comes first though. That way
>> when a keyword doesn't match, your "identifer" rule will pick it up (e.g.
>> "FINE"), and there won't be a possibility for "NE" to be matched alone.
>>
>> 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.
>>
>>
>
>
> --
> "Perhaps people don't believe this, but throughout all of the discussions
> of entering China our focus has really been what's best for the Chinese
> people. It's not been about our revenue or profit or whatnot."
> --Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.
>

-- 
"Perhaps people don't believe this, but throughout all of the discussions
of entering China our focus has really been what's best for the Chinese
people. It's not been about our revenue or profit or whatnot."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.
-- 
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 Sat 07 Nov 2015 - 10:10:07 EST

This archive was generated by hypermail 2.2.0 : Sun 08 Nov 2015 - 06:27:32 EST