CE Macro.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /******************************************************************************/
  2. #if EE_PRIVATE
  3. namespace Edit{
  4. /******************************************************************************/
  5. struct Macro
  6. {
  7. struct Part
  8. {
  9. TOKEN_TYPE type;
  10. Int param; // -1 if not param, >=0 if should be replaced with 'param' param
  11. BStr text;
  12. void set(TOKEN_TYPE type, Int param, BStr *text) {T.type=type; T.param=param; if(text)T.text=*text;}
  13. Bool save(File &f)C
  14. {
  15. f.putMulti(type, param).putStr(text.asStr());
  16. return true;
  17. }
  18. Bool load(File &f)
  19. {
  20. f.getMulti(type, param); text.setCustom(f.getStr());
  21. return true;
  22. }
  23. Part() {type=TOKEN_NONE; param=-1;}
  24. };
  25. Bool all_up_case, use_for_suggestions;
  26. Int params, // -1 if macro definition is not followed by (), 0 if is followed by (), 1 if (x), 2 if (x, y), ..
  27. line;
  28. Str name, def;
  29. Memc<Part> parts;
  30. Source *source;
  31. Bool operator==(CChar8 *name )C {return Equal(T.name, name, true);}
  32. Bool operator==(CChar *name )C {return Equal(T.name, name, true);}
  33. Bool operator==(C Macro &macro)C {return T==macro.name;}
  34. Macro& set(Token &token);
  35. Macro& set(C Str &name );
  36. Macro& reset() {params=-1; line=-1; parts.clear(); source=null; return T;}
  37. Bool save(File &f, StrLibrary &sl)C;
  38. Bool load(File &f, StrLibrary &sl, Str &temp);
  39. Macro() {all_up_case=false; use_for_suggestions=true; params=-1; line=-1; source=null;}
  40. };
  41. /******************************************************************************/
  42. } // namespace
  43. /******************************************************************************/
  44. inline Int CompareCS(C Edit::Macro &a, C Edit::Macro &b) {return CompareCS(a.name, b.name);}
  45. inline Int CompareCS(C Edit::Macro &a, C Str &b) {return CompareCS(a.name, b );}
  46. inline Int CompareCS(C Edit::Macro &a, C BStr &b) {return CompareCS(a.name, b );}
  47. inline Int CompareCS(C Edit::Macro &a, CChar8*C &b) {return CompareCS(a.name, b );}
  48. /******************************************************************************/
  49. #endif
  50. /******************************************************************************/