Skip to content

feat: add STRINGIFY() builtin macro#268

Merged
aspizu merged 5 commits into
mainfrom
feat-stringify
May 26, 2026
Merged

feat: add STRINGIFY() builtin macro#268
aspizu merged 5 commits into
mainfrom
feat-stringify

Conversation

@aspizu

@aspizu aspizu commented Mar 23, 2026

Copy link
Copy Markdown
Owner

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
Copy Markdown
Contributor

What is this actually meant to be used for?

@aspizu

aspizu commented Mar 23, 2026

Copy link
Copy Markdown
Owner Author

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".

@aspizu aspizu merged commit 33f0fe8 into main May 26, 2026
7 checks passed
@aspizu aspizu deleted the feat-stringify branch May 26, 2026 17:54
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