1#ifndef TEXTMATELIB_REGISTRY_H
2#define TEXTMATELIB_REGISTRY_H
17class BalancedBracketSelectors;
20class IGrammarRepository {
22 virtual ~IGrammarRepository() {}
23 virtual IRawGrammar* lookup(
const ScopeName& scopeName) = 0;
24 virtual std::vector<ScopeName> injections(
const ScopeName& scopeName) = 0;
30 virtual ~IThemeProvider() {}
31 virtual StyleAttributes* themeMatch(ScopeStack* scopePath) = 0;
32 virtual StyleAttributes* getDefaults() = 0;
36class SyncRegistry :
public IGrammarRepository,
public IThemeProvider {
38 std::map<ScopeName, Grammar*> _grammars;
39 std::map<ScopeName, IRawGrammar*> _rawGrammars;
40 std::map<ScopeName, std::vector<ScopeName>> _injectionGrammars;
45 SyncRegistry(Theme* theme, IOnigLib* onigLib);
49 void setTheme(Theme* theme);
50 std::vector<std::string> getColorMap();
53 void addGrammar(IRawGrammar* grammar,
const std::vector<ScopeName>* injectionScopeNames =
nullptr);
56 IRawGrammar* lookup(
const ScopeName& scopeName)
override;
57 std::vector<ScopeName> injections(
const ScopeName& scopeName)
override;
60 StyleAttributes* themeMatch(ScopeStack* scopePath)
override;
61 StyleAttributes* getDefaults()
override;
64 Grammar* grammarForScopeName(
69 BalancedBracketSelectors* balancedBracketSelectors
74struct RegistryOptions {
77 std::vector<std::string>* colorMap;
78 std::function<IRawGrammar*(
const ScopeName&)> loadGrammar;
79 std::function<std::vector<ScopeName>(
const ScopeName&)> getInjections;
82 : onigLib(nullptr), theme(nullptr), colorMap(nullptr) {}
86struct IGrammarConfiguration {
89 std::vector<std::string>* balancedBracketSelectors;
90 std::vector<std::string>* unbalancedBracketSelectors;
92 IGrammarConfiguration()
93 : embeddedLanguages(nullptr), tokenTypes(nullptr),
94 balancedBracketSelectors(nullptr), unbalancedBracketSelectors(nullptr) {}
100 RegistryOptions _options;
101 SyncRegistry* _syncRegistry;
102 std::map<std::string, bool> _ensureGrammarCache;
105 explicit Registry(
const RegistryOptions& options);
111 void setTheme(
const IRawTheme* theme,
const std::vector<std::string>* colorMap =
nullptr);
114 std::vector<std::string> getColorMap();
117 Grammar* loadGrammarWithEmbeddedLanguages(
124 Grammar* loadGrammarWithConfiguration(
127 const IGrammarConfiguration& configuration
131 Grammar* loadGrammar(
const ScopeName& initialScopeName);
135 IRawGrammar* rawGrammar,
136 const std::vector<std::string>& injections = std::vector<std::string>(),
137 int initialLanguage = 0,
142 Grammar* _loadGrammar(
147 BalancedBracketSelectors* balancedBracketSelectors
150 void _loadSingleGrammar(
const ScopeName& scopeName);
151 void _doLoadSingleGrammar(
const ScopeName& scopeName);
153 Grammar* _grammarForScopeName(
155 int initialLanguage = 0,
158 BalancedBracketSelectors* balancedBracketSelectors =
nullptr
std::string ScopeName
Semantic name identifying a scope (e.g., "source.javascript", "comment.line")
std::map< std::string, int > EmbeddedLanguagesMap
Map from embedded language name to token type ID.
std::map< std::string, StandardTokenType > TokenTypeMap
Map from scope pattern to standard token type.
Core type definitions and interfaces for TextMateLib.