hyperion::assert::highlight#

group highlight

This module provides an API for setting and querying hyperion::assert’s syntax highlighting, powered by libfmt styling functionality, as well functionality to syntax highlight arbitrary strings containing C++ code in a libfmt-compatible way.

Example#

constexpr auto keyword_color = hyperion::assert::highlight::Color(0xC67ADA_u32);
constexpr auto keyword_highlight = hyperion::assert::highlight::Highlight {
    .kind = hyperion::assert::tokens::Keyword{},
    .color = keyword_color,
};
hyperion::assert::highlight::register_highlight(keyword_highlight);
highlighted = hyperion::assert::highlight::highlight("auto my_cpp_code = 42;");

Functions

auto highlight(std::string_view str, bool first_token_is_function = false) -> std::string#

Highlights the given string in a way compatible with libfmt’s styling functionality, according to the currently configured highlighting style, and returns the result as a new std::string

Parameters:
  • str – the string to do syntax highlighting on

  • first_token_is_function – Whether the first token in the given string is known to represent a function (to prevent it from being highlighted as a variable)

Returns:

The syntax highlighted string

auto register_highlight(const Highlight &_highlight)#

Registers the given syntax highlighting setting in hyperion::assert’s syntax highlighting configuration.

Parameters:

_highlight – The syntax highlighting setting to register

auto register_highlight(Highlight &&_highlight)#

Registers the given syntax highlighting setting in hyperion::assert’s syntax highlighting configuration.

Parameters:

_highlight – The syntax highlighting setting to register

auto register_highlights(const std::vector<Highlight> &highlights)#

Registers the given syntax highlighting settings in hyperion::assert’s syntax highlighting configuration.

Parameters:

highlights – The syntax highlighting settings to register

auto register_highlights(std::vector<Highlight> &&highlights)#

Registers the given syntax highlighting settings in hyperion::assert’s syntax highlighting configuration.

Parameters:

highlights – The syntax highlighting settings to register

auto get_color(const tokens::Kind &kind) noexcept -> Color#

Returns the syntax highlighting color currently registered in hyperion::assert’s syntax highlighting configuration.

Parameters:

kind – The token kind to get the registered highlight color for

Returns:

The registered color syntax highlight color for kind

struct RgbColor#
#include <hyperion/assert/highlight.h>

RgbColor represents a red-green-blue color, typically defined as a six-digit hexadecimal number (e.g. 0x61AFEF)

Public Functions

inline explicit(false) const expr RgbColor(const u32 hex) noexcept#

Constructs an RgbColor from a six-digit hex number.

Parameters:

hex – the six-digit hex number representing the red, green, and blue color values

inline  explicit (false) const expr RgbColor(const fmt

Constructs an RgbColor from a libfmt fmt::color type.

Parameters:

color – the color

inline constexpr RgbColor(const u8 _red, const u8 _green, const u8 _blue) noexcept#

Constructs an RgbColor from individual red, green, and blue color values.

Parameters:
  • _red – the red value

  • _green – the green value

  • _blue – the blue value

inline explicit(false) const expr operator u32() const noexcept#

Implicit conversion operator for RgbColor to its numeric representation.

Returns:

the numeric representation of this RgbColor

explicit(false) const expr operator fmt constexpr auto operator== (const RgbColor &other) const noexcept -> bool=default

Implicit conversion operator for RgbColor to the corresponding libfmt fmt::detail::color_type representation.

three-way comparison operator for RgbColor

s

equality comparison operator for

RgbColors

Returns:

the libfmt representation of this RgbColor

Returns:

how this RgbColor orders relative to other

Returns:

whether this RgbColor is equal to other

class Color#
#include <hyperion/assert/highlight.h>

Color represents either a red-green-blue color value (i.e. an RgbColor), typically defined as a six-digit hexadecimal number (e.g. 0x61AFEF), OR a libfmt terminal emulator color value (i.e. fmt::terminal_color)

Public Functions

constexpr Color() noexcept = default#

Default constructs a Color as pure white.

inline explicit(false) const expr Color(const RgbColor color) noexcept#

Constructs a Color as the given RgbColor value.

Parameters:

color – The RgbColor value to construct this Color as

inline  explicit (false) const expr Color(const fmt

Constructs a Color as the given libfmt fmt::terminal_color value.

Parameters:

color – The fmt::terminal_color value to construct this Color as

inline explicit(false) const expr Color(const u32 rgb_hex) noexcept#

Constructs a Color as the given red-blue-green color.

Parameters:

rgb_hex – The red-blue-green color to construct this Color as, represented as a 6-digit hexadecimal number

inline constexpr auto is_term_color() const noexcept#

Returns whether this Color represents a terminal emulator color.

Returns:

whether this Color represents a libfmt terminal emulator color, i.e. a fmt::terminal_color

inline constexpr auto term_color() const noexcept -> std::optional<fmt::terminal_color>#

Returns the libfmt terminal color this Color represents, if it represents one.

Returns:

the fmt::terminal_color this Color represents, or std::nullopt if it doesn’t represent an fmt::terminal_color

inline constexpr auto is_rgb_color() const noexcept#

Returns whether this Color represents an RgbColor

Returns:

whether this Color represents an RgbColor

inline constexpr auto rgb_color() const noexcept -> std::optional<RgbColor>#

Returns the RgbColor this Color represents, if it represents one.

Returns:

the RgbColor this Color represents, or std::nullopt if it doesn’t represent an RgbColor

union storage#
#include <highlight.h>

implicit conversion operator for Color to the corresponding libfmt fmt::detail::color_type representation

three-way comparison operator for Colors

    When `this` and `other` represent different types of colors
    (i.e. `this->is_term_color() != other.is_term_color()`),
    `this` is defined to compare as less than `other` when both of
    `this->is_term_color()` and `other.is_rgb_color()` are true,
    and vice versa

    @return how this `Color` orders relative to `other`

equality comparison operator for Colors

    When `this` and `other` represent the same type of color
    (i.e. `this->is_term_color() == other.is_term_color()`),
    returns the result of directly comparing the color values
    they represent. Otherwise, returns `false`.

    @return whether this `Color` is equal to `other`

storage implementation for Color

Return:

the libfmt color type representation of this Color

Public Functions

inline explicit(false) const expr storage(const RgbColor color) noexcept#
inline  explicit (false) const expr storage(const fmt

Public Members

RgbColor rgb_color = 0xFFFFFF_u32#
fmt::terminal_color term_color#
struct Highlight#
#include <hyperion/assert/highlight.h>

Highlight represents the syntax highlighting configuration for a specific token kind

Public Members

tokens::Kind kind#

The token kind this highlight configuration is for.

Color color#

The color tokens of kind should be highlighted as.