TextMateLib 1.0
Modern C++ implementation of the TextMate syntax highlighting engine
Loading...
Searching...
No Matches
c_api.h File Reference

C language API for TextMateLib. More...

#include "tml_export.h"
#include <stdint.h>
Include dependency graph for c_api.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TextMateToken
 Represents a single token in tokenized text. More...
 
struct  TextMateTokenizeResult
 Result from tokenizing a single line with decoded tokens. More...
 
struct  TextMateTokenizeResult2
 Result from tokenizing a single line with encoded tokens. More...
 
struct  TextMateTokenizeMultiLinesResult
 Result from batch tokenizing multiple lines. More...
 

Typedefs

typedef void * TextMateTheme
 Handle to a theme object containing color schemes.
 
typedef void * TextMateGrammar
 Handle to a grammar definition for a specific language.
 
typedef void * TextMateStateStack
 Handle to a parsing state stack (immutable, used for incremental tokenization)
 
typedef void * TextMateOnigLib
 Handle to the Oniguruma regex library instance.
 
typedef void * TextMateRegistry
 Handle to the grammar registry managing loaded grammars and themes.
 

Functions

TML_API TextMateTheme textmate_theme_load_from_file (const char *themePath)
 Load a theme from a JSON file.
 
TML_API TextMateTheme textmate_theme_load_from_json (const char *jsonContent)
 Load a theme from a JSON string.
 
TML_API uint32_t textmate_theme_get_foreground (TextMateTheme theme, const char *scopePath, uint32_t defaultColor)
 Get the foreground color for a scope path.
 
TML_API uint32_t textmate_theme_get_background (TextMateTheme theme, const char *scopePath, uint32_t defaultColor)
 Get the background color for a scope path.
 
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.
 
TML_API uint32_t textmate_theme_get_default_foreground (TextMateTheme theme)
 Get the default/fallback foreground color for the entire theme.
 
TML_API uint32_t textmate_theme_get_default_background (TextMateTheme theme)
 Get the default/fallback background color for the entire theme.
 
TML_API void textmate_theme_dispose (TextMateTheme theme)
 Free a theme object and release resources.
 
TML_API TextMateOnigLib textmate_oniglib_create ()
 Initialize the Oniguruma regular expression library.
 
TML_API TextMateRegistry textmate_registry_create (TextMateOnigLib onigLib)
 Create a new grammar registry.
 
TML_API void textmate_registry_dispose (TextMateRegistry registry)
 Free a registry and all its resources.
 
TML_API int textmate_registry_add_grammar_from_file (TextMateRegistry registry, const char *grammarPath)
 Register a grammar from a JSON file.
 
TML_API int textmate_registry_add_grammar_from_json (TextMateRegistry registry, const char *jsonContent)
 Register a grammar from a JSON string.
 
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.
 
TML_API TextMateGrammar textmate_registry_load_grammar (TextMateRegistry registry, const char *scopeName)
 Load a grammar by scope name.
 
TML_API TextMateStateStack textmate_get_initial_state ()
 Get the initial parsing state.
 
TML_API TextMateTokenizeResulttextmate_tokenize_line (TextMateGrammar grammar, const char *lineText, TextMateStateStack prevState)
 Tokenize a single line of text with decoded scopes.
 
TML_API TextMateTokenizeResult2textmate_tokenize_line2 (TextMateGrammar grammar, const char *lineText, TextMateStateStack prevState)
 Tokenize a single line of text with encoded tokens (more efficient)
 
TML_API TextMateTokenizeMultiLinesResulttextmate_tokenize_lines (TextMateGrammar grammar, const char **lines, int32_t lineCount, TextMateStateStack initialState)
 Tokenize multiple lines in a single call.
 
TML_API void textmate_free_tokenize_result (TextMateTokenizeResult *result)
 Free a line tokenization result.
 
TML_API void textmate_free_tokenize_result2 (TextMateTokenizeResult2 *result)
 Free an encoded line tokenization result.
 
TML_API void textmate_free_tokenize_lines_result (TextMateTokenizeMultiLinesResult *result)
 Free a batch tokenization result.
 
TML_API TextMateTokenizeResulttextmate_tokenize_line_utf16 (TextMateGrammar grammar, const char *lineText, TextMateStateStack prevState)
 Tokenize a single line with decoded scopes, returning UTF-16 indices.
 
TML_API TextMateTokenizeResult2textmate_tokenize_line2_utf16 (TextMateGrammar grammar, const char *lineText, TextMateStateStack prevState)
 Tokenize a single line with encoded tokens, returning UTF-16 indices.
 
TML_API TextMateTokenizeMultiLinesResulttextmate_tokenize_lines_utf16 (TextMateGrammar grammar, const char **lines, int32_t lineCount, TextMateStateStack initialState)
 Tokenize multiple lines in a single call, returning UTF-16 indices.
 
TML_API const char * textmate_grammar_get_scope_name (TextMateGrammar grammar)
 Get the scope name (language identifier) of a grammar.
 
TML_API void textmate_oniglib_dispose (TextMateOnigLib onigLib)
 Free the Oniguruma library.
 

Detailed Description

C language API for TextMateLib.

This header provides a C FFI (Foreign Function Interface) for TextMateLib, enabling use from C code and language bindings (C#, Python, Node.js, etc.).

API Organization:

  • Theme API: Loading and querying theme colors and styles
  • Registry & Grammar API: Managing grammar definitions and tokenization
  • Tokenization API: Core text processing with stateful line-by-line parsing

Typical Workflow:

  1. Initialize: Create registry, load grammars and themes
  2. Tokenize: Call tokenize_line() or tokenize_lines() with grammar and text
  3. Apply Styles: Use theme colors from returned scopes
  4. Cleanup: Dispose resources and results

Definition in file c_api.h.