TextMateLib 1.0
Modern C++ implementation of the TextMate syntax highlighting engine
Loading...
Searching...
No Matches
c_api.h
Go to the documentation of this file.
1#ifndef TEXTMATELIB_C_API_H
2#define TEXTMATELIB_C_API_H
3
4/// @file c_api.h
5/// @brief C language API for TextMateLib
6///
7/// This header provides a C FFI (Foreign Function Interface) for TextMateLib,
8/// enabling use from C code and language bindings (C#, Python, Node.js, etc.).
9///
10/// **API Organization:**
11/// - **Theme API**: Loading and querying theme colors and styles
12/// - **Registry & Grammar API**: Managing grammar definitions and tokenization
13/// - **Tokenization API**: Core text processing with stateful line-by-line parsing
14///
15/// **Typical Workflow:**
16/// 1. Initialize: Create registry, load grammars and themes
17/// 2. Tokenize: Call tokenize_line() or tokenize_lines() with grammar and text
18/// 3. Apply Styles: Use theme colors from returned scopes
19/// 4. Cleanup: Dispose resources and results
20
21#include "tml_export.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <stdint.h>
28
29/// @defgroup opaque_types Opaque Handle Types
30/// @{
31/// Opaque pointer types for C API objects. Actual implementations are in C++,
32/// handles are meant to be passed directly without inspection.
33
34/// @brief Handle to a theme object containing color schemes
35typedef void* TextMateTheme;
36
37/// @brief Handle to a grammar definition for a specific language
38typedef void* TextMateGrammar;
39
40/// @brief Handle to a parsing state stack (immutable, used for incremental tokenization)
41typedef void* TextMateStateStack;
42
43/// @brief Handle to the Oniguruma regex library instance
44typedef void* TextMateOnigLib;
45
46/// @brief Handle to the grammar registry managing loaded grammars and themes
47typedef void* TextMateRegistry;
48
49/// @}
50
51/// @defgroup token_structures Token and Result Structures
52/// @{
53
54/// @brief Represents a single token in tokenized text
55///
56/// A token maps a range of text to a scope hierarchy (list of scopes).
57/// The scopes determine styling through theme matching.
59 int32_t startIndex; ///< Start position in the line (0-based)
60 int32_t endIndex; ///< End position (exclusive)
61 int32_t scopeDepth; ///< Number of scopes in the scope hierarchy
62 char** scopes; ///< Array of scope strings (e.g., "keyword.control", "string.quoted.double")
63};
64
65/// @brief Result from tokenizing a single line with decoded tokens
66///
67/// Returned by textmate_tokenize_line(). Contains the tokens and the state
68/// needed to continue tokenization on the next line (for incremental updates).
69///
70/// **Memory Ownership:**
71/// Caller must free this structure using textmate_free_tokenize_result().
73 TextMateToken* tokens; ///< Array of tokens found in this line
74 int32_t tokenCount; ///< Number of tokens in the array
75 TextMateStateStack ruleStack; ///< State at end of line (pass to next line's tokenization)
76 int32_t stoppedEarly; ///< Non-zero if tokenization stopped before end (time limit hit)
77};
78
79/// @brief Result from tokenizing a single line with encoded tokens
80///
81/// Alternative to TextMateTokenizeResult that uses compact 32-bit token encoding
82/// rather than decoded scopes. Used by textmate_tokenize_line2() for performance.
83///
84/// **Memory Ownership:**
85/// Caller must free this structure using textmate_free_tokenize_result2().
87 uint32_t* tokens; ///< Array of encoded tokens
88 int32_t tokenCount; ///< Number of tokens in the array
89 TextMateStateStack ruleStack; ///< State at end of line (pass to next line's tokenization)
90 int32_t stoppedEarly; ///< Non-zero if tokenization stopped before end (time limit hit)
91};
92
93/// @brief Result from batch tokenizing multiple lines
94///
95/// Returned by textmate_tokenize_lines(). Optimized for multi-line tokenization
96/// to reduce FFI call overhead in language bindings.
97///
98/// **Memory Ownership:**
99/// Caller must free this structure using textmate_free_tokenize_lines_result().
101 TextMateTokenizeResult** lineResults; ///< Array of results, one per line
102 int32_t lineCount; ///< Number of lines tokenized
103};
104
105/// @brief Result from batch tokenizing multiple lines with encoded tokens
106///
107/// Returned by textmate_tokenize_lines2(). Combines batch tokenization with
108/// compact 32-bit token encoding for maximum performance in language bindings.
109///
110/// **Memory Ownership:**
111/// Caller must free this structure using textmate_free_tokenize_lines_result2().
113 TextMateTokenizeResult2** lineResults; ///< Array of encoded results, one per line
114 int32_t lineCount; ///< Number of lines tokenized
115};
116
117/// @brief Theme color map returned by textmate_registry_get_color_map()
118///
119/// Contains the color palette used by encoded tokens. Foreground/background
120/// color IDs in encoded token metadata are indices into this map.
121///
122/// **Memory Ownership:**
123/// Caller must free this structure using textmate_free_color_map().
125 char** colors; ///< Array of hex color strings (e.g., "#RRGGBB" or "#RRGGBBAA")
126 int32_t colorCount; ///< Number of colors in the array
127};
128
129/// @}
130
131/// @defgroup theme_api Theme API
132/// @{
133/// Load and query color schemes (themes) for syntax highlighting.
134/// Themes map scope hierarchies to foreground/background colors and font styles.
135
136/// @brief Load a theme from a JSON file
137/// @param themePath Path to the theme JSON file (TextMate theme format)
138/// @return Opaque theme handle on success, NULL on error (file not found, invalid JSON, etc.)
139/// @note The returned theme must be disposed with textmate_theme_dispose()
141 const char* themePath
142);
143
144/// @brief Load a theme from a JSON string
145/// @param jsonContent Theme JSON content as a null-terminated string
146/// @return Opaque theme handle on success, NULL on error (invalid JSON)
147/// @note The returned theme must be disposed with textmate_theme_dispose()
149 const char* jsonContent
150);
151
152/// @brief Get the foreground color for a scope path
153/// @param theme Valid theme handle (from textmate_theme_load_*)
154/// @param scopePath Scope path to match (e.g., "source.js keyword.control", "string.quoted.double")
155/// @param defaultColor Color to return if scope is not found in theme
156/// @return RGBA color value (0xRRGGBBAA format, e.g., 0xFF0000FF for opaque red)
157/// @note Scope matching uses TextMate's scope selector rules
158/// @see textmate_theme_get_background(), textmate_theme_get_font_style()
159TML_API uint32_t textmate_theme_get_foreground(
160 TextMateTheme theme,
161 const char* scopePath,
162 uint32_t defaultColor
163);
164
165/// @brief Get the background color for a scope path
166/// @param theme Valid theme handle (from textmate_theme_load_*)
167/// @param scopePath Scope path to match
168/// @param defaultColor Color to return if scope is not found in theme
169/// @return RGBA color value (0xRRGGBBAA format)
170/// @see textmate_theme_get_foreground()
171TML_API uint32_t textmate_theme_get_background(
172 TextMateTheme theme,
173 const char* scopePath,
174 uint32_t defaultColor
175);
176
177/// @brief Font style flag constants for textmate_theme_get_font_style()
178/// @{
179#define TEXTMATE_FONT_STYLE_NONE 0 ///< No special styling
180#define TEXTMATE_FONT_STYLE_ITALIC 1 ///< Italic text
181#define TEXTMATE_FONT_STYLE_BOLD 2 ///< Bold text
182#define TEXTMATE_FONT_STYLE_UNDERLINE 4 ///< Underlined text
183/// @}
184
185/// @brief Get the font style flags for a scope path
186/// @param theme Valid theme handle (from textmate_theme_load_*)
187/// @param scopePath Scope path to match
188/// @param defaultStyle Font style flags to return if scope is not found
189/// @return Combination of TEXTMATE_FONT_STYLE_* flags
190/// @note Flags can be combined with bitwise OR (e.g., BOLD | ITALIC)
191/// @see textmate_theme_get_foreground()
192TML_API int32_t textmate_theme_get_font_style(
193 TextMateTheme theme,
194 const char* scopePath,
195 int32_t defaultStyle
196);
197
198/// @brief Get the default/fallback foreground color for the entire theme
199/// @param theme Valid theme handle (from textmate_theme_load_*)
200/// @return RGBA color value (0xRRGGBBAA format)
201/// @note Used when no matching scope is found in the theme
203
204/// @brief Get the default/fallback background color for the entire theme
205/// @param theme Valid theme handle (from textmate_theme_load_*)
206/// @return RGBA color value (0xRRGGBBAA format)
207/// @note Used when no matching scope is found in the theme
209
210/// @brief Free a theme object and release resources
211/// @param theme Valid theme handle (from textmate_theme_load_*), or NULL (no-op)
212/// @warning Do not use theme after calling this function
213/// @note Safe to call with NULL
214TML_API void textmate_theme_dispose(TextMateTheme theme);
215
216/// @}
217
218/// @defgroup registry_api Registry and Grammar API
219/// @{
220/// Manage grammar definitions, handle dependencies, and perform tokenization.
221/// The registry is the central component for working with multiple grammars and themes.
222
223/// @brief Initialize the Oniguruma regular expression library
224/// @return Opaque Oniguruma library handle on success, NULL on error
225/// @note This must be created before creating a registry
226/// @note The returned handle must be disposed with textmate_oniglib_dispose()
228
229/// @brief Create a new grammar registry
230/// @param onigLib Valid Oniguruma library handle (from textmate_oniglib_create())
231/// @return Registry handle on success, NULL on error
232/// @note The registry must be disposed with textmate_registry_dispose()
233/// @see textmate_oniglib_create()
235
236/// @brief Free a registry and all its resources
237/// @param registry Valid registry handle (from textmate_registry_create()), or NULL (no-op)
238/// @warning Do not use registry after calling this function
239/// @warning All grammars loaded from this registry become invalid
240/// @note Safe to call with NULL
241TML_API void textmate_registry_dispose(TextMateRegistry registry);
242
243/// @brief Register a grammar from a JSON file
244/// @param registry Valid registry handle
245/// @param grammarPath Path to the grammar JSON file (TextMate grammar format)
246/// @return Non-zero on success, 0 on error (file not found, invalid JSON, etc.)
247/// @note Grammars must be registered before they can be loaded with textmate_registry_load_grammar()
248/// @see textmate_registry_add_grammar_from_json(), textmate_registry_load_grammar()
250 TextMateRegistry registry,
251 const char* grammarPath
252);
253
254/// @brief Register a grammar from a JSON string
255/// @param registry Valid registry handle
256/// @param jsonContent Grammar JSON content as a null-terminated string (TextMate grammar format)
257/// @return Non-zero on success, 0 on error (invalid JSON, etc.)
258/// @note Grammars must be registered before they can be loaded
259/// @see textmate_registry_add_grammar_from_file(), textmate_registry_load_grammar()
261 TextMateRegistry registry,
262 const char* jsonContent
263);
264
265/// @brief Set grammar injection rules for a scope
266/// @param registry Valid registry handle
267/// @param scopeName Scope to inject grammars into (e.g., "source.js string.quoted.single")
268/// @param injections Array of grammar scope names to inject
269/// @param injectionCount Number of injections in the array
270/// @note Call before loading the target grammar to take effect
271/// @note Allows embedding one grammar within another (e.g., regex highlighting in string literals)
273 TextMateRegistry registry,
274 const char* scopeName,
275 const char** injections,
276 int32_t injectionCount
277);
278
279/// @brief Set the color theme on the registry
280/// @param registry Valid registry handle
281/// @param themeJsonContent Theme JSON content as a null-terminated string (TextMate theme format)
282/// @return Non-zero on success, 0 on error (invalid JSON, etc.)
283/// @note Must be called before tokenizeLine2 to get meaningful themed tokens
284/// @see textmate_tokenize_line2(), textmate_tokenize_line2_utf16()
286 TextMateRegistry registry,
287 const char* themeJsonContent
288);
289
290/// @brief Get the color map from the registry after setting a theme
291/// @param registry Valid registry handle
292/// @return Pointer to color map on success, NULL if no theme is set
293/// @note The foreground/background IDs in encoded token metadata are indices into this map
294/// @note The returned result must be freed with textmate_free_color_map()
295/// @see textmate_registry_set_theme()
297
298/// @brief Load a grammar by scope name
299/// @param registry Valid registry handle
300/// @param scopeName Scope name of the grammar to load (e.g., "source.javascript", "text.html.markdown")
301/// @return Grammar handle on success, NULL if grammar not found or registration failed
302/// @note Automatically resolves grammar dependencies and includes
303/// @note The grammar must have been previously registered with textmate_registry_add_grammar_*()
304/// @see textmate_registry_add_grammar_from_file(), textmate_registry_add_grammar_from_json()
306 TextMateRegistry registry,
307 const char* scopeName
308);
309
310/// @}
311
312/// @defgroup tokenization_api Tokenization API
313/// @{
314/// Tokenize text using a grammar, handling stateful line-by-line parsing.
315
316/// @brief Get the initial parsing state
317/// @return The INITIAL state stack (first line of a document)
318/// @note This is used as the prevState parameter for the first line
319/// @note The returned state is read-only and should not be freed
321
322/// @brief Tokenize a single line of text with decoded scopes
323/// @param grammar Valid grammar handle (from textmate_registry_load_grammar())
324/// @param lineText The text to tokenize (should not include newline)
325/// @param prevState The state from the previous line (or initial state for first line)
326/// @return Pointer to tokenization result on success, NULL on error
327/// @note The returned result must be freed with textmate_free_tokenize_result()
328/// @note Use the ruleStack from the result as prevState for the next line
329/// @see textmate_tokenize_line2() for encoded token format (more efficient)
330/// @see textmate_get_initial_state()
332 TextMateGrammar grammar,
333 const char* lineText,
334 TextMateStateStack prevState
335);
336
337/// @brief Tokenize a single line of text with encoded tokens (more efficient)
338/// @param grammar Valid grammar handle (from textmate_registry_load_grammar())
339/// @param lineText The text to tokenize (should not include newline)
340/// @param prevState The state from the previous line (or initial state for first line)
341/// @return Pointer to tokenization result on success, NULL on error
342/// @note The returned result must be freed with textmate_free_tokenize_result2()
343/// @note Tokens are encoded as 32-bit values for better performance
344/// @note Prefer this over textmate_tokenize_line() for performance-critical code
346 TextMateGrammar grammar,
347 const char* lineText,
348 TextMateStateStack prevState
349);
350
351/// @brief Tokenize multiple lines in a single call
352/// @param grammar Valid grammar handle
353/// @param lines Array of line strings (none should include newline)
354/// @param lineCount Number of lines in the array
355/// @param initialState The state to start with (typically INITIAL or from Session API)
356/// @return Pointer to batch result on success, NULL on error
357/// @note The returned result must be freed with textmate_free_tokenize_lines_result()
358/// @note Reduces FFI call overhead when tokenizing multiple lines (important for language bindings)
359/// @note Each result's ruleStack is automatically passed to the next line
360/// @see textmate_free_tokenize_lines_result()
362 TextMateGrammar grammar,
363 const char** lines,
364 int32_t lineCount,
365 TextMateStateStack initialState
366);
367
368/// @brief Tokenize multiple lines with encoded tokens in a single call
369/// @param grammar Valid grammar handle
370/// @param lines Array of line strings (none should include newline)
371/// @param lineCount Number of lines in the array
372/// @param initialState The state to start with (typically INITIAL or from Session API)
373/// @return Pointer to batch result on success, NULL on error
374/// @note The returned result must be freed with textmate_free_tokenize_lines_result2()
375/// @note Combines batch tokenization with compact encoding for maximum performance
376/// @note Requires a theme to be set on the registry for meaningful themed output
377/// @see textmate_registry_set_theme(), textmate_free_tokenize_lines_result2()
379 TextMateGrammar grammar,
380 const char** lines,
381 int32_t lineCount,
382 TextMateStateStack initialState
383);
384
385/// @brief Free a line tokenization result
386/// @param result Valid result pointer (from textmate_tokenize_line()), or NULL (no-op)
387/// @warning Do not use result after calling this function
388/// @note Safe to call with NULL
390
391/// @brief Free an encoded line tokenization result
392/// @param result Valid result pointer (from textmate_tokenize_line2()), or NULL (no-op)
393/// @warning Do not use result after calling this function
394/// @note Safe to call with NULL
396
397/// @brief Free a batch tokenization result
398/// @param result Valid result pointer (from textmate_tokenize_lines()), or NULL (no-op)
399/// @warning Do not use result after calling this function
400/// @note Safe to call with NULL
402
403/// @brief Free a batch encoded tokenization result
404/// @param result Valid result pointer (from textmate_tokenize_lines2()), or NULL (no-op)
405/// @warning Do not use result after calling this function
406/// @note Safe to call with NULL
408
409/// @brief Free a color map
410/// @param colorMap Valid color map pointer (from textmate_registry_get_color_map()), or NULL (no-op)
411/// @warning Do not use colorMap after calling this function
412/// @note Safe to call with NULL
413TML_API void textmate_free_color_map(TextMateColorMap* colorMap);
414
415/// @defgroup tokenization_utf16_api UTF-16 Tokenization API
416/// @{
417/// Tokenize text and return indices as UTF-16 code unit offsets.
418/// Use these from language bindings where strings are UTF-16 encoded (C#, JavaScript).
419/// The original functions above return UTF-8 byte offsets which are correct for C/C++.
420
421/// @brief Tokenize a single line with decoded scopes, returning UTF-16 indices
422/// @param grammar Valid grammar handle (from textmate_registry_load_grammar())
423/// @param lineText The text to tokenize (UTF-8, null-terminated)
424/// @param prevState The state from the previous line (or initial state for first line)
425/// @return Pointer to tokenization result on success, NULL on error
426/// @note Token startIndex/endIndex are UTF-16 code unit offsets
427/// @note The returned result must be freed with textmate_free_tokenize_result()
429 TextMateGrammar grammar,
430 const char* lineText,
431 TextMateStateStack prevState
432);
433
434/// @brief Tokenize a single line with encoded tokens, returning UTF-16 indices
435/// @param grammar Valid grammar handle (from textmate_registry_load_grammar())
436/// @param lineText The text to tokenize (UTF-8, null-terminated)
437/// @param prevState The state from the previous line (or initial state for first line)
438/// @return Pointer to tokenization result on success, NULL on error
439/// @note Start offsets in the encoded tokens are UTF-16 code unit offsets
440/// @note The returned result must be freed with textmate_free_tokenize_result2()
442 TextMateGrammar grammar,
443 const char* lineText,
444 TextMateStateStack prevState
445);
446
447/// @brief Tokenize multiple lines in a single call, returning UTF-16 indices
448/// @param grammar Valid grammar handle
449/// @param lines Array of line strings (UTF-8, null-terminated, none should include newline)
450/// @param lineCount Number of lines in the array
451/// @param initialState The state to start with (typically INITIAL or from Session API)
452/// @return Pointer to batch result on success, NULL on error
453/// @note Token startIndex/endIndex are UTF-16 code unit offsets
454/// @note The returned result must be freed with textmate_free_tokenize_lines_result()
456 TextMateGrammar grammar,
457 const char** lines,
458 int32_t lineCount,
459 TextMateStateStack initialState
460);
461
462/// @brief Tokenize multiple lines with encoded tokens, returning UTF-16 indices
463/// @param grammar Valid grammar handle
464/// @param lines Array of line strings (UTF-8, null-terminated, none should include newline)
465/// @param lineCount Number of lines in the array
466/// @param initialState The state to start with (typically INITIAL or from Session API)
467/// @return Pointer to batch result on success, NULL on error
468/// @note Start offsets in encoded tokens are UTF-16 code unit offsets
469/// @note The returned result must be freed with textmate_free_tokenize_lines_result2()
470/// @see textmate_registry_set_theme(), textmate_free_tokenize_lines_result2()
472 TextMateGrammar grammar,
473 const char** lines,
474 int32_t lineCount,
475 TextMateStateStack initialState
476);
477
478/// @}
479
480/// @brief Get the scope name (language identifier) of a grammar
481/// @param grammar Valid grammar handle (from textmate_registry_load_grammar())
482/// @return Scope name string (e.g., "source.javascript"), valid for lifetime of grammar
483/// @return NULL if grammar is invalid
484TML_API const char* textmate_grammar_get_scope_name(TextMateGrammar grammar);
485
486/// @brief Free the Oniguruma library
487/// @param onigLib Valid Oniguruma handle (from textmate_oniglib_create()), or NULL (no-op)
488/// @warning Do not use onigLib after calling this function
489/// @warning All registries and grammars created with this lib become invalid
490/// @note Safe to call with NULL
491TML_API void textmate_oniglib_dispose(TextMateOnigLib onigLib);
492
493/// @}
494
495#ifdef __cplusplus
496}
497#endif
498
499#endif // TEXTMATELIB_C_API_H
void * TextMateGrammar
Handle to a grammar definition for a specific language.
Definition c_api.h:38
void * TextMateTheme
Handle to a theme object containing color schemes.
Definition c_api.h:35
void * TextMateRegistry
Handle to the grammar registry managing loaded grammars and themes.
Definition c_api.h:47
void * TextMateStateStack
Handle to a parsing state stack (immutable, used for incremental tokenization)
Definition c_api.h:41
void * TextMateOnigLib
Handle to the Oniguruma regex library instance.
Definition c_api.h:44
TML_API int textmate_registry_set_theme(TextMateRegistry registry, const char *themeJsonContent)
Set the color theme on the registry.
Definition c_api.cpp:593
TML_API int textmate_registry_add_grammar_from_json(TextMateRegistry registry, const char *jsonContent)
Register a grammar from a JSON string.
Definition c_api.cpp:544
TML_API TextMateOnigLib textmate_oniglib_create()
Initialize the Oniguruma regular expression library.
Definition c_api.cpp:446
TML_API void textmate_registry_dispose(TextMateRegistry registry)
Free a registry and all its resources.
Definition c_api.cpp:506
TML_API int textmate_registry_add_grammar_from_file(TextMateRegistry registry, const char *grammarPath)
Register a grammar from a JSON file.
Definition c_api.cpp:514
TML_API TextMateRegistry textmate_registry_create(TextMateOnigLib onigLib)
Create a new grammar registry.
Definition c_api.cpp:496
TML_API TextMateColorMap * textmate_registry_get_color_map(TextMateRegistry registry)
Get the color map from the registry after setting a theme.
Definition c_api.cpp:613
TML_API TextMateGrammar textmate_registry_load_grammar(TextMateRegistry registry, const char *scopeName)
Load a grammar by scope name.
Definition c_api.cpp:642
TML_API void textmate_registry_set_injections(TextMateRegistry registry, const char *scopeName, const char **injections, int32_t injectionCount)
Set grammar injection rules for a scope.
Definition c_api.cpp:568
TML_API uint32_t textmate_theme_get_default_background(TextMateTheme theme)
Get the default/fallback background color for the entire theme.
Definition c_api.cpp:417
TML_API uint32_t textmate_theme_get_background(TextMateTheme theme, const char *scopePath, uint32_t defaultColor)
Get the background color for a scope path.
Definition c_api.cpp:279
TML_API void textmate_theme_dispose(TextMateTheme theme)
Free a theme object and release resources.
Definition c_api.cpp:438
TML_API uint32_t textmate_theme_get_foreground(TextMateTheme theme, const char *scopePath, uint32_t defaultColor)
Get the foreground color for a scope path.
Definition c_api.cpp:216
TML_API int32_t textmate_theme_get_font_style(TextMateTheme theme, const char *scopePath, int32_t defaultStyle)
Get the font style flags for a scope path.
Definition c_api.cpp:342
TML_API uint32_t textmate_theme_get_default_foreground(TextMateTheme theme)
Get the default/fallback foreground color for the entire theme.
Definition c_api.cpp:396
TML_API TextMateTheme textmate_theme_load_from_json(const char *jsonContent)
Load a theme from a JSON string.
Definition c_api.cpp:192
TML_API TextMateTheme textmate_theme_load_from_file(const char *themePath)
Load a theme from a JSON file.
Definition c_api.cpp:163
TML_API void textmate_free_tokenize_result(TextMateTokenizeResult *result)
Free a line tokenization result.
Definition c_api.cpp:748
TML_API const char * textmate_grammar_get_scope_name(TextMateGrammar grammar)
Get the scope name (language identifier) of a grammar.
Definition c_api.cpp:1153
TML_API TextMateTokenizeMultiLinesResult * textmate_tokenize_lines(TextMateGrammar grammar, const char **lines, int32_t lineCount, TextMateStateStack initialState)
Tokenize multiple lines in a single call.
Definition c_api.cpp:776
TML_API void textmate_oniglib_dispose(TextMateOnigLib onigLib)
Free the Oniguruma library.
Definition c_api.cpp:1169
TML_API TextMateStateStack textmate_get_initial_state()
Get the initial parsing state.
Definition c_api.cpp:660
TML_API TextMateTokenizeResult2 * textmate_tokenize_line2(TextMateGrammar grammar, const char *lineText, TextMateStateStack prevState)
Tokenize a single line of text with encoded tokens (more efficient)
Definition c_api.cpp:712
TML_API void textmate_free_tokenize_lines_result2(TextMateTokenizeMultiLinesResult2 *result)
Free a batch encoded tokenization result.
Definition c_api.cpp:903
TML_API void textmate_free_tokenize_lines_result(TextMateTokenizeMultiLinesResult *result)
Free a batch tokenization result.
Definition c_api.cpp:839
TML_API TextMateTokenizeResult * textmate_tokenize_line(TextMateGrammar grammar, const char *lineText, TextMateStateStack prevState)
Tokenize a single line of text with decoded scopes.
Definition c_api.cpp:665
TML_API void textmate_free_color_map(TextMateColorMap *colorMap)
Free a color map.
Definition c_api.cpp:916
TML_API void textmate_free_tokenize_result2(TextMateTokenizeResult2 *result)
Free an encoded line tokenization result.
Definition c_api.cpp:766
TML_API TextMateTokenizeMultiLinesResult2 * textmate_tokenize_lines2(TextMateGrammar grammar, const char **lines, int32_t lineCount, TextMateStateStack initialState)
Tokenize multiple lines with encoded tokens in a single call.
Definition c_api.cpp:853
TML_API TextMateTokenizeMultiLinesResult2 * textmate_tokenize_lines2_utf16(TextMateGrammar grammar, const char **lines, int32_t lineCount, TextMateStateStack initialState)
Tokenize multiple lines with encoded tokens, returning UTF-16 indices.
Definition c_api.cpp:1097
TML_API TextMateTokenizeMultiLinesResult * textmate_tokenize_lines_utf16(TextMateGrammar grammar, const char **lines, int32_t lineCount, TextMateStateStack initialState)
Tokenize multiple lines in a single call, returning UTF-16 indices.
Definition c_api.cpp:1031
TML_API TextMateTokenizeResult2 * textmate_tokenize_line2_utf16(TextMateGrammar grammar, const char *lineText, TextMateStateStack prevState)
Tokenize a single line with encoded tokens, returning UTF-16 indices.
Definition c_api.cpp:985
TML_API TextMateTokenizeResult * textmate_tokenize_line_utf16(TextMateGrammar grammar, const char *lineText, TextMateStateStack prevState)
Tokenize a single line with decoded scopes, returning UTF-16 indices.
Definition c_api.cpp:933
Theme color map returned by textmate_registry_get_color_map()
Definition c_api.h:124
char ** colors
Array of hex color strings (e.g., "#RRGGBB" or "#RRGGBBAA")
Definition c_api.h:125
int32_t colorCount
Number of colors in the array.
Definition c_api.h:126
Represents a single token in tokenized text.
Definition c_api.h:58
int32_t startIndex
Start position in the line (0-based)
Definition c_api.h:59
int32_t endIndex
End position (exclusive)
Definition c_api.h:60
char ** scopes
Array of scope strings (e.g., "keyword.control", "string.quoted.double")
Definition c_api.h:62
int32_t scopeDepth
Number of scopes in the scope hierarchy.
Definition c_api.h:61
Result from batch tokenizing multiple lines with encoded tokens.
Definition c_api.h:112
TextMateTokenizeResult2 ** lineResults
Array of encoded results, one per line.
Definition c_api.h:113
int32_t lineCount
Number of lines tokenized.
Definition c_api.h:114
Result from batch tokenizing multiple lines.
Definition c_api.h:100
int32_t lineCount
Number of lines tokenized.
Definition c_api.h:102
TextMateTokenizeResult ** lineResults
Array of results, one per line.
Definition c_api.h:101
Result from tokenizing a single line with encoded tokens.
Definition c_api.h:86
int32_t tokenCount
Number of tokens in the array.
Definition c_api.h:88
TextMateStateStack ruleStack
State at end of line (pass to next line's tokenization)
Definition c_api.h:89
uint32_t * tokens
Array of encoded tokens.
Definition c_api.h:87
int32_t stoppedEarly
Non-zero if tokenization stopped before end (time limit hit)
Definition c_api.h:90
Result from tokenizing a single line with decoded tokens.
Definition c_api.h:72
int32_t stoppedEarly
Non-zero if tokenization stopped before end (time limit hit)
Definition c_api.h:76
TextMateStateStack ruleStack
State at end of line (pass to next line's tokenization)
Definition c_api.h:75
TextMateToken * tokens
Array of tokens found in this line.
Definition c_api.h:73
int32_t tokenCount
Number of tokens in the array.
Definition c_api.h:74