CodeHighlighter
classin packageklyn.code.highlighters
public class CodeHighlighter extends Object implements SyntaxHighlighter
└ CodeHighlighter
All Implemented Interfaces: SyntaxHighlighter

Unified line-oriented syntax highlighter backed by any klyn.code.Tokenizer.

Converts lexical TokenSpan segments produced by klyn.code tokenizers into StyledSpan runs using AnsiSyntax styles, guaranteeing that the concatenated text of the returned spans always matches the input line.

Example
import klyn.code.highlighters

highlighter = CodeHighlighter(["if", "return"], "//")
spans = highlighter.highlight("return 42 // answer")
Inherited Properties
propertyInherited Properties from Object: type
Constructors
Modifier and Type Member Description
public CodeHighlighter
CodeHighlighter(keywords as ArrayList<String> = [], lineCommentToken as String = "", caseInsensitiveKeywords as Boolean = false)
Creates a CodeHighlighter with the given keyword list and line comment delimiter.
Methods
Modifier and Type Member Description
public static fromLanguage
fromLanguage(languageOrPath as String) as CodeHighlighter
Creates a CodeHighlighter for a language identifier or file path via LanguageRegistry.
public static fromTokenizer
fromTokenizer(tokenizer as Tokenizer) as CodeHighlighter
Creates a CodeHighlighter wrapping an existing klyn.code.Tokenizer.
public highlight
highlight(line as String) as List<StyledSpan>
Tokenizes and styles a single line of source code from the default LexicalState.NORMAL state.
public highlightWithState
highlightWithState(line as String, initialState as LexicalState = null) as List<StyledSpan>
Tokenizes and styles a single line of source code starting from initialState.
public static styleToken
styleToken(text as String, kind as TokenKind) as StyledSpan
Maps a TokenKind and token slice to its corresponding StyledSpan.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml