TextMateLib 1.0
Modern C++ implementation of the TextMate syntax highlighting engine
Loading...
Searching...
No Matches
tokenizeString.h
1#ifndef TEXTMATELIB_TOKENIZE_STRING_H
2#define TEXTMATELIB_TOKENIZE_STRING_H
3
4#include "types.h"
5#include "onigLib.h"
6#include "rule.h"
7#include <vector>
8
9namespace tml {
10
11// Forward declarations
12class Grammar;
13class StateStackImpl;
14class LineTokens;
15class AttributedScopeStack;
16class BeginEndRule;
17class BeginWhileRule;
18class MatchRule;
19struct Injection;
20
21// StackElement result structure
22struct StackElement {
23 StateStackImpl* stack;
24 int linePos;
25 int anchorPosition;
26 bool stoppedEarly;
27
28 StackElement()
29 : stack(nullptr), linePos(0), anchorPosition(0), stoppedEarly(false) {}
30};
31
32// Match result structure
33struct IMatchResult {
34 std::vector<IOnigCaptureIndex> captureIndices;
35 RuleId matchedRuleId;
36
37 IMatchResult() : matchedRuleId(ruleIdFromNumber(0)) {}
38};
39
40// Match injections result structure
41struct IMatchInjectionsResult {
42 bool priorityMatch;
43 std::vector<IOnigCaptureIndex> captureIndices;
44 RuleId matchedRuleId;
45
46 IMatchInjectionsResult() : priorityMatch(false), matchedRuleId(ruleIdFromNumber(0)) {}
47};
48
49// While check result structure
50struct IWhileCheckResult {
51 StateStackImpl* stack;
52 int linePos;
53 int anchorPosition;
54 bool isFirstLine;
55
56 IWhileCheckResult()
57 : stack(nullptr), linePos(0), anchorPosition(-1), isFirstLine(false) {}
58};
59
60// LocalStackElement for capture handling
61class LocalStackElement {
62public:
63 AttributedScopeStack* scopes;
64 int endPos;
65
66 LocalStackElement(AttributedScopeStack* scopes_, int endPos_)
67 : scopes(scopes_), endPos(endPos_) {}
68};
69
70// Main tokenization function
71StackElement tokenizeString(
72 Grammar* grammar,
73 OnigString* lineText,
74 bool isFirstLine,
75 int linePos,
76 StateStackImpl* stack,
77 LineTokens* lineTokens,
78 bool checkWhileConditions,
79 int timeLimit
80);
81
82// Helper functions
83IWhileCheckResult _checkWhileConditions(
84 Grammar* grammar,
85 OnigString* lineText,
86 bool isFirstLine,
87 int linePos,
88 StateStackImpl* stack,
89 LineTokens* lineTokens
90);
91
92IMatchResult* matchRuleOrInjections(
93 Grammar* grammar,
94 OnigString* lineText,
95 bool isFirstLine,
96 int linePos,
97 StateStackImpl* stack,
98 int anchorPosition
99);
100
101IMatchResult* matchRule(
102 Grammar* grammar,
103 OnigString* lineText,
104 bool isFirstLine,
105 int linePos,
106 StateStackImpl* stack,
107 int anchorPosition
108);
109
110IMatchInjectionsResult* matchInjections(
111 const std::vector<Injection>& injections,
112 Grammar* grammar,
113 OnigString* lineText,
114 bool isFirstLine,
115 int linePos,
116 StateStackImpl* stack,
117 int anchorPosition
118);
119
120void handleCaptures(
121 Grammar* grammar,
122 OnigString* lineText,
123 bool isFirstLine,
124 StateStackImpl* stack,
125 LineTokens* lineTokens,
126 const std::vector<CaptureRule*>& captures,
127 const std::vector<IOnigCaptureIndex>& captureIndices
128);
129
130} // namespace tml
131
132#endif // TEXTMATELIB_TOKENIZE_STRING_H
RuleId ruleIdFromNumber(int id)
Convert an integer to a RuleId.
Definition types.h:109
Core type definitions and interfaces for TextMateLib.