Skip to content
ConsoleMonster

API Reference

Class

RegexHighlighter

Namespace ConsoleMonster.Highlighting
Assembly ConsoleMonster
Implements
Modifiers sealed

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

Constructors

public RegexHighlighter(String name, Boolean ignoreCase = false) #

Creates an empty highlighter.

Parameters

name System.String requiredposition: 0
The language name.
ignoreCase System.Boolean = false optionalposition: 1
Whether the rules ignore case.

Methods

public RegexHighlighter Rule(String pattern, HighlightRole role) #
Returns: RegexHighlighter

Adds a rule. Patterns run in multiline mode (^ and $ match at line breaks); avoid nested quantifiers.

Parameters

pattern System.String requiredposition: 0
The pattern.
role ConsoleMonster.Highlighting.HighlightRole requiredposition: 1
The role of what it matches.

Returns

This highlighter.

public IReadOnlyList<HighlightToken> Tokenize(String text) #
Returns: IReadOnlyList<HighlightToken>

Tokenizes text.

Parameters

text System.String requiredposition: 0
The text (any line endings).

Returns

The tokens, in order and not overlapping.

public RegexHighlighter Words(HighlightRole role, params String[] words) #
Returns: RegexHighlighter

Adds a keyword rule: whole words from a list.

Parameters

role ConsoleMonster.Highlighting.HighlightRole requiredposition: 0
The role.
words System.String[] requiredposition: 1
The words.

Returns

This highlighter.

Properties

public String Name { get; } #

The language name, for example "json" (lower case).

public Boolean IgnoreCase { get; } #

Whether the rules ignore case.

public TimeSpan Timeout { get; set; } #

The time limit for one text (default 250 ms).