TODO: Multiline comments
| 116 | |
| 117 | // TODO: Multiline comments |
| 118 | void ZepSyntax::UpdateSyntax() { |
| 119 | auto& buffer = m_buffer.GetWorkingBuffer(); |
| 120 | auto itrCurrent = buffer.begin() + m_processedChar; |
| 121 | auto itrEnd = buffer.begin() + m_targetChar; |
| 122 | |
| 123 | assert(std::distance(itrCurrent, itrEnd) < int(m_syntax.size())); |
| 124 | assert(m_syntax.size() == buffer.size()); |
| 125 | |
| 126 | std::string delim; |
| 127 | std::string lineEnd("\n"); |
| 128 | |
| 129 | if (m_flags & ZepSyntaxFlags::LispLike) { |
| 130 | delim = std::string(" \t.\n(){}[]"); |
| 131 | } else { |
| 132 | delim = std::string(" \t.\n;(){}[]=:,!"); |
| 133 | } |
| 134 | |
| 135 | // Walk backwards to previous delimiter |
| 136 | while (itrCurrent > buffer.begin()) { |
| 137 | if (std::find(delim.begin(), delim.end(), *itrCurrent) == delim.end()) { |
| 138 | itrCurrent--; |
| 139 | } else { |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // Back to the previous line |
| 145 | while (itrCurrent > buffer.begin() && *itrCurrent != '\n') { |
| 146 | itrCurrent--; |
| 147 | } |
| 148 | itrEnd = buffer.find_first_of(itrEnd, buffer.end(), lineEnd.begin(), lineEnd.end()); |
| 149 | |
| 150 | // Mark a region of the syntax buffer with the correct marker |
| 151 | auto mark = [&](GapBuffer<uint8_t>::const_iterator itrA, GapBuffer<uint8_t>::const_iterator itrB, ThemeColor type, ThemeColor background) { |
| 152 | std::fill(m_syntax.begin() + (itrA - buffer.begin()), m_syntax.begin() + (itrB - buffer.begin()), SyntaxData{type, background}); |
| 153 | }; |
| 154 | |
| 155 | auto markSingle = [&](GapBuffer<uint8_t>::const_iterator itrA, ThemeColor type, ThemeColor background) { |
| 156 | (m_syntax.begin() + (itrA - buffer.begin()))->foreground = type; |
| 157 | (m_syntax.begin() + (itrA - buffer.begin()))->background = background; |
| 158 | }; |
| 159 | |
| 160 | // Update start location |
| 161 | m_processedChar = long(itrCurrent - buffer.begin()); |
| 162 | |
| 163 | // Walk the buffer updating information about syntax coloring |
| 164 | while (itrCurrent != itrEnd) { |
| 165 | if (m_stop == true) { |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | // Find a token, skipping delim <itrFirst, itrLast> |
| 170 | auto itrFirst = buffer.find_first_not_of(itrCurrent, buffer.end(), delim.begin(), delim.end()); |
| 171 | if (itrFirst == buffer.end()) |
| 172 | break; |
| 173 | |
| 174 | auto itrLast = buffer.find_first_of(itrFirst, buffer.end(), delim.begin(), delim.end()); |
| 175 |
nothing calls this directly
no test coverage detected