Class
RegexHighlighter
ConsoleMonster.Highlighting
A highlighter built from regular-expression rules, tried in order at each position (the first rule that matches wins). Use it to add a language without writing a lexer: Highlighters.Register(new RegexHighlighter("ini").Rule(@"^\s*;.*$", HighlightRole.Comment).Rule(...), "ini"). Matching has a time limit (default 250 ms per text); text after a timeout stays plain.
Inheritance
- object
- RegexHighlighter
Usage
Explore 2 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 2
- Method RegexHighlighter.Rule
- Method RegexHighlighter.Words
Constructors
public RegexHighlighter(string name, bool ignoreCase = false) #Creates an empty highlighter.
Parameters
- name string
- The language name.
- ignoreCase bool = false
- Whether the rules ignore case.
Methods
public RegexHighlighter Rule(string pattern, HighlightRole role) #Adds a rule. Patterns run in multiline mode (^ and $ match at line breaks); avoid nested quantifiers.
Parameters
- pattern string
- The pattern.
- role ConsoleMonster.Highlighting.HighlightRole
- The role of what it matches.
public IReadOnlyList<HighlightToken> Tokenize(string text) #Tokenizes text.
Parameters
- text string
- The text (any line endings).
public RegexHighlighter Words(HighlightRole role, params string[] words) #Adds a keyword rule: whole words from a list.
Parameters
- role ConsoleMonster.Highlighting.HighlightRole
- The role.
- words string[]
- The words.