t-edson / SynFacilSyn

Scriptable Highlighter for the SynEdit Component of Lazarus
GNU General Public License v2.0
34 stars 16 forks source link

I need c lexer tips from you #35

Closed tigrazone closed 1 year ago

tigrazone commented 1 year ago

Hello. How to do c highlighter which:

  1. processing string in #include "stdio.h" or #include as string colored by string colors - i.e. between "" and <>?
  2. how to work with #if #else #endif and try catch finally blocks for highlight these keywords and use these keywords for folding and highlight as block elements?

Thank you at all

t-edson commented 1 year ago

Hi. You can define delimiter " for strings and every text between " and " will be highlighted. You can define strings with "<" and ">" as delimiters too. However it will make every "<" char start a string and will fail in cases like "if (x<y) { }". The easy way is to highlight all the line #include "stdio.h" or #include , with something like:

  <Attribute Name="Directive" ForeCol="#FE2EF7"> </Attribute>
  <Token Start="#" End="" Attribute='DIRECTIVE'> </Token>

About #if #else #endif, you can define the folding using two sections inside a block:

  <Block Start="#if" End="#endif" Parent="Main">
    <Section Start="#if" FirstSec="True"> </Section>
    <Section Start="#else"> </Section>
  </Block>