aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/minimacro.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unstable/minimacro.h212
1 files changed, 106 insertions, 106 deletions
diff --git a/src/unstable/minimacro.h b/src/unstable/minimacro.h
index dc38891..1c33ea4 100644
--- a/src/unstable/minimacro.h
+++ b/src/unstable/minimacro.h
@@ -13,118 +13,118 @@
13 13
14namespace Bu 14namespace Bu
15{ 15{
16 typedef Bu::Hash<Bu::String, Bu::String> StrHash; 16 typedef Bu::Hash<Bu::String, Bu::String> StrHash;
17 /** 17 /**
18 * A processor for Libbu++ brand Mini Macros. These are really simple, but 18 * A processor for Libbu++ brand Mini Macros. These are really simple, but
19 * still fairly flexible. It's mainly text replacement, but with a few 19 * still fairly flexible. It's mainly text replacement, but with a few
20 * extras like filter functions and conditional text segments. So far we 20 * extras like filter functions and conditional text segments. So far we
21 * don't support loops or anything, I'm not sure we ever will. 21 * don't support loops or anything, I'm not sure we ever will.
22 * 22 *
23 * Anatomy of a mini macro: 23 * Anatomy of a mini macro:
24 * - Every macro begins with a two character code, the first character is 24 * - Every macro begins with a two character code, the first character is
25 * always '{', the second character determines the operation to perform. 25 * always '{', the second character determines the operation to perform.
26 * - If the '{' is followed by a character that is not valid it is not 26 * - If the '{' is followed by a character that is not valid it is not
27 * considered for expansion and the characters are copied to the output. 27 * considered for expansion and the characters are copied to the output.
28 * - Every macro ends with a closing '}' 28 * - Every macro ends with a closing '}'
29 * - Macro types: 29 * - Macro types:
30 * - '=': variable replacement. The '=' is immediatley followed by the 30 * - '=': variable replacement. The '=' is immediatley followed by the
31 * name of the variable to replace, then any number of optional filter 31 * name of the variable to replace, then any number of optional filter
32 * segments. 32 * segments.
33 * - '?': conditional text. The '?' is immediately followed by the 33 * - '?': conditional text. The '?' is immediately followed by the
34 * variable to test. This works two ways, the variable can be alone, in 34 * variable to test. This works two ways, the variable can be alone, in
35 * which case it's existance is tested, or it can be followed by a "=" 35 * which case it's existance is tested, or it can be followed by a "="
36 * and a string to compare to. This is then followed by a text segment 36 * and a string to compare to. This is then followed by a text segment
37 * that will be used if the test is true, and an optional text segment 37 * that will be used if the test is true, and an optional text segment
38 * to be used if the test is false. 38 * to be used if the test is false.
39 * - ':': command. The ':' is immediately followed by a command string, 39 * - ':': command. The ':' is immediately followed by a command string,
40 * of which there's only one right now, but that's ok. These are not 40 * of which there's only one right now, but that's ok. These are not
41 * put into the output stream, but instead mark something for the 41 * put into the output stream, but instead mark something for the
42 * parser. Currently supported: 42 * parser. Currently supported:
43 * - {:end}: end of parsing, stop here, also make note of how many input 43 * - {:end}: end of parsing, stop here, also make note of how many input
44 * characters were used. 44 * characters were used.
45 * - Segments: 45 * - Segments:
46 * - Each segment is seperated by a colon. 46 * - Each segment is seperated by a colon.
47 * - Filter segments give the name of the filter, followed by 47 * - Filter segments give the name of the filter, followed by
48 * parenthesies. Parameters may be provided within the parenthesies. 48 * parenthesies. Parameters may be provided within the parenthesies.
49 * - Text segments should always be quoted, but may contain any characters 49 * - Text segments should always be quoted, but may contain any characters
50 * within the quotes, backslash is used as per C/ANSI/ISO standard. 50 * within the quotes, backslash is used as per C/ANSI/ISO standard.
51 * You can also quote any text using [' '] instead of quotes, which 51 * You can also quote any text using [' '] instead of quotes, which
52 * allows for nested strings. The [' token is only recognised within 52 * allows for nested strings. The [' token is only recognised within
53 * a macro. 53 * a macro.
54 * 54 *
55 *@verbatim 55 *@verbatim
56 {=name:tolower()} 56 {=name:tolower()}
57 {=name:ccsplit("_"):toupper()} 57 {=name:ccsplit("_"):toupper()}
58 {?name:"name exists and is {=name}"} 58 {?name:"name exists and is {=name}"}
59 {?name:"{=name}":"no name!"} 59 {?name:"{=name}":"no name!"}
60 {?name="bob":"You're named bob!":"Who are you? I only know bob..."} 60 {?name="bob":"You're named bob!":"Who are you? I only know bob..."}
61 @endverbatim 61 @endverbatim
62 */ 62 */
63 class MiniMacro 63 class MiniMacro
64 { 64 {
65 public: 65 public:
66 MiniMacro(); 66 MiniMacro();
67 MiniMacro( const StrHash &sVarSrc ); 67 MiniMacro( const StrHash &sVarSrc );
68 virtual ~MiniMacro(); 68 virtual ~MiniMacro();
69 69
70 Bu::String parse( const Bu::String &sIn ); 70 Bu::String parse( const Bu::String &sIn );
71 void addVar( const Bu::String &sName, const Bu::String &sValue ); 71 void addVar( const Bu::String &sName, const Bu::String &sValue );
72 bool hasVar( const Bu::String &sName ); 72 bool hasVar( const Bu::String &sName );
73 const Bu::String &getVar( const Bu::String &sName ); 73 const Bu::String &getVar( const Bu::String &sName );
74 const StrHash &getVars(); 74 const StrHash &getVars();
75 int getPosition(); 75 int getPosition();
76 76
77 private: 77 private:
78 const char *sCur; 78 const char *sCur;
79 Bu::String parseRepl(); 79 Bu::String parseRepl();
80 Bu::String parseCond(); 80 Bu::String parseCond();
81 Bu::String parseCmd(); 81 Bu::String parseCmd();
82 Bu::String callFunc( 82 Bu::String callFunc(
83 const Bu::String &sIn, const Bu::String &sFunc ); 83 const Bu::String &sIn, const Bu::String &sFunc );
84 84
85 StrHash hVars; 85 StrHash hVars;
86 bool bContinue; 86 bool bContinue;
87 int iLastPos; 87 int iLastPos;
88 88
89 public: 89 public:
90 typedef Bu::List<Bu::String> StrList; 90 typedef Bu::List<Bu::String> StrList;
91 class Func 91 class Func
92 { 92 {
93 public: 93 public:
94 Func(){} 94 Func(){}
95 virtual ~Func(){} 95 virtual ~Func(){}
96 virtual Bu::String call( 96 virtual Bu::String call(
97 const Bu::String &sIn, StrList &lsParam )=0; 97 const Bu::String &sIn, StrList &lsParam )=0;
98 }; 98 };
99 99
100 class FuncToUpper : public Func 100 class FuncToUpper : public Func
101 { 101 {
102 public: 102 public:
103 FuncToUpper(){} 103 FuncToUpper(){}
104 virtual ~FuncToUpper(){} 104 virtual ~FuncToUpper(){}
105 virtual Bu::String call( 105 virtual Bu::String call(
106 const Bu::String &sIn, StrList & ) 106 const Bu::String &sIn, StrList & )
107 { 107 {
108 return sIn.toUpper(); 108 return sIn.toUpper();
109 } 109 }
110 }; 110 };
111 111
112 class FuncToLower : public Func 112 class FuncToLower : public Func
113 { 113 {
114 public: 114 public:
115 FuncToLower(){} 115 FuncToLower(){}
116 virtual ~FuncToLower(){} 116 virtual ~FuncToLower(){}
117 virtual Bu::String call( 117 virtual Bu::String call(
118 const Bu::String &sIn, StrList & ) 118 const Bu::String &sIn, StrList & )
119 { 119 {
120 return sIn.toLower(); 120 return sIn.toLower();
121 } 121 }
122 }; 122 };
123 123
124 private: 124 private:
125 typedef Bu::Hash<Bu::String,class Func *> FuncHash; 125 typedef Bu::Hash<Bu::String,class Func *> FuncHash;
126 FuncHash hFuncs; 126 FuncHash hFuncs;
127 }; 127 };
128}; 128};
129 129
130#endif 130#endif