public class LexicalState extends Object
Immutable lexical state carried from the end of one source line to the start of the next.
LexicalState tracks open multi-line comments, multi-line string literals, string interpolation brace depth (f"{...}"), contextual Klyn query: block indentation, and Markdown fenced code block languages.
Normal lines share the pre-allocated LexicalState.NORMAL singleton to avoid heap allocations during incremental document scanning.
import klyn.code state = LexicalState.NORMAL assert state.isNormal() assert not state.inBlockComment()
| Modifier and Type | Member | Description |
|---|---|---|
| public static readonly | NORMALNORMAL as LexicalState = LexicalState(LexicalMode.NORMAL, "", false, false, 0, -1, "") |
Shared singleton representing the default top-level code state. |
| Modifier and Type | Member | Description |
|---|---|---|
| public readonly property | delimiterdelimiter as String |
Closing delimiter expected to exit the current multi-line mode. |
| public readonly property | fenceLanguagefenceLanguage as String |
Language identifier of the active Markdown fenced code block. |
| public readonly property | interpolationDepthinterpolationDepth as Int |
Current nesting depth of {...} expressions inside an interpolated multi-line string. |
| public readonly property | isFormattedisFormatted as Boolean |
Indicates whether the active multi-line string supports {...} interpolation. |
| public readonly property | isRawisRaw as Boolean |
Indicates whether the active multi-line string is a raw literal. |
| public readonly property | modemode as LexicalMode |
Active multi-line lexical mode. |
| public readonly property | queryIndentqueryIndent as Int |
Indentation column of the active Klyn query: block, or -1 when outside a query block. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | LexicalStateLexicalState(
mode as LexicalMode = LexicalMode.NORMAL,
delimiter as String = "",
isRaw as Boolean = false,
isFormatted as Boolean = false,
interpolationDepth as Int = 0,
queryIndent as Int = -1,
fenceLanguage as String = ""
) |
Constructs a lexical state with explicit continuation parameters. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | equalsStateequalsState(other as LexicalState) as Boolean |
Compares all fields of this state with another LexicalState for value equality. |
| public | inBlockCommentinBlockComment() as Boolean |
Returns true when inside a multi-line block or documentation comment. |
| public | inMarkdownFenceinMarkdownFence() as Boolean |
Returns true when inside a Markdown fenced code block ( or ~~~`). |
| public | inQueryBlockinQueryBlock() as Boolean |
Returns true when inside an indented Klyn query: block. |
| public | inStringinString() as Boolean |
Returns true when inside a multi-line string literal (outside interpolated code). |
| public | isNormalisNormal() as Boolean |
Returns true when this state is the default top-level state with no open multi-line construct. |
| public static | ofof(
mode as LexicalMode = LexicalMode.NORMAL,
delimiter as String = "",
isRaw as Boolean = false,
isFormatted as Boolean = false,
interpolationDepth as Int = 0,
queryIndent as Int = -1,
fenceLanguage as String = ""
) as LexicalState |
Returns the canonical state, reusing LexicalState.NORMAL when all fields match the default state. |
| public | withQueryIndentwithQueryIndent(indent as Int) as LexicalState |
Returns a copy of this state with an updated queryIndent value. |