Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor SyntaxHighlighter class into one class for each language #256

Open
tvidvei opened this issue Feb 20, 2023 · 0 comments
Open

Refactor SyntaxHighlighter class into one class for each language #256

tvidvei opened this issue Feb 20, 2023 · 0 comments

Comments

@tvidvei
Copy link

tvidvei commented Feb 20, 2023

Hi

Thanks a lot for an excellent component! I have started to use it in one of my projects, and it works great! But I still have one wish - and proposal:

I want to implement syntax highlighting for additional languages, or modify the highlighting for some of the existing languages. The solution offered, as I understand it, is one of the following - provided that we will not modify FastColoredTextBox itself:
a) Use Language.Custom with a description file specifying the syntax highlighting
b) Write an event handler for the TextChanged event in FTBC with the new highlighting functionality. (See SimplestSyntaxHighlightingSample in Tester project.)

I think, however, that we could get more flexibility and a cleaner solution if we instead could define replacements for the built-in SyntaxHighlighter class, which contains all the syntax highlighting for all the buildt-in languages + the support for custom highlighting by means of a description file. We can achieve this while preserving all the present functionality in FastColoredTextBox (ftbc) by doing a refactoring on the SyntaxHighlighter class along these lines:

  1. Define an interface ISyntaxHighlighter which defines the functionality (methods an properties) to be delivered to the ftbc by a syntax highlighter implementation
  2. Define a base class SyntaxHighlighterBase : ISyntaxHighlighter which should contain the stuff common to all languages implemented in todays SyntaxHighlighter.
  3. Implement a subclass of SyntaxHighlighterBase for each language
  4. Define a SyntaxHighlighterAttribute with at least a Name property to give names (typically language names) to the ISyntaxHighlighter classes. (The Name attribute replaces todays enum Language in some respects, but has the advantage that new names can be added without needing to do modifications to ftbc.)
  5. Modify the functionality of the Language property in ftbc so that an instance of the right class of Syntaxhighlighters is chosen. It should be able to look for SyntaxHighlighters both in the application using the ftbc, an external assembly as specified, and of course among the built-in highlighters in FastColoredTextBox.

I have already implemented this functionality in my local ftbc repo, since I needed it in my project. But I wanted to present the idea and listen to the reactions before I make a pull request out of it.

Regards,
Tor Vidvei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant