Skip to content

Implement macro parameter substitution in statement contexts #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2025

Conversation

jserv
Copy link
Collaborator

@jserv jserv commented Aug 2, 2025

This enables function-like macros with statement bodies that reference macro parameters.

Examples now supported:

  • ASSIGN_MACRO(variable, val) → variable = variable + val + 10
  • COMPOUND_ASSIGN(variable, val) → variable += val + 10
  • SET_VAR(var, value) → var = value

Implementation uses find_macro_param_src_idx() with careful lexer state management to safely substitute parameter values in statement parsing contexts, matching existing expression context functionality.

Close #142

Summary by Bito

This pull request enhances the macro system by implementing parameter substitution in statement contexts and introducing new macros like ASSIGN_MACRO and COMPOUND_ASSIGN. Comprehensive tests have been added to ensure the functionality and robustness of these features.

This enables function-like macros with statement bodies that reference
macro parameters.

Examples now supported:
- ASSIGN_MACRO(variable, val) → variable = variable + val + 10
- COMPOUND_ASSIGN(variable, val) → variable += val + 10
- SET_VAR(var, value) → var = value

Implementation uses find_macro_param_src_idx() with careful lexer  state
management to safely substitute parameter values in statement  parsing
contexts, matching existing expression context functionality.

Close #142
@jserv jserv merged commit 351a058 into master Aug 3, 2025
12 checks passed
@jserv jserv deleted the parse-macro branch August 3, 2025 16:51
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.

Unable to parse the specific macros
2 participants