TextMateLib 1.0
Modern C++ implementation of the TextMate syntax highlighting engine
Loading...
Searching...
No Matches
basicScopesAttributeProvider.h
1#ifndef TEXTMATELIB_BASIC_SCOPES_ATTRIBUTE_PROVIDER_H
2#define TEXTMATELIB_BASIC_SCOPES_ATTRIBUTE_PROVIDER_H
3
4#include "types.h"
5#include "utils.h"
6#include <string>
7#include <map>
8#include <vector>
9#include <regex>
10
11namespace tml {
12
13// BasicScopeAttributes class
14class BasicScopeAttributes {
15public:
16 int languageId;
18
19 BasicScopeAttributes() : languageId(0), tokenType() {}
20 BasicScopeAttributes(int languageId_, OptionalStandardTokenType tokenType_);
21};
22
23// ScopeMatcher template class
24template<typename TValue>
25class ScopeMatcher {
26private:
27 std::map<std::string, TValue> values;
28 std::regex* scopesRegExp;
29 bool hasValues;
30
31public:
32 ScopeMatcher(const std::vector<std::pair<std::string, TValue>>& valuesList);
33 ~ScopeMatcher();
34
35 TValue* match(const ScopeName& scope);
36};
37
38// BasicScopeAttributesProvider class
39class BasicScopeAttributesProvider {
40private:
41 BasicScopeAttributes _defaultAttributes;
42 ScopeMatcher<int>* _embeddedLanguagesMatcher;
43 CachedFn<ScopeName, BasicScopeAttributes>* _getBasicScopeAttributesCache;
44
45 static std::regex STANDARD_TOKEN_TYPE_REGEXP;
46 static BasicScopeAttributes NULL_SCOPE_METADATA;
47
48public:
49 BasicScopeAttributesProvider(int initialLanguageId, const EmbeddedLanguagesMap* embeddedLanguages);
50 ~BasicScopeAttributesProvider();
51
52 BasicScopeAttributes getDefaultAttributes() const;
53 BasicScopeAttributes getBasicScopeAttributes(const ScopeName* scopeName);
54
55private:
56 int _scopeToLanguage(const ScopeName& scope);
57 OptionalStandardTokenType _toStandardTokenType(const ScopeName& scopeName);
58};
59
60} // namespace tml
61
62#endif // TEXTMATELIB_BASIC_SCOPES_ATTRIBUTE_PROVIDER_H
std::string ScopeName
Semantic name identifying a scope (e.g., "source.javascript", "comment.line")
Definition types.h:20
std::map< std::string, int > EmbeddedLanguagesMap
Map from embedded language name to token type ID.
Definition types.h:175
OptionalStandardTokenType
Standard token type with optional (unknown) state.
Definition types.h:145
Core type definitions and interfaces for TextMateLib.