TextMateLib 1.0
Modern C++ implementation of the TextMate syntax highlighting engine
Loading...
Searching...
No Matches
Registry and Grammar API

Manage grammar definitions, handle dependencies, and perform tokenization. More...

Functions

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 int textmate_registry_set_theme (TextMateRegistry registry, const char *themeJsonContent)
 Set the color theme on the registry.
 
TML_API TextMateColorMap * textmate_registry_get_color_map (TextMateRegistry registry)
 Get the color map from the registry after setting a theme.
 
TML_API TextMateGrammar textmate_registry_load_grammar (TextMateRegistry registry, const char *scopeName)
 Load a grammar by scope name.
 

Detailed Description

Manage grammar definitions, handle dependencies, and perform tokenization.

The registry is the central component for working with multiple grammars and themes.

Function Documentation

◆ textmate_oniglib_create()

TML_API TextMateOnigLib textmate_oniglib_create ( )

Initialize the Oniguruma regular expression library.

Returns
Opaque Oniguruma library handle on success, NULL on error
Note
This must be created before creating a registry
The returned handle must be disposed with textmate_oniglib_dispose()

Definition at line 446 of file c_api.cpp.

◆ textmate_registry_add_grammar_from_file()

TML_API int textmate_registry_add_grammar_from_file ( TextMateRegistry  registry,
const char *  grammarPath 
)

Register a grammar from a JSON file.

Parameters
registryValid registry handle
grammarPathPath to the grammar JSON file (TextMate grammar format)
Returns
Non-zero on success, 0 on error (file not found, invalid JSON, etc.)
Note
Grammars must be registered before they can be loaded with textmate_registry_load_grammar()
See also
textmate_registry_add_grammar_from_json(), textmate_registry_load_grammar()

Definition at line 514 of file c_api.cpp.

◆ textmate_registry_add_grammar_from_json()

TML_API int textmate_registry_add_grammar_from_json ( TextMateRegistry  registry,
const char *  jsonContent 
)

Register a grammar from a JSON string.

Parameters
registryValid registry handle
jsonContentGrammar JSON content as a null-terminated string (TextMate grammar format)
Returns
Non-zero on success, 0 on error (invalid JSON, etc.)
Note
Grammars must be registered before they can be loaded
See also
textmate_registry_add_grammar_from_file(), textmate_registry_load_grammar()

Definition at line 544 of file c_api.cpp.

◆ textmate_registry_create()

TML_API TextMateRegistry textmate_registry_create ( TextMateOnigLib  onigLib)

Create a new grammar registry.

Parameters
onigLibValid Oniguruma library handle (from textmate_oniglib_create())
Returns
Registry handle on success, NULL on error
Note
The registry must be disposed with textmate_registry_dispose()
See also
textmate_oniglib_create()

Definition at line 496 of file c_api.cpp.

◆ textmate_registry_dispose()

TML_API void textmate_registry_dispose ( TextMateRegistry  registry)

Free a registry and all its resources.

Parameters
registryValid registry handle (from textmate_registry_create()), or NULL (no-op)
Warning
Do not use registry after calling this function
All grammars loaded from this registry become invalid
Note
Safe to call with NULL

Definition at line 506 of file c_api.cpp.

◆ textmate_registry_get_color_map()

TML_API TextMateColorMap * textmate_registry_get_color_map ( TextMateRegistry  registry)

Get the color map from the registry after setting a theme.

Parameters
registryValid registry handle
Returns
Pointer to color map on success, NULL if no theme is set
Note
The foreground/background IDs in encoded token metadata are indices into this map
The returned result must be freed with textmate_free_color_map()
See also
textmate_registry_set_theme()

Definition at line 613 of file c_api.cpp.

References TextMateColorMap::colorCount, and textmate_free_color_map().

◆ textmate_registry_load_grammar()

TML_API TextMateGrammar textmate_registry_load_grammar ( TextMateRegistry  registry,
const char *  scopeName 
)

Load a grammar by scope name.

Parameters
registryValid registry handle
scopeNameScope name of the grammar to load (e.g., "source.javascript", "text.html.markdown")
Returns
Grammar handle on success, NULL if grammar not found or registration failed
Note
Automatically resolves grammar dependencies and includes
The grammar must have been previously registered with textmate_registry_add_grammar_*()
See also
textmate_registry_add_grammar_from_file(), textmate_registry_add_grammar_from_json()

Definition at line 642 of file c_api.cpp.

◆ textmate_registry_set_injections()

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.

Parameters
registryValid registry handle
scopeNameScope to inject grammars into (e.g., "source.js string.quoted.single")
injectionsArray of grammar scope names to inject
injectionCountNumber of injections in the array
Note
Call before loading the target grammar to take effect
Allows embedding one grammar within another (e.g., regex highlighting in string literals)

Definition at line 568 of file c_api.cpp.

◆ textmate_registry_set_theme()

TML_API int textmate_registry_set_theme ( TextMateRegistry  registry,
const char *  themeJsonContent 
)

Set the color theme on the registry.

Parameters
registryValid registry handle
themeJsonContentTheme JSON content as a null-terminated string (TextMate theme format)
Returns
Non-zero on success, 0 on error (invalid JSON, etc.)
Note
Must be called before tokenizeLine2 to get meaningful themed tokens
See also
textmate_tokenize_line2(), textmate_tokenize_line2_utf16()

Definition at line 593 of file c_api.cpp.