TextMateLib 1.0
Modern C++ implementation of the TextMate syntax highlighting engine
Loading...
Searching...
No Matches
encodedTokenAttributes.h
1#ifndef TEXTMATELIB_ENCODED_TOKEN_ATTRIBUTES_H
2#define TEXTMATELIB_ENCODED_TOKEN_ATTRIBUTES_H
3
4#include "types.h"
5#include <string>
6#include <cstdint>
7
8namespace tml {
9
10// Encoded token data constants
11namespace EncodedTokenDataConsts {
12 const int32_t LANGUAGEID_MASK = 0b00000000000000000000000011111111;
13 const int32_t TOKEN_TYPE_MASK = 0b00000000000000000000001100000000;
14 const int32_t BALANCED_BRACKETS_MASK = 0b00000000000000000000010000000000;
15 const int32_t FONT_STYLE_MASK = 0b00000000000000000111100000000000;
16 const int32_t FOREGROUND_MASK = 0b00000000111111111000000000000000;
17 const int32_t BACKGROUND_MASK = 0b11111111000000000000000000000000;
18
19 const int LANGUAGEID_OFFSET = 0;
20 const int TOKEN_TYPE_OFFSET = 8;
21 const int BALANCED_BRACKETS_OFFSET = 10;
22 const int FONT_STYLE_OFFSET = 11;
23 const int FOREGROUND_OFFSET = 15;
24 const int BACKGROUND_OFFSET = 24;
25}
26
27// Convert token type functions
28inline OptionalStandardTokenType toOptionalTokenType(StandardTokenType standardType) {
29 return static_cast<OptionalStandardTokenType>(static_cast<int>(standardType));
30}
31
32inline StandardTokenType fromOptionalTokenType(OptionalStandardTokenType standardType) {
33 return static_cast<StandardTokenType>(static_cast<int>(standardType));
34}
35
36// EncodedTokenAttributes namespace (equivalent to TypeScript namespace)
37namespace EncodedTokenAttributesHelper {
38 std::string toBinaryStr(EncodedTokenAttributes encodedTokenAttributes);
39
40 void print(EncodedTokenAttributes encodedTokenAttributes);
41
42 int getLanguageId(EncodedTokenAttributes encodedTokenAttributes);
43
44 StandardTokenType getTokenType(EncodedTokenAttributes encodedTokenAttributes);
45
46 bool containsBalancedBrackets(EncodedTokenAttributes encodedTokenAttributes);
47
48 int getFontStyle(EncodedTokenAttributes encodedTokenAttributes);
49
50 int getForeground(EncodedTokenAttributes encodedTokenAttributes);
51
52 int getBackground(EncodedTokenAttributes encodedTokenAttributes);
53
55 EncodedTokenAttributes encodedTokenAttributes,
56 int languageId,
58 bool* containsBalancedBrackets,
59 int fontStyle,
60 int foreground,
61 int background
62 );
63}
64
65} // namespace tml
66
67#endif // TEXTMATELIB_ENCODED_TOKEN_ATTRIBUTES_H
StandardTokenType
Standard TextMate token type for syntax classification.
Definition types.h:136
OptionalStandardTokenType
Standard token type with optional (unknown) state.
Definition types.h:145
int32_t EncodedTokenAttributes
Compact 32-bit encoding of a token's attributes.
Definition types.h:128
Core type definitions and interfaces for TextMateLib.