equal
deleted
inserted
replaced
19 #include <iomanip> |
19 #include <iomanip> |
20 #include <sstream> |
20 #include <sstream> |
21 #include <iostream> |
21 #include <iostream> |
22 using namespace std; |
22 using namespace std; |
23 |
23 |
24 namespace CdlCompilerToolkit { |
24 namespace CdlCompilerToolkit |
|
25 { |
25 |
26 |
26 // |
27 // |
27 // SyntaxErr |
28 // SyntaxErr |
28 // |
29 // |
29 |
30 |
187 StripComments(line, iComment); |
188 StripComments(line, iComment); |
188 if (!line.empty()) |
189 if (!line.empty()) |
189 { |
190 { |
190 // add the line to the API buffer |
191 // add the line to the API buffer |
191 CdlTkUtil::AppendString(iApiBuf, line); |
192 CdlTkUtil::AppendString(iApiBuf, line); |
192 int pos; |
193 string::size_type pos; |
193 // extract API declarations from the API buffer, separated by semi-colons |
194 // extract API declarations from the API buffer, separated by semi-colons |
194 while ((pos = iApiBuf.find_first_of(';')) != string::npos) |
195 while ((pos = iApiBuf.find_first_of(';')) != string::npos) |
195 { |
196 { |
196 // extract API declaration from API buf and create API from it |
197 // extract API declaration from API buf and create API from it |
197 line = iApiBuf.substr(0, pos); |
198 line = iApiBuf.substr(0, pos); |
237 |
238 |
238 bool CCdlTkCdlFileParser::MatchLineStart(const string& aLine, const string& aHeader, string& aVal) |
239 bool CCdlTkCdlFileParser::MatchLineStart(const string& aLine, const string& aHeader, string& aVal) |
239 { |
240 { |
240 if (aLine.size() < aHeader.size() || aLine.substr(0, aHeader.size()) != aHeader) |
241 if (aLine.size() < aHeader.size() || aLine.substr(0, aHeader.size()) != aHeader) |
241 return false; |
242 return false; |
242 |
|
243 aVal = aLine.substr(aHeader.size()); |
243 aVal = aLine.substr(aHeader.size()); |
244 StripComments(aVal, iComment); |
244 StripComments(aVal, iComment); |
245 CdlTkUtil::StripLeadingAndTrailingWhitespace(aVal); |
245 CdlTkUtil::StripLeadingAndTrailingWhitespace(aVal); |
246 return true; |
246 return true; |
247 } |
247 } |
248 |
248 |
249 void CCdlTkCdlFileParser::StripComments(string& aStr, string& aComment) |
249 void CCdlTkCdlFileParser::StripComments(string& aStr, string& aComment) |
250 { |
250 { |
251 int pos = aStr.find(KCommentStart); |
251 string::size_type pos = aStr.find(KCommentStart); |
252 if (pos != string::npos) |
252 if (pos != string::npos) |
253 { |
253 { |
254 aComment += aStr.substr(pos) + "\n"; |
254 aComment += aStr.substr(pos) + "\n"; |
255 } |
255 } |
256 aStr = aStr.substr(0, pos); |
256 aStr = aStr.substr(0, pos); |
261 auto_ptr<CCdlTkApi> pApi; |
261 auto_ptr<CCdlTkApi> pApi; |
262 bool isFunc = (aLine[aLine.size()-1] == ')'); // function APIs end with ')', data APIs don't |
262 bool isFunc = (aLine[aLine.size()-1] == ')'); // function APIs end with ')', data APIs don't |
263 if (isFunc) |
263 if (isFunc) |
264 { |
264 { |
265 auto_ptr<CCdlTkFunctionApi> pFuncApi(new CCdlTkFunctionApi(aCdl)); |
265 auto_ptr<CCdlTkFunctionApi> pFuncApi(new CCdlTkFunctionApi(aCdl)); |
266 int paramStart = aLine.find('('); |
266 string::size_type paramStart = aLine.find('('); |
267 if (paramStart == string::npos) |
267 if (paramStart == string::npos) |
268 SyntaxError("function has missing '('"); |
268 SyntaxError("function has missing '('"); |
269 string params = aLine.substr(paramStart); |
269 string params = aLine.substr(paramStart); |
270 aLine = aLine.substr(0, paramStart); |
270 aLine = aLine.substr(0, paramStart); |
271 params = params.substr(1, params.size()-2); // -2 for opening and closing brackets |
271 params = params.substr(1, params.size()-2); // -2 for opening and closing brackets |
289 |
289 |
290 void CCdlTkCdlFileParser::ParseApiParams(CCdlTkApiParams& aParams, string& aList) |
290 void CCdlTkCdlFileParser::ParseApiParams(CCdlTkApiParams& aParams, string& aList) |
291 { |
291 { |
292 while (aList.size()) |
292 while (aList.size()) |
293 { |
293 { |
294 int pos = aList.find(','); |
294 string::size_type pos = aList.find(','); |
295 string param = aList.substr(0, pos); |
295 string param = aList.substr(0, pos); |
296 aList = aList.substr(param.size() + (pos == string::npos ? 0 : 1)); |
296 aList = aList.substr(param.size() + (pos == string::npos ? 0 : 1)); |
297 CdlTkUtil::StripLeadingAndTrailingWhitespace(aList); |
297 CdlTkUtil::StripLeadingAndTrailingWhitespace(aList); |
298 |
298 |
299 string name, type, defaultValue; |
299 string name, type, defaultValue; |
304 } |
304 } |
305 |
305 |
306 void CCdlTkCdlFileParser::ParseNameTypeAndDefaultValue(string& aStr, string& aName, string& aType, string& aDefaultValue) |
306 void CCdlTkCdlFileParser::ParseNameTypeAndDefaultValue(string& aStr, string& aName, string& aType, string& aDefaultValue) |
307 { |
307 { |
308 CdlTkUtil::StripLeadingAndTrailingWhitespace(aStr); |
308 CdlTkUtil::StripLeadingAndTrailingWhitespace(aStr); |
309 int eq = aStr.find_last_of(KEqualsSign); |
309 string::size_type eq = aStr.find_last_of(KEqualsSign); |
310 if(eq != string::npos) |
310 if(eq != string::npos) |
311 { |
311 { |
312 aDefaultValue = aStr.substr(eq + 1); |
312 aDefaultValue = aStr.substr(eq + 1); |
313 CdlTkUtil::StripLeadingAndTrailingWhitespace(aDefaultValue); |
313 CdlTkUtil::StripLeadingAndTrailingWhitespace(aDefaultValue); |
314 |
314 |
324 aType = aStr; |
324 aType = aStr; |
325 } |
325 } |
326 |
326 |
327 void CCdlTkCdlFileParser::ParseTranslationText(CCdlTkDataTypeTranslation& aTrans, string& aLine) |
327 void CCdlTkCdlFileParser::ParseTranslationText(CCdlTkDataTypeTranslation& aTrans, string& aLine) |
328 { |
328 { |
329 int pos1 = aLine.find('#'); |
329 string::size_type pos1 = aLine.find('#'); |
330 if (pos1 == string::npos) |
330 if (pos1 == string::npos) |
331 SyntaxError("First # not found"); |
331 SyntaxError("First # not found"); |
332 int pos2 = aLine.find('#', pos1+1); |
332 string::size_type pos2 = aLine.find('#', pos1+1); |
333 if (pos2 == string::npos) |
333 if (pos2 == string::npos) |
334 SyntaxError("Second # not found"); |
334 SyntaxError("Second # not found"); |
335 if (aLine.find('#', pos2+1) != string::npos) |
335 if (aLine.find('#', pos2+1) != string::npos) |
336 SyntaxError("Third # found"); |
336 SyntaxError("Third # found"); |
337 |
337 |