MCPcopy Create free account
hub / github.com/crosire/reshade / colorize

Method colorize

source/imgui_code_editor.cpp:1897–2182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1895#include "effect_lexer.hpp"
1896
1897void reshade::imgui::code_editor::colorize()
1898{
1899 if (_colorize_line_beg >= _colorize_line_end)
1900 return;
1901
1902 // Step through code incrementally rather than coloring everything at once
1903 const size_t from = _colorize_line_beg, to = std::min(from + 1000, _colorize_line_end);
1904 _colorize_line_beg = to;
1905
1906 // Reset coloring range if we have finished coloring it after this iteration
1907 if (_colorize_line_end > _lines.size())
1908 _colorize_line_end = _lines.size();
1909 if (_colorize_line_beg == _colorize_line_end)
1910 {
1911 _colorize_line_beg = std::numeric_limits<size_t>::max();
1912 _colorize_line_end = 0;
1913 }
1914
1915 // Copy lines into string for consumption by the lexer (needs to use the same offsets as the indices in '_lines', so strip any unicode characters which are multi-byte)
1916 std::string input_string;
1917 for (size_t l = from; l < to && l < _lines.size(); ++l, input_string.push_back('\n'))
1918 for (size_t k = 0; k < _lines[l].size(); ++k)
1919 input_string += _lines[l][k].c < 0x80 ? static_cast<char>(_lines[l][k].c) : '?';
1920
1921 reshadefx::lexer lexer(
1922 std::move(input_string),
1923 false /* ignore_comments */,
1924 true /* ignore_whitespace */,
1925 false /* ignore_pp_directives */,
1926 true /* ignore_line_directives */,
1927 false /* ignore_keywords */,
1928 false /* escape_string_literals */);
1929
1930 for (reshadefx::token tok; (tok = lexer.lex()).id != reshadefx::tokenid::end_of_file;)
1931 {
1932 color col = color_default;
1933
1934 switch (tok.id)
1935 {
1936 case reshadefx::tokenid::exclaim:
1937 case reshadefx::tokenid::percent:
1938 case reshadefx::tokenid::ampersand:
1939 case reshadefx::tokenid::parenthesis_open:
1940 case reshadefx::tokenid::parenthesis_close:
1941 case reshadefx::tokenid::star:
1942 case reshadefx::tokenid::plus:
1943 case reshadefx::tokenid::comma:
1944 case reshadefx::tokenid::minus:
1945 case reshadefx::tokenid::dot:
1946 case reshadefx::tokenid::slash:
1947 case reshadefx::tokenid::colon:
1948 case reshadefx::tokenid::semicolon:
1949 case reshadefx::tokenid::less:
1950 case reshadefx::tokenid::equal:
1951 case reshadefx::tokenid::greater:
1952 case reshadefx::tokenid::question:
1953 case reshadefx::tokenid::bracket_open:
1954 case reshadefx::tokenid::backslash:

Callers 1

draw_gui_logMethod · 0.80

Calls 1

lexMethod · 0.80

Tested by

no test coverage detected