TokenSpan
classin packageklyn.code
public class TokenSpan extends Object
└ TokenSpan

Represents a half-open token range [start, end) within a single source line.

TokenSpan avoids allocating substring copies during line-by-line syntax highlighting. Callers can extract the underlying text on demand via slice(line).

import klyn.code

span = TokenSpan(0, 6, TokenKind.KEYWORD)
assert span.length == 6
assert span.slice("public class Foo:") == "public"
Properties
Modifier and Type Member Description
public readonly property end
end as Long
Zero-based exclusive end offset within the line.
public readonly property kind
kind as TokenKind
Lexical classification of this span.
public readonly property length
length as Long
Number of characters covered by this span (end - start).
public readonly property start
start as Long
Zero-based inclusive start offset within the line.
Inherited Properties
propertyInherited Properties from Object: type
Constructors
Modifier and Type Member Description
public TokenSpan
TokenSpan(start as Long, end as Long, kind as TokenKind)
Constructs a token span covering [start, end) with the given TokenKind.
Methods
Modifier and Type Member Description
public contains
contains(column as Long) as Boolean
Checks whether a zero-based column offset falls within [start, end).
public slice
slice(line as String) as String
Extracts the substring covered by this span from line.
public override toString
toString() as String
Returns a human-readable representation of this span.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml