Skip to content

feat: add STRINGIFY() builtin macro#268

Open
aspizu wants to merge 2 commits intomainfrom
feat-stringify
Open

feat: add STRINGIFY() builtin macro#268
aspizu wants to merge 2 commits intomainfrom
feat-stringify

Conversation

@aspizu
Copy link
Owner

@aspizu aspizu commented Mar 23, 2026

Summary

Adds a new builtin function-like macro STRINGIFY() to the preprocessor.

Behaviour

STRINGIFY(expr) expands to a string literal whose contents are the space-joined token text of the argument expression, before any further macro expansion (similar to C's # stringification operator).

Example

%define MY_VAR 42
say STRINGIFY(MY_VAR + 1);   // produces the string "MY_VAR + 1"

Implementation

  • Added substitute_stringify method in src/pre_processor.rs, modelled after the existing substitute_concat.
  • Hooked it into the process loop alongside substitute_concat.

STRINGIFY(expr) turns any macro argument into a string token
containing the space-joined text of the argument tokens.

Modelled after substitute_concat; handles nested parentheses.
Example:
  %define X 42
  say STRINGIFY(X + 1);  // => "X + 1"
@faretek1
Copy link

What is this actually meant to be used for?

@aspizu
Copy link
Owner Author

aspizu commented Mar 23, 2026

This is primarily intended for use in testing macros. For example, a TEST(expr) macro could use STRINGIFY to include the original expression text in its output message, so TEST(A+B) could print smth like "Assertion failed: A+B".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants