MCPcopy Create free account
hub / github.com/Rezonality/zep / UpdateSyntax

Method UpdateSyntax

src/syntax.cpp:145–333  ·  view source on GitHub ↗

TODO: Multiline comments

Source from the content-addressed store, hash-verified

143
144// TODO: Multiline comments
145void ZepSyntax::UpdateSyntax()
146{
147 auto& buffer = m_buffer.GetWorkingBuffer();
148 auto itrCurrent = buffer.begin() + m_processedChar;
149 auto itrEnd = buffer.begin() + m_targetChar;
150
151 assert(std::distance(itrCurrent, itrEnd) < int(m_syntax.size()));
152 assert(m_syntax.size() == buffer.size());
153
154 std::string delim;
155 std::string lineEnd("\n");
156
157 if (m_flags & ZepSyntaxFlags::LispLike)
158 {
159 delim = std::string(" \t.\n(){}[]");
160 }
161 else
162 {
163 delim = std::string(" \t.\n;(){}[]=:");
164 }
165
166 // Walk backwards to previous delimiter
167 while (itrCurrent > buffer.begin())
168 {
169 if (std::find(delim.begin(), delim.end(), *itrCurrent) == delim.end())
170 {
171 itrCurrent--;
172 }
173 else
174 {
175 break;
176 }
177 }
178
179 // Back to the previous line
180 while (itrCurrent > buffer.begin() && *itrCurrent != '\n')
181 {
182 itrCurrent--;
183 }
184 itrEnd = buffer.find_first_of(itrEnd, buffer.end(), lineEnd.begin(), lineEnd.end());
185
186 // Mark a region of the syntax buffer with the correct marker
187 auto mark = [&](GapBuffer<uint8_t>::const_iterator itrA, GapBuffer<uint8_t>::const_iterator itrB, ThemeColor type, ThemeColor background) {
188 std::fill(m_syntax.begin() + (itrA - buffer.begin()), m_syntax.begin() + (itrB - buffer.begin()), SyntaxData{ type, background });
189 };
190
191 auto markSingle = [&](GapBuffer<uint8_t>::const_iterator itrA, ThemeColor type, ThemeColor background) {
192 (m_syntax.begin() + (itrA - buffer.begin()))->foreground = type;
193 (m_syntax.begin() + (itrA - buffer.begin()))->background = background;
194 };
195
196 // Update start location
197 m_processedChar = long(itrCurrent - buffer.begin());
198
199 // Walk the buffer updating information about syntax coloring
200 while (itrCurrent != itrEnd)
201 {
202 if (m_stop == true)

Callers

nothing calls this directly

Calls 8

string_tolowerFunction · 0.85
find_first_ofMethod · 0.80
find_first_not_ofMethod · 0.80
findMethod · 0.80
distanceFunction · 0.50
beginMethod · 0.45
sizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected