#include #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::Transformer t(uc); t.Owned(); // Causes t to be released when it goes out of scope // 1. Define state variable in the uCalc instance. uc.DefineVariable("indent = 0"); // 2. Define the transformation rules. // Note: '{', '}', '[', ']' are escaped with quotes to be treated as literals. // Rule for '{' and '[': Add newline, increment indent, add indent string. t.FromTo("{ '{' | '[' }", "{@Self}{@nl}{@Exec: indent++}{@Eval: ' ' * indent}"); // Rule for '}' and ']': Add newline, decrement indent, add indent string. t.FromTo("{ '}' | ']' }", "{@nl}{@Exec: indent--}{@Eval: ' ' * indent}{@Self}"); // Rule for ',': Add newline and current indent string. t.FromTo(",", ",{@nl}{@Eval: ' ' * indent}"); // Rule for ':': Add a space after it for readability. t.FromTo(":", ": "); // 3. Define the minified input string. auto minifiedJson = R"({"id":123,"name":"Example","tags":["A","B"],"active":true})"; // 4. Run the transformation and print the result. cout << t.Transform(minifiedJson) << endl; } }