Skip to content

Type Editor


Type Editor / @type-editor/model / content-parser/TokenStream / TokenStream

Class: TokenStream

Defined in: packages/model/src/content-parser/TokenStream.ts:7

Tokenizes and provides streaming access to a content expression string. Splits the expression into individual tokens for parsing.

Constructors

Constructor

ts
new TokenStream(expression, nodeTypes): TokenStream;

Defined in: packages/model/src/content-parser/TokenStream.ts:26

Creates a new token stream from a content expression string.

Parameters

ParameterTypeDescription
expressionstringThe content expression to tokenize
nodeTypesReadonly<Record<string, NodeType>>Map of available node types for name resolution

Returns

TokenStream

Accessors

inline

Get Signature

ts
get inline(): boolean;

Defined in: packages/model/src/content-parser/TokenStream.ts:48

Tracks whether the expression contains inline content (true), block content (false), or hasn't been determined yet (null). Used to prevent mixing inline and block content in expressions.

Returns

boolean

Set Signature

ts
set inline(isInline): void;

Defined in: packages/model/src/content-parser/TokenStream.ts:52

Parameters
ParameterType
isInlineboolean
Returns

void


next

Get Signature

ts
get next(): string;

Defined in: packages/model/src/content-parser/TokenStream.ts:88

Gets the current token without consuming it.

Returns

string

The current token, or undefined if at end of stream


nodeTypes

Get Signature

ts
get nodeTypes(): Readonly<Record<string, NodeType>>;

Defined in: packages/model/src/content-parser/TokenStream.ts:79

Map of available node types for name resolution

Returns

Readonly<Record<string, NodeType>>


pos

Get Signature

ts
get pos(): number;

Defined in: packages/model/src/content-parser/TokenStream.ts:59

Current position in the token array

Returns

number

Set Signature

ts
set pos(position): void;

Defined in: packages/model/src/content-parser/TokenStream.ts:69

Current position in the token array

Throws

If position is negative

Parameters
ParameterType
positionnumber
Returns

void

Methods

eat()

ts
eat(tok): boolean;

Defined in: packages/model/src/content-parser/TokenStream.ts:99

Attempts to consume a specific token. If the current token matches, advances the position and returns true.

Parameters

ParameterTypeDescription
tokstringThe token to try to consume

Returns

boolean

true if the token was consumed, false otherwise


err()

ts
err(str): never;

Defined in: packages/model/src/content-parser/TokenStream.ts:113

Throws a syntax error with context about the content expression.

Parameters

ParameterTypeDescription
strstringThe error message

Returns

never

Throws

Always throws with the provided message and expression context