Macro: replace order bug(?)
See original GitHub issueThere some problem that short variables can to brake more long variables:
#def MACRO1$(Dx$; x$)
x$ + Dx$
#end def
#def MACRO2$(x$; Dx$)
x$ + Dx$
#end def
MACRO1$(10; 20)'shows 20+10=30
MACRO2$(10; 20)'Error in "10 + D10" on line [2]: Undefined variable or units: "D10".
I’m not shure is it bug or not, but can we replace variables from long to short order?
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Macro evaluation order [duplicate] - c++
An argument is macro-replaced before it is substituted into the replacement list, except where it appears as the operand of # (stringize) or...
Read more >Search & replace macro returns error
I'm trying to run what I thought was a simple search & replace macro in Word 2011, to replace manual line breaks with...
Read more >Replacing text macros
Object-like macros replace every occurrence of defined identifier with replacement-list. Version (1) of the #define directive behaves ...
Read more >Replacing text macros
Object-like macros replace every occurrence of a defined identifier with replacement-list. Version (1) of the #define directive behaves ...
Read more >PRE01-C. Use parentheses within macros around ...
Macro replacement lists should be parenthesized. Noncompliant Code Example. This CUBE() macro definition is noncompliant because it fails to parenthesize the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, It is a bug. Variables are parsed from longer to shorter. But for replacement, I simply used the string.Replace() method in C#, cycling through the parameter in their original order. The best way is to write custom replace method that does the job in just one pass, but it will take time.
Now, I can make a quick fix by preliminary sorting the parameters by their length - from longer to shorter and perform the replacement in this order.
Thanks! It works correctly now (so big problems not found at least)