11#include <fmt/format.h>
12#include <libassert/assert.hpp>
13#include <range/v3/algorithm/contains.hpp>
14#include <range/v3/algorithm/find.hpp>
15#include <range/v3/algorithm/find_if.hpp>
16#include <range/v3/algorithm/fold_left.hpp>
17#include <range/v3/algorithm/transform.hpp>
18#include <range/v3/iterator/concepts.hpp>
19#include <range/v3/range/access.hpp>
20#include <range/v3/range/concepts.hpp>
21#include <range/v3/range/conversion.hpp>
22#include <range/v3/range/primitives.hpp>
23#include <range/v3/view/enumerate.hpp>
24#include <range/v3/view/join.hpp>
25#include <range/v3/view/split.hpp>
26#include <range/v3/view/split_when.hpp>
27#include <range/v3/view/transform.hpp>
36#include <system_error>
42using Option = std::pair<inspection::Token::Kind, fmt::text_style>;
56 std::function<fmt::text_style(std::string_view)>
style_fn;
60 std::string
apply(std::string_view str)
const;
65 std::string_view ident);
66 static fmt::text_style
style_op_keywords(fmt::text_style keyword_style, fmt::text_style default_style,
87 return token_opts.at(
static_cast<std::size_t
>(kind));
133std::string
render_blocks(std::string_view str,
bool skip_styling);
Definition syntax_highlighter.hpp:40
std::string render_blocks(std::string_view str, bool skip_styling)
Parses and renders literal blocks, returning a form meant for displaying to a console user,...
Definition syntax_highlighter.cpp:428
std::pair< inspection::Token::Kind, fmt::text_style > Option
Definition syntax_highlighter.hpp:42
Definition syntax_highlighter.hpp:51
std::function< fmt::text_style(std::string_view)> style_fn
Function to call to determine the style for a token kind with a specific string. May be null....
Definition syntax_highlighter.hpp:56
std::string apply(std::string_view str) const
Definition syntax_highlighter.cpp:37
std::function< std::string(std::string_view)> transform_fn
Function to call to transform a token string. May be null.
Definition syntax_highlighter.hpp:58
fmt::text_style style
Style for the token kind.
Definition syntax_highlighter.hpp:53
Definition syntax_highlighter.hpp:47
constexpr Opt & operator[](inspection::Token::Kind kind)
Definition syntax_highlighter.hpp:82
constexpr Opt & operator[](std::size_t idx)
Definition syntax_highlighter.hpp:80
static fmt::text_style style_basic_ident_types(fmt::text_style type_style, fmt::text_style default_style, std::string_view ident)
Custom styling functions for identifiers that are types (e.g., void, int, etc.)
Definition syntax_highlighter.cpp:52
static std::string basic_binary_op_spacing(std::string_view op)
Add spacing for binary ops.
Definition syntax_highlighter.cpp:74
constexpr const Opt & operator[](inspection::Token::Kind kind) const
Definition syntax_highlighter.hpp:86
constexpr const Opt & operator[](std::size_t idx) const
Definition syntax_highlighter.hpp:84
static Options get_default_options()
Definition syntax_highlighter.cpp:115
static std::string basic_op_spacing(std::string_view op)
Definition syntax_highlighter.cpp:95
static fmt::text_style style_op_keywords(fmt::text_style keyword_style, fmt::text_style default_style, std::string_view op)
Definition syntax_highlighter.cpp:63
std::array< Opt, num_token_kinds > token_opts
Each index is representative of the highlighting option for the token kind enumerator with a value ==...
Definition syntax_highlighter.hpp:78
static constexpr auto num_token_kinds
Definition syntax_highlighter.hpp:48
Token of a very basic C++ expression. The primary use case is for rudemtary console syntax coloring.
Definition expression_inspection.hpp:57
Kind
The kind of token.
Definition expression_inspection.hpp:73