tiny.syn.State
Defined in state.
The continuation state: what the last scanned line left open.
API (6)
Actions
Public operations.
mode: Returns the open mode, or null when nothing is open, for a caller or a test reading which comment or string is open after a line.owner: Returns the owning language, or null when nothing is open, for a caller or a test reading which language left something open.rebind: Keeps the open mode whenlanguageowns it, and clears the state otherwise, forhighlightLineat the start of each line so an open comment or string from another language never reaches this one.reset: Clears the state, so nothing is open, for a caller starting a new document.retain: Storesnext_modewithlanguageas its owner, or clears the state whennext_modeis null, forhighlightLineafter scanning a line to store what the line left open.
Fields and members
Public fields and members.
Source
Source: lib/syn/src/state.zig:97
zig
/// The continuation state: what the last scanned line left open. A caller keeps one for each/// document and passes it to every `highlightLine` call for that document. The value `.{}` is the/// fresh state for the start of a document. The struct holds no pointers and needs no cleanup. The/// state records no document, so a caller that moves to another document calls `reset`.pub const State = struct { /// The open mode with its owning language, or null when nothing is open. The package changes it /// only through `reset`, `rebind` and `retain`, which keep the mode admitted by its language. continuation: ?Continuation = null, /// Clears the state, so nothing is open, for a caller starting a new document. pub fn reset(self: *State) void { self.* = .{}; } /// Keeps the open mode when `language` owns it, and clears the state otherwise, for /// `highlightLine` at the start of each line so an open comment or string from another language /// never reaches this one. The call asserts that a stored mode is admitted by its owning /// language. pub fn rebind(self: *State, language: Language) void { const continuation = self.continuation orelse return; std.debug.assert(continuation.mode.admittedBy( continuation.language, )); if (continuation.language != language) self.reset(); } /// Stores `next_mode` with `language` as its owner, or clears the state when `next_mode` is /// null, for `highlightLine` after scanning a line to store what the line left open. The call /// asserts that `language` admits `next_mode`. pub fn retain( self: *State, language: Language, next_mode: ?Mode, ) void { if (next_mode) |actual| { std.debug.assert(actual.admittedBy(language)); } self.continuation = if (next_mode) |actual| .{ .language = language, .mode = actual } else null; } /// Returns the owning language, or null when nothing is open, for a caller or a test reading /// which language left something open. pub fn owner(self: *const State) ?Language { const continuation = self.continuation orelse return null; return continuation.language; } /// Returns the open mode, or null when nothing is open, for a caller or a test reading which /// comment or string is open after a line. pub fn mode(self: *const State) ?Mode { const continuation = self.continuation orelse return null; return continuation.mode; }};Source: lib/syn/src/root.zig:52
zig
pub const State = state.State;Complete caller list for State.mode
8 direct callers.
lib.syn.src.scan.test.test_activated_syntax_highlighting_performs_no_backing_allocation[function] — test source atlib/syn/src/scan/test.zig:400in nearest public ownerlib.syn.src.scan.testlib.syn.src.scan.test.test_foreign_continuation_equals_a_fresh_target-language_scan[function] — test source atlib/syn/src/scan/test.zig:256in nearest public ownerlib.syn.src.scan.testlib.syn.src.scan.test.test_rust_lifetime_and_block_opener_produce_one_coherent_transition[function] — test source atlib/syn/src/scan/test.zig:284in nearest public ownerlib.syn.src.scan.testlib.syn.src.scan.test.test_syn_line_state_carries_a_new_block_opened_after_a_continuation_closes[function] — test source atlib/syn/src/scan/test.zig:165in nearest public ownerlib.syn.src.scan.testlib.syn.src.scan.test.test_syn_line_state_carries_generic_block_comments[function] — test source atlib/syn/src/scan/test.zig:146in nearest public ownerlib.syn.src.scan.testlib.syn.src.scan.test.test_syn_line_state_carries_markup_comments_and_toml_strings[function] — test source atlib/syn/src/scan/test.zig:203in nearest public ownerlib.syn.src.scan.testlib.syn.src.scan.test.test_syn_line_state_carries_python_triple_strings[function] — test source atlib/syn/src/scan/test.zig:180in nearest public ownerlib.syn.src.scan.testlib.syn.src.scan.test.test_toml_escaped_triple_delimiter_retains_the_scanner_transition[function] — test source atlib/syn/src/scan/test.zig:231in nearest public ownerlib.syn.src.scan.test
Audit
| Definitions | 6 |
|---|---|
| Public names | 12 |
| Members | 1 |
| Version | 26.7.0 |
| Revision | daab053ee433 |