Create Language with object model

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by tobias weltner
Avatar
So far, I have been using language xml files to define the language.
Now, I wanted to create a language completely from scratch during run-time but failed.
I instantiated a new SyntaxLanguage object and passed it a key as argument.
I was then trying to assing this object to document.language but got an error message regarding a "missing key".
Do you have any code snippets that demonstrate what I want to do?

Comments (2)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Here's our code for the PlainText language:
public static SyntaxLanguage PlainText {
    get {
        // Create a language
        SyntaxLanguage plainTextLanguage = new SyntaxLanguage("Plain Text", false);
        plainTextLanguage.ExampleText = "Plain text with\r\n2 lines.";

        // Get the default style
        HighlightingStyle defaultHighlightingStyle = plainTextLanguage.HighlightingStyles["DefaultStyle"];

        // Create the default state
        LexicalState lexicalState = new LexicalState("DefaultState");
        lexicalState.DefaultHighlightingStyle = defaultHighlightingStyle;
        lexicalState.LexicalPatternGroups.Add(new LexicalPatternGroup(LexicalPatternType.Regex, "WhitespaceToken", defaultHighlightingStyle, "{WhitespaceMacro}+"));
        lexicalState.LexicalPatternGroups[lexicalState.LexicalPatternGroups.Count - 1].IsWhitespace = true;
        lexicalState.LexicalPatternGroups.Add(new LexicalPatternGroup(LexicalPatternType.Regex, "LineTerminatorToken", defaultHighlightingStyle, "{LineTerminatorMacro}+"));
        lexicalState.LexicalPatternGroups[lexicalState.LexicalPatternGroups.Count - 1].IsWhitespace = true;
        lexicalState.LexicalPatternGroups.Add(new LexicalPatternGroup(LexicalPatternType.Regex, "IdentifierToken", defaultHighlightingStyle, "{AlphaMacro}({WordMacro})*"));
        lexicalState.LexicalPatternGroups.Add(new LexicalPatternGroup(LexicalPatternType.Regex, "NumberToken", defaultHighlightingStyle, "{DigitMacro}+", "{NonWordMacro}"));

        // Add the states
        plainTextLanguage.LexicalStates.Add(lexicalState);
        plainTextLanguage.DefaultLexicalState = lexicalState;

        // Mark that updating is complete
        plainTextLanguage.IsUpdating = false;

        return plainTextLanguage;
    }
}


Actipro Software Support

Posted 14 years ago by tobias weltner
Avatar
Thanks so much!
Actually, I think I did everything like that myself, but I was missing the isUpdating=false...
The latest build of this product (v2018.1 build 0341) was released 7 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.