Skip to content

Commit

Permalink
Add formatter for Prism node types
Browse files Browse the repository at this point in the history
When ENFORCE macros fail, they use fmt (via spdlog) to format error messages.
Add a formatter specialization for pm_node_type to properly display Prism node
types in these error messages. Instead of showing numeric values, the formatter
uses pm_node_type_to_str to display human-readable node type names.
  • Loading branch information
egiurleo authored and st0012 committed Jan 21, 2025
1 parent 6f85f66 commit a4c9ea7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions parser/prism/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ extern "C" {
#include "prism.h"
}

template <> struct fmt::formatter<pm_node_type> : formatter<const char *> {
auto format(pm_node_type type, format_context &ctx) const {
return formatter<const char *>::format(pm_node_type_to_str(type), ctx);
}
};

namespace sorbet::parser::Prism {

// This templated `PrismNodeTypeHelper` type and its specializations work as a lookup-table that associates
Expand Down

0 comments on commit a4c9ea7

Please sign in to comment.