Problem using custom configuration files

Topics: User Forum
Dec 22, 2008 at 8:07 AM
I followed the example and it seemed to work. But when I changed the name of the pascal.xml file to powershell.xml, changed the Name= to powershell, and the language to powershell in the ConfigurationManager, only the style (the CHARACTER) was applied. Seems to me that the lexer part isn't really working unless there's a built-in lexer for the language named in the file. Also, with the language still at pascal, using LineCommentPrefix="#" (stolen from the python.xml in the source tree) doesn't seem to work. I really want to use this control, but without working general examples it's kinda hard. This example looked pretty good, but once I tinkered with it it seemed to break. Could be that I'm doing something wrong, and I hope so, but I've tried to get a simple example working for several hours now.
Developer
Jan 5, 2009 at 1:41 PM
I don't know what your exactly want to do but I hope I can help a bit.

In the ConfigurationFile you must choose a build-In Lexer or write your own.
The you have to create a ConfigFile like that:

<ScintillaNET>
  <Language Name="Powershell">
    [...]
    <Lexer LexerName="pascal" LineCommentPrefix="#" StreamCommentPrefix="/*" StreamCommentSuffix="*/">
     [... Keyword ...]
    </Lexer>
    <Styles>
      <Style Name="DOCUMENT_DEFAULT" Bold="False" Italic="false" Underline="false" Font="Courier New" Size="10" ForeColor="-16777216" BackColor=""/>
      [... more styles supported by the lexer (look at the ..\Configuration\Builtin\LexerStyleNames\<lexername>.txt in  ...]
    </Styles>
  </Language>
</ScintillaNET>
Feb 25, 2009 at 6:54 PM
I'm kinda stuck on the same thing. I can't get my own Lexer to work. What am I doin wrong?

That is the code in the Form constructor.
            sciControl1.ConfigurationManager.IsUserEnabled = true;
            sciControl1.ConfigurationManager.CustomLocation = "sci_default.xml";
            sciControl1.ConfigurationManager.Language = "CSHARP";

            sciControl1.ConfigurationManager.Configure();

            sciControl1.Lexing.Lexer = Lexer.Cpp;

            sciControl1.Styles.LineNumber.BackColor = Color.White;
            sciControl1.Styles.LineNumber.ForeColor = Color.YellowGreen;
            sciControl1.Margins.Margin0.Width = 35;

            sciControl1.Text =
            "for (int i = 0; i < 0x00FF; i++)\r\n" +
            "{\r\n" +
            "\tint dense = i / 20 * i / 3;\r\n" +
            "}";

Here the lexer/language
<?xml version="1.0" encoding="utf-8" ?>
<ScintillaNET>
 
  <Language Name="default">
    <Styles>
      <Style Name="Default" FontName="Courier New" Size="10"/>
    </Styles>
  </Language>
 
  <Language Name="CSHARP">
    <AutoComplete FillUpCharacters=".([" SingleLineAccept="True" IsCaseSensitive="False">
      <List>
        abstract as base break case catch checked continue default delegate do else event explicit extern
        false finally fixed for foreach goto if implicit in interface internal is lock Namespace new null
        object operator out override params private protected public readonly ref return sealed sizeof
        stackalloc switch this throw true try typeof unchecked unsafe using virtual while bool byte char
        class const decimal double enum float int long sbyte short static string struct uint ulong ushort void
      </List>
    </AutoComplete>

    <Indentation TabWidth="4"  UseTabs="false"/>

    <Lexer LexerName="CSHARP" LineCommentPrefix="//" StreamCommentPrefix="/*" StreamCommentSuffix="*/" >
      <Keywords List="0" Inherit="False">
        abstract as base break case catch checked continue default delegate do else event explicit extern
        false finally fixed for foreach goto if implicit in interface internal is lock Namespace new null
        object operator out override params private protected public readonly ref return sealed sizeof
        stackalloc switch this throw true try typeof unchecked unsafe using virtual while
      </Keywords>
      <Keywords List="1" Inherit="False">
        bool byte char class const decimal double enum float int long sbyte
        short static string struct uint ulong ushort void
      </Keywords>
    </Lexer>

    <Styles>
      <style Name="COMMENT" BackColor="White" ForeColor="Green" />
      <style Name="COMMENTLINE" BackColor="White" ForeColor="Green" />
      <style Name="COMMENTDOC" BackColor="White" ForeColor="Green" />
      <style Name="NUMBER" BackColor="White" ForeColor="Purple" />
      <style Name="WORD" BackColor="White" ForeColor="Blue" />
      <style Name="STRING" BackColor="White" ForeColor="Teal" />
      <style Name="CHARACTER" BackColor="White" ForeColor="Teal" />
      <style Name="UUID" BackColor="White" ForeColor="Indigo" />
      <style Name="PREPROCESSOR" BackColor="White" ForeColor="OrangeRed" />
      <style Name="OPERATOR" BackColor="White" ForeColor="Gray" />
      <style Name="IDENTIFIER" BackColor="White" ForeColor="Black" />
      <style Name="STRINGEOL" BackColor="White" ForeColor="Black" />
      <style Name="VERBATIM" BackColor="White" ForeColor="Black" />
      <style Name="REGEX" BackColor="White" ForeColor="DarkViolet" />
      <style Name="COMMENTLINEDOC" BackColor="White" ForeColor="Green" />
      <style Name="WORD2" BackColor="White" ForeColor="Navy" />
      <style Name="COMMENTDOCKEYWORD" BackColor="White" ForeColor="Green" />
      <style Name="COMMENTDOCKEYWORDERROR" BackColor="White" ForeColor="Green" />
      <style Name="GLOBALCLASS" BackColor="White" ForeColor="Blue" />
      <!-- Default -->
      <style Name="STANDARD" BackColor="White" ForeColor="Black" />
      <style Name="DEFAULT" BackColor="White" ForeColor="Black" />
      <!-- Braces -->
      <style Name="BRACELIGHT" BackColor="Lavender" ForeColor="Blue" />
      <style Name="BRACEBAD" BackColor="MistyRose" ForeColor="Red" />
    </Styles>

  </Language>
</ScintillaNET>
Developer
Mar 5, 2009 at 8:17 AM
Hi KainPlan,

I'm not sure if your XML is right, have a look at the two cpp.txt File in the Configuration Folder.
There a the possible styles. And you can use the cpp Lexer for C#.

I hope this can help a little bit:

Configuration config = new Configuration("FileName", "CSHARP", true);
this.sciDocument.ConfigurationManager.Configure(config);

And the Configfile could look like this:

<?xml version="1.0" encoding="utf-8" ?>
<ScintillaNET>
  <Language Name="CSHARP">
    <Indentation TabWidth="8" SmartIndentType="cpp" />
    <AutoComplete FillUpCharacters=".([" SingleLineAccept="True" IsCaseSensitive="False">
      <List>
        abstract as base break case catch checked continue default delegate do else event explicit extern
        false finally fixed for foreach goto if implicit in interface internal is lock Namespace new null
        object operator out override params private protected public readonly ref return sealed sizeof
        stackalloc switch this throw true try typeof unchecked unsafe using virtual while bool byte char
        class const decimal double enum float int long sbyte short static string struct uint ulong ushort void
      </List>
    </AutoComplete>
    <Lexer LexerName="cpp" LineCommentPrefix="//" StreamCommentPrefix="/*" StreamCommentSuffix="*/">
      <Keywords List="0" Inherit="False">
        abstract as base break case catch checked continue default delegate do else event explicit extern
        false finally fixed for foreach goto if implicit in interface internal is lock Namespace new null
        object operator out override params private protected public readonly ref return sealed sizeof
        stackalloc switch this throw true try typeof unchecked unsafe using virtual while
      </Keywords>
      <Keywords List="1" Inherit="False">
        bool byte char class const decimal double enum float int long sbyte
        short static string struct uint ulong ushort void
      </Keywords>
    </Lexer>
    <Commands Inherit="True">
      <Binding Key="Q" Modifier="Control" Command="ToggleLineComment" ReplaceCurrent="True">
        <!--Strg + Q um einen Zeilenkommentar zu setzen bzw. zuentfernen-->
      </Binding>
      <Binding Key="Q" Modifier="Shift Control" Command="StreamComment" ReplaceCurrent="True">
        <!--Strg + Shift + Q um einen Blockkommentar zu setzten /* */-->
      </Binding>
    </Commands>
    <Styles>
      <Style Name="DOCUMENT_DEFAULT" Bold="False" Italic="false" Underline="false" Font="Courier New" Size="10" ForeColor="-16777216" BackColor="">
        <!--DOCUMENT_DEFAULT Style-->
      </Style>
      <Style Name="WORD" Bold="True" Italic="False" Underline="False" Font="Courier New" Size="10" ForeColor="-16776961" BackColor="16777215">
        <!--WORD Style-->
      </Style>
      <Style Name="WORD2" Bold="True" Italic="false" Underline="false" Font="Courier New" Size="10" ForeColor="-16744320" BackColor="">
        <!--WORD2 Style-->
      </Style>
      <Style Name="COMMENT" Bold="False" Italic="false" Underline="false" Font="Courier New" Size="9" ForeColor="-16744448" BackColor="">
        <!--COMMENT Style-->
      </Style>
      <Style Name="COMMENTLINE" Bold="False" Italic="false" Underline="false" Font="Courier New" Size="10" ForeColor="-16744448" BackColor="">
        <!--COMMENTLINE Style-->
      </Style>
      <Style Name="STRING" Bold="False" Italic="false" Underline="false" Font="Courier New" Size="10" ForeColor="-65536" BackColor="">
        <!--STRING Style-->
      </Style>
      <Style Name="OPERATOR" Bold="True" Italic="false" Underline="false" Font="Courier New" Size="9" ForeColor="-15132304" BackColor="">
        <!--OPERATOR Style-->
      </Style>
      <Style Name="NUMBER" Bold="False" Italic="false" Underline="false" Font="Courier New" Size="9" ForeColor="-23296" BackColor="">
        <!--NUMBER Style-->
      </Style>
    </Styles>
  </Language>
</ScintillaNET>

Good Luck
Klingel

P.S.: bist du deutscher? xD