Advertisement
sehe

macro expansion

Feb 21st, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. Macro expansion callback: http://ideone.com/aKLt9
  2.  
  3. Input:
  4. ==============================
  5.  
  6.     std::string input =
  7.         "Greeting is <<hello>> world!\n"
  8.         "Side effects are <<sideeffect>> and <<other>> vars are untouched\n"
  9.         "Empty <<>> macros are ok, as are stray '>>' pairs.\n"
  10.         "<<nested <<macros>> (<<hello>>?) work>>\n"
  11.         "The order of expansion (evaluation) is _eager_: '<<<<hello>>>>' will expand to the same as '<<bye>>'\n"
  12.         "Lastly you can do algorithmic stuff too: <<!esrever ~ni <<hello>>>>\n"
  13. #ifdef SUPPORT_ESCAPES // bonus: escapes
  14.         "You can escape \\<<hello>> (not expanded to '<<hello>>')\n"
  15.         "Demonstrate how it <<avoids <\\<nesting\\>> macros>>.\n"
  16. #endif
  17.         ;
  18.  
  19. Output:
  20. ==============================
  21.  
  22. this is a side effect while parsing
  23.  
  24. Greeting is bye world!
  25. Side effects are (done) and <<other>> vars are untouched
  26. Empty <<>> macros are ok, as are stray '>>' pairs.
  27. <<nested <<macros>> (bye?) work>>
  28. The order of expansion (evaluation) is _eager_: 'We meet again' will expand to the same as 'We meet again'
  29. Lastly you can do algorithmic stuff too: eyb in reverse!
  30. You can escape <<hello>> (not expanded to 'bye')
  31. Demonstrate how it <<avoids <<nesting>> macros>>.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement