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

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()
Fields
Modifier and Type Member Description
public static readonly NORMAL
NORMAL as LexicalState = LexicalState(LexicalMode.NORMAL, "", false, false, 0, -1, "")
Shared singleton representing the default top-level code state.
Properties
Modifier and Type Member Description
public readonly property delimiter
delimiter as String
Closing delimiter expected to exit the current multi-line mode.
public readonly property fenceLanguage
fenceLanguage as String
Language identifier of the active Markdown fenced code block.
public readonly property interpolationDepth
interpolationDepth as Int
Current nesting depth of {...} expressions inside an interpolated multi-line string.
public readonly property isFormatted
isFormatted as Boolean
Indicates whether the active multi-line string supports {...} interpolation.
public readonly property isRaw
isRaw as Boolean
Indicates whether the active multi-line string is a raw literal.
public readonly property mode
mode as LexicalMode
Active multi-line lexical mode.
public readonly property queryIndent
queryIndent as Int
Indentation column of the active Klyn query: block, or -1 when outside a query block.
Inherited Properties
propertyInherited Properties from Object: type
Constructors
Modifier and Type Member Description
public LexicalState
LexicalState( 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.
Methods
Modifier and Type Member Description
public equalsState
equalsState(other as LexicalState) as Boolean
Compares all fields of this state with another LexicalState for value equality.
public inBlockComment
inBlockComment() as Boolean
Returns true when inside a multi-line block or documentation comment.
public inMarkdownFence
inMarkdownFence() as Boolean
Returns true when inside a Markdown fenced code block ( or ~~~`).
public inQueryBlock
inQueryBlock() as Boolean
Returns true when inside an indented Klyn query: block.
public inString
inString() as Boolean
Returns true when inside a multi-line string literal (outside interpolated code).
public isNormal
isNormal() as Boolean
Returns true when this state is the default top-level state with no open multi-line construct.
public static of
of( 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 withQueryIndent
withQueryIndent(indent as Int) as LexicalState
Returns a copy of this state with an updated queryIndent value.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml