[prev in list] [next in list] [prev in thread] [next in thread] 

List:       vim
Subject:    Sybtax rules (was RE: Syntax highlighting for numbers)
From:       "Keith Roberts" <kroberts () wpas-inc ! com>
Date:       2003-11-26 17:54:40
[Download RAW message or body]

I changed the topic, so as not to obfuscate the OP's discussion.  Sorry for
including everything, but I think it helps with clarity in this case.

>-----Original Message-----
>From: Charles E. Campbell, Jr. [mailto:drchip@campbellfamily.biz]
>Sent: Tuesday, November 25, 2003 11:23 AM
>To: vim@vim.org
>Subject: Re: Syntax highlighting for numbers
>
>Charles Campbell replied:
> >There are three forms of priority:
> >   1) later syntax matches/regions take priority over earlier ones
> >      syn match One "one"
> >      syn match Two "one"
> >      Two takes priority over One.
> >
> >   2) keywords take priority over matches and regions
> >      syn keyword One "one"
> >      syn match   Two "one"
> >      One takes priority over Two.
> >
> >   3) during syntax highlighting analysis, earlier matches
> >      effectively take priority over later ones.
> >      syn match One   "bone"
> >      syn match Two   "one"
> >      syn match Three "ome"
> >      The one bone is home.
> >          111 2222     333
> >
> >      Note that by rule 2, Two has priority when highlighting the "one"
>in
> >      "bone", but by rule 3 Two has priority.  Rule 3 wins.
>
>
>Keith Roberts replied:
> >Uh ... Dr. C ... I don't understand this paragraph at all.  You say that
> >'Two' has priority in both cases, yet you use the word 'but', as if they
> >should be different.  What are you trying to demonstrate here?
>
> >      Note that by rule 2, Two has priority when highlighting the "one"
>in
> >      "bone", but by rule 3 One has priority.  Rule 3 wins.
>Sorry -----------------------^^^


Yes, I figured that was a typo.  But I still don't understand the 'Rule 3
wins.' comment ... are you positing that all three of these sets of 'syn'
statements are in the same syntax file at the same time, and in that order?
If so, I agree, but I thought these were three separate cases.


>Imagine the highlighter as a state machine.  It starts off with no
>highlighting.
>Now it examines the situation at the first character:
>
>    Search keyword tables for a match, starting with the most recent table.
>    If there's a keyword match, recognize that keyword's highlighting.
>    (thereby implementing keywords-have-priority)
>
>    If no keyword table matched, consider all regions' start patterns and
>    match patterns, starting with the most recent such pattern and
>considering
>    successively older patterns (thereby implementing "more recent has
>priority").
>
>    In either the keyword case or the match/region-start case, restrict the
>    number of patterns under consideration for matching inside the
>highlighting
>    group that was found to match to those that are contained.  Thus one
>may
>    highlight things inside things.
>
>   Repeat.


This is very good info!  I created a syntax file for the funky language I
[have to] use (from c.vim), and it works pretty well, but I had to do some
fiddling with the order of definitions, and didn't really understand why
things did or didn't work one way or another.  Now when I go back to add
structures (regions) it will be clearer.


> >Moreover, rules 1 and 3 seems to be diametrically opposite; that requires
> >some explication.
>
>Look carefully: rule one involves two matches, rule two involves a match
>vs a keyword list.  Keywords *always* have priority over matches and
>regions.
>
>Rule 3 involves what-syntax-do-we-look-for-and-when.  Thus "bone" was
>recognized as having Three highlighting.

Note that in the example you underlined "bone" with 2, not 1.  I can't come
up with any way to associate the #2 with "bone".

>Once recognition as One is
>determined, only those groups contained inside One have a shot at being
>recognized inside One.  There are no such groups according to the syntax
>above; in particular, highlighting Two is not contained inside One.  Thus
>the substring "one" in "bone" is not recognized as having Two highlighting.

Understood.  All this makes sense.

>Following "bone" is a blank, at which point One is done and no highlighting
>rules apply.  Likewise, "is " is also not recognized by any of the rules.
>The "h" in "home" also does not match any rules, but the subsequent string
>"ome" is recognized by highlighting #Three.
>
>Regards,
>Chip Campbell

Here's case 3) again, but I've added letters to refer to each line
separately and unambiguously:

> >   3) during syntax highlighting analysis, earlier matches
> >      effectively take priority over later ones.
> >      a) syn match One   "bone"
> >      b) syn match Two   "one"
> >      c) syn match Three "ome"
> >      The one bone is home.
> >          111 2222     333

Here is the way I would interpret the rules as applied to said sentence.

> >      The one bone is home.
> >          bbb aaaa     ccc

Am I correct?  Or perhaps you were trying to make a different point
entirely, which I have missed?




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic