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 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 445 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 513 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 543 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 495 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 505 of file c_api.cpp.

◆ 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 592 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 567 of file c_api.cpp.