Re: [code] Fixes to Prolog and Logtalk lexers in 10.6

From: Mitchell <m.att.foicica.com>
Date: Thu, 19 Sep 2019 09:21:05 -0400 (EDT)

Hi Michael,

On Thu, 19 Sep 2019, Michael Richter wrote:

> And more problems with directives.
>
> In Prolog, a "directive" follows this pattern:
>
> <optional whitespace> ':-' <optional whitespace> <directive keyword>
>
> So if 'foo" is a directive keyword, it should be highlighted as a directive
> in all of the following:
>
> :-foo
> :- foo
> :-foo
> :- foo
>
> It should *not* be highlighted as a directive in the following:
>
> bar :- foo
> bar :-
> foo
>
> Everything I've tried to get conforming behaviour has failed. My latest
> attempt looks like this:
>
> lex:add_rule('directive', token(lexer.WHITESPACE, lexer.starts_line(S('
> \t')^0)) *
> token(lexer.OPERATOR, P':-') *
> token(lexer.WHITESPACE, S(' \t')^0) *
> token(lexer.PREPROCESSOR, P(word_match[[foo]])))
>
> This works with anything that has ':-' at the start of the line, but any
> interjected whitespace makes it fail. I'm at a loss for making it work as
> expected.

You'll need to put this as the very first rule, before the whitespace rule. Otherwise the whitespace rule will start matching and when it gets to your rule later, no dice.

Remember that lexers match rules in the order that you add them.

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 Thu 19 Sep 2019 - 09:21:05 EDT

This archive was generated by hypermail 2.2.0 : Fri 20 Sep 2019 - 06:31:13 EDT