TextMateLib 1.0
Modern C++ implementation of the TextMate syntax highlighting engine
Loading...
Searching...
No Matches
tml.h
Go to the documentation of this file.
1#ifndef TEXTMATELIB_TML_H
2#define TEXTMATELIB_TML_H
3
4/**
5 * @file tml.h
6 * @brief Comprehensive public API header for TextMateLib
7 *
8 * This header includes all necessary components for using TextMateLib in C++ applications.
9 * It provides a single point of inclusion for:
10 * - Core types and interfaces
11 * - Grammar processing and tokenization
12 * - Theme and styling
13 * - Registry and grammar management
14 * - Session API for stateful tokenization
15 * - Syntax highlighting utilities
16 * - Regex engine interface
17 * - Token encoding and attributes
18 */
19
20// ============================================================================
21// Core Type Definitions
22// ============================================================================
23#include "types.h" // Core types, interfaces, and enums
24
25// ============================================================================
26// Regex and Pattern Matching
27// ============================================================================
28#include "onigLib.h" // Oniguruma regex engine wrapper
29#include "matcher.h" // Pattern matching utilities
30
31// ============================================================================
32// Grammar Processing Pipeline
33// ============================================================================
34#include "rawGrammar.h" // Raw grammar data structures (JSON-based)
35#include "parseRawGrammar.h" // JSON grammar parser
36#include "rule.h" // Individual grammar rules
37#include "grammarDependencies.h" // Grammar dependency resolution
38#include "grammar.h" // Compiled grammar with rule matching
39
40// ============================================================================
41// Tokenization
42// ============================================================================
43#include "tokenizeString.h" // Core tokenization logic and state transitions
44#include "encodedTokenAttributes.h" // Token encoding and attribute management
45
46// ============================================================================
47// Session API (Stateful Tokenization)
48// ============================================================================
49#include "session.h" // High-level stateful editor session with caching
50
51// ============================================================================
52// Theme and Styling
53// ============================================================================
54#include "theme.h" // Theme parsing and color/style application
55#include "basicScopesAttributeProvider.h" // Scope-to-attribute mapping
56
57// ============================================================================
58// Registry and Management
59// ============================================================================
60#include "registry.h" // Central grammar/theme manager and lookup
61
62// ============================================================================
63// Syntax Highlighting Convenience
64// ============================================================================
65#include "syntax_highlighter.h" // High-level convenience wrapper combining grammar + theme
66
67// ============================================================================
68// Utilities
69// ============================================================================
70#include "utils.h" // Helper functions and utilities
71
72namespace tml {
73
74/// @defgroup cpp_api C++ Public API
75/// @{
76/// Main public API for C++ applications using TextMateLib.
77/// These type aliases and constants provide the core components for syntax highlighting.
78
79/// @defgroup core_types Core Types and Interfaces
80/// Fundamental types for grammar management, tokenization state, and token representation.
81
82/// @brief Central registry for managing grammars and themes
83/// @ingroup core_types
84/// @see Registry, RegistryOptions
85using tml::Registry;
86
87/// @brief Configuration options for the registry
88/// @ingroup core_types
89/// @see Registry
90using tml::RegistryOptions;
91
92/// @brief Interface for customizing grammar configuration behavior
93/// @ingroup core_types
94/// @see Grammar
95using tml::IGrammarConfiguration;
96
97/// @brief Compiled grammar representation for tokenization
98/// @ingroup core_types
99/// @details Grammar objects handle rule matching and token generation.
100/// Created by Registry::loadGrammar() after registering grammar definitions.
101/// @see Grammar, Registry
102using tml::Grammar;
103
104/// @brief Abstract interface for grammar implementations
105/// @ingroup core_types
106/// @see Grammar
107using tml::IGrammar;
108
109/// @brief Immutable parsing state representing position in a grammar rule hierarchy
110/// @ingroup core_types
111/// @details StateStack encapsulates the parsing state at the end of a line.
112/// Two StateStacks that are equal() indicate the same parsing position,
113/// enabling incremental tokenization optimizations.
114/// @see ITokenizeLineResult::ruleStack
115using tml::StateStack;
116
117/// @brief Single token with scope information
118/// @ingroup core_types
119/// @details Represents a region of text with its associated scope hierarchy.
120/// @see ITokenizeLineResult
121using tml::IToken;
122
123/// @brief Result of tokenizing a single line
124/// @ingroup core_types
125/// @details Contains tokens and the state to continue on the next line.
126/// @see Grammar::tokenizeLine()
127using tml::ITokenizeLineResult;
128
129/// @brief Result of tokenizing a line with encoded tokens
130/// @ingroup core_types
131/// @details More compact representation than ITokenizeLineResult.
132/// @see Grammar::tokenizeLine2()
133using tml::ITokenizeLineResult2;
134
135/// @brief Raw (uncompiled) grammar data structure from JSON parsing
136/// @ingroup core_types
137/// @see parseRawGrammar()
138using tml::IRawGrammar;
139
140/// @brief Raw (uncompiled) theme data structure from JSON parsing
141/// @ingroup core_types
142/// @see Theme
143using tml::IRawTheme;
144
145/// @brief Interface to the Oniguruma regex engine
146/// @ingroup core_types
147/// @details Handles pattern matching for rule evaluation during tokenization.
148using tml::IOnigLib;
149
150/// @brief Default Oniguruma implementation
151/// @ingroup core_types
152/// @see Registry
153using tml::DefaultOnigLib;
154
155/// @defgroup grammar_processing Grammar Processing
156/// Grammar definition parsing and compilation utilities.
157
158/// @brief Parse a TextMate grammar from raw JSON data
159/// @ingroup grammar_processing
160/// @see Grammar, Registry
161using tml::parseRawGrammar;
162
163/// @defgroup tokenization Tokenization and Tokens
164/// Tokenization results and token attribute encoding.
165
166/// @brief Single token with scope information
167/// @ingroup tokenization
168/// @details Maps a text range to a scope hierarchy for styling.
169using tml::IToken;
170
171/// @brief Compact 32-bit encoding of token attributes
172/// @ingroup tokenization
173/// @details Used in ITokenizeLineResult2 for space-efficient token representation.
175
176/// @defgroup session_api Session API
177/// @{
178/// Stateful incremental tokenization with line caching for editor integration.
179///
180/// **Types:**
181/// - SessionImpl - High-level session manager for incremental document tokenization
182/// - SessionLine - Represents a cached line in the session
183/// - SessionMetadata - Metadata and statistics for a session
184
185/// @brief High-level session manager for incremental document tokenization
186/// @details Handles line-by-line tokenization with automatic state caching
187/// and early stopping optimization. Ideal for editor integration.
188/// @see SessionLine, SessionMetadata
189using tml::SessionImpl;
190
191/// @brief Represents a cached line in the session
192/// @see SessionImpl
193using tml::SessionLine;
194
195/// @brief Metadata and statistics for a session
196/// @see SessionImpl
197using tml::SessionMetadata;
198
199/// @}
200
201/// @defgroup theme_api Theme and Styling
202/// Theme parsing and scope-to-color mapping.
203
204/// @brief Theme containing scope-to-color-and-style mappings
205/// @ingroup theme_api
206/// @details Applies colors and font styles to tokens based on their scopes.
207/// Created by loading a TextMate theme definition.
208using tml::Theme;
209
210/// @defgroup utilities Utilities
211/// @{
212/// Helper utilities for pattern matching and operations.
213///
214/// **Types:**
215/// - Matcher - Pattern matching utilities and cache
216
217/// @brief Pattern matching utilities and cache
218/// @details Used internally for regex pattern caching and optimization.
219using tml::Matcher;
220
221/// @}
222
223/// @defgroup syntax_highlighting Syntax Highlighting Convenience API
224/// @{
225/// High-level syntax highlighting combining grammar + theme + caching.
226///
227/// **Types:**
228/// - SyntaxHighlighter - High-level API combining grammar, theme, and session
229/// - HighlightedToken - Single highlighted token with computed style attributes
230/// - HighlightedLine - Result of highlighting a single line
231/// - HighlighterCache - Cache for highlighted lines
232
233/// @brief High-level API combining grammar, theme, and session
234/// @details Provides a convenient single point for tokenization and styling.
235/// Automatically handles state management and caching.
236using tml::SyntaxHighlighter;
237
238/// @brief Single highlighted token with computed style attributes
239/// @see SyntaxHighlighter, HighlightedLine
240using tml::HighlightedToken;
241
242/// @brief Result of highlighting a single line
243/// @details Contains tokens with computed foreground/background colors and styles.
244/// @see SyntaxHighlighter
245using tml::HighlightedLine;
246
247/// @brief Cache for highlighted lines
248/// @details Optimizes repeated highlighting of unchanged lines.
249/// @see SyntaxHighlighter
250using tml::HighlighterCache;
251
252/// @}
253
254/// @defgroup constants Constants and Initialization
255/// Global constants and initialization functions.
256
257/// @brief Initial parsing state for the first line of a document
258/// @ingroup constants
259/// @details Used as the prevState argument when tokenizing the first line
260/// of any document. Read-only; do not delete.
261extern const StateStack* INITIAL;
262
263/// @}
264
265} // namespace tml
266
267#endif // TEXTMATELIB_TML_H
Abstract interface representing the parsing state at the end of a line.
Definition types.h:55
const StateStack * INITIAL
Initial parsing state for the first line of a document.
Definition main.cpp:6
int32_t EncodedTokenAttributes
Compact 32-bit encoding of a token's attributes.
Definition types.h:128
Core type definitions and interfaces for TextMateLib.