@@ -85,7 +85,7 @@ namespace pl::gen::fmt {
8585 if (pattern->getVisibility () == ptrn::Visibility::TreeHidden) return ;
8686
8787 if (pattern->isSealed ()) {
88- formatString (pattern);
88+ formatValue (pattern);
8989 } else {
9090 addLine (pattern->getVariableName ());
9191 pushIndent ();
@@ -110,19 +110,36 @@ namespace pl::gen::fmt {
110110 addLine (pattern->getVariableName (), ::fmt::format (" \" {}\" " , hlp::encodeByteString ({ result.begin (), result.end () })));
111111 }
112112
113- void formatValue (pl::ptrn::Pattern *pattern) {
114- if (pattern->getVisibility () == ptrn::Visibility::Hidden) return ;
115- if (pattern->getVisibility () == ptrn::Visibility::TreeHidden) return ;
116-
117- auto result = pattern->toString ();
113+ std::string formatLiteral (const core::Token::Literal &literal) {
114+ auto result = std::visit (wolv::util::overloaded {
115+ [&](integral auto value) -> std::string { return ::fmt::format (" {}" , value); },
116+ [&](std::floating_point auto value) -> std::string { return ::fmt::format (" {}" , value); },
117+ [&](const std::string &value) -> std::string { return ::fmt::format (" \" {}\" " , value); },
118+ [&](bool value) -> std::string { return value ? " true" : " false" ; },
119+ [&](char value) -> std::string { return ::fmt::format (" \" {}\" " , value); },
120+ [&](const std::shared_ptr<ptrn::Pattern> &value) -> std::string { return ::fmt::format (" \" {}\" " , value->toString ()); },
121+ }, literal);
118122
119123 const bool number = std::ranges::all_of (result, [](char c) { return std::isdigit (c) || c == ' .' || c == ' -' || c == ' +' ; });
120124 const bool needsEscape = std::ranges::any_of (result, [](char c) { return std::ispunct (c) || !std::isprint (c); });
121125
122126 if (!number && needsEscape)
123- formatString (pattern) ;
127+ return result ;
124128 else
125- addLine (pattern->getVariableName (), wolv::util::replaceStrings (result, " \n " , " " ));
129+ return wolv::util::replaceStrings (result, " \n " , " " );
130+ }
131+
132+ void formatValue (pl::ptrn::Pattern *pattern) {
133+ if (pattern->getVisibility () == ptrn::Visibility::Hidden) return ;
134+ if (pattern->getVisibility () == ptrn::Visibility::TreeHidden) return ;
135+
136+ if (!pattern->getReadFormatterFunction ().empty ())
137+ formatString (pattern);
138+ else {
139+ auto literal = pattern->getValue ();
140+
141+ addLine (pattern->getVariableName (), wolv::util::replaceStrings (formatLiteral (literal), " \n " , " " ));
142+ }
126143 }
127144
128145 private:
0 commit comments