|
@@ -5,6 +5,8 @@
|
5
|
5
|
#include "cmMem.h"
|
6
|
6
|
#include "cmMallocDebug.h"
|
7
|
7
|
#include "cmData.h"
|
|
8
|
+#include "cmLex.h"
|
|
9
|
+#include "cmStack.h"
|
8
|
10
|
|
9
|
11
|
cmDtRC_t _cmDataErrNo = kOkDtRC;
|
10
|
12
|
|
|
@@ -2061,7 +2063,10 @@ cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, unsigned errRC, ... )
|
2061
|
2063
|
|
2062
|
2064
|
|
2063
|
2065
|
|
2064
|
|
-//----------------------------------------------------------------------------
|
|
2066
|
+//============================================================================
|
|
2067
|
+//============================================================================
|
|
2068
|
+//============================================================================
|
|
2069
|
+
|
2065
|
2070
|
unsigned _cmDataSerializeNodeByteCount( const cmData_t* p )
|
2066
|
2071
|
{
|
2067
|
2072
|
unsigned n = 0;
|
|
@@ -2173,6 +2178,226 @@ cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp
|
2173
|
2178
|
return kOkDtRC;
|
2174
|
2179
|
}
|
2175
|
2180
|
|
|
2181
|
+//============================================================================
|
|
2182
|
+//============================================================================
|
|
2183
|
+//============================================================================
|
|
2184
|
+#ifdef NOT_DEF
|
|
2185
|
+enum
|
|
2186
|
+{
|
|
2187
|
+ kLCurlyLexTId = kUserLexTId + 1,
|
|
2188
|
+ kRCurlyLexTId,
|
|
2189
|
+ kLParenLexTId,
|
|
2190
|
+ kRParenLexTId,
|
|
2191
|
+ kLBrackLexTId,
|
|
2192
|
+ kRBrackLexTId,
|
|
2193
|
+ kColonLexTId,
|
|
2194
|
+ kCommaLexTId,
|
|
2195
|
+};
|
|
2196
|
+
|
|
2197
|
+typedef struct
|
|
2198
|
+{
|
|
2199
|
+ unsigned id;
|
|
2200
|
+ const cmChar_t* label;
|
|
2201
|
+} cmDtToken_t;
|
|
2202
|
+
|
|
2203
|
+cmDtToken_t _cmDtTokenArray[] =
|
|
2204
|
+{
|
|
2205
|
+ { kLCurlyLexTId, "{" },
|
|
2206
|
+ { kRCurlyLexTId, "}" },
|
|
2207
|
+ { kLBrackLexTId, "[" },
|
|
2208
|
+ { kRBrackLexTId, "]" },
|
|
2209
|
+ { kLParenLexTId, "(" },
|
|
2210
|
+ { kRParenLexTId, ")" },
|
|
2211
|
+ { kColonLexTId, ":" },
|
|
2212
|
+ { kCommaLexTId, "," },
|
|
2213
|
+ { kErrorLexTId,""}
|
|
2214
|
+
|
|
2215
|
+};
|
|
2216
|
+
|
|
2217
|
+typedef struct
|
|
2218
|
+{
|
|
2219
|
+ cmErr_t err;
|
|
2220
|
+ cmLexH lexH;
|
|
2221
|
+ cmStackH_t stH;
|
|
2222
|
+
|
|
2223
|
+} cmDataParser_t;
|
|
2224
|
+
|
|
2225
|
+typedef struct
|
|
2226
|
+{
|
|
2227
|
+ unsigned tokId;
|
|
2228
|
+} cmDataStEle_t;
|
|
2229
|
+
|
|
2230
|
+cmDataParserH_t cmDataParserNullHandle = cmSTATIC_NULL_HANDLE;
|
|
2231
|
+
|
|
2232
|
+cmDataParser_t* _cmDataParserHandleToPtr( cmDataParserH_t h )
|
|
2233
|
+{
|
|
2234
|
+ cmDataParser_t* p = (cmDataParser_t*)h.h;
|
|
2235
|
+ assert( p!= NULL );
|
|
2236
|
+ return p;
|
|
2237
|
+}
|
|
2238
|
+
|
|
2239
|
+cmDtRC_t _cmDataParserDestroy( cmDataParser_t* p )
|
|
2240
|
+{
|
|
2241
|
+ if( cmLexFinal(&p->lexH) != kOkLexRC )
|
|
2242
|
+ cmErrMsg(&p->err,kLexFailedDtRC,"Lexer release failed.");
|
|
2243
|
+
|
|
2244
|
+ if( cmStackFree(&p->stH) != kOkStRC )
|
|
2245
|
+ cmErrMsg(&p->err,kParserStackFailDtRC,"The data object parser stack release failed.");
|
|
2246
|
+
|
|
2247
|
+ return kOkDtRC;
|
|
2248
|
+}
|
|
2249
|
+
|
|
2250
|
+cmDtRC_t cmDataParserCreate( cmCtx_t* ctx, cmDataParserH_t* hp )
|
|
2251
|
+{
|
|
2252
|
+ cmDtRC_t rc;
|
|
2253
|
+ unsigned i;
|
|
2254
|
+
|
|
2255
|
+ if((rc = cmDataParserDestroy(hp)) != kOkDtRC )
|
|
2256
|
+ return rc;
|
|
2257
|
+
|
|
2258
|
+ cmDataParser_t* p = cmMemAllocZ(cmDataParser_t,1);
|
|
2259
|
+
|
|
2260
|
+ cmErrSetup(&p->err,&ctx->err,"Data Parser");
|
|
2261
|
+
|
|
2262
|
+ if(cmLexIsValid(p->lexH = cmLexInit(NULL,0,0,err->rpt))==false)
|
|
2263
|
+ {
|
|
2264
|
+ rc = cmErrMsg(err, kLexFailDtRC, "The data object parser lexer create failed.");
|
|
2265
|
+ goto errLabel;
|
|
2266
|
+ }
|
|
2267
|
+
|
|
2268
|
+ for(i=0; cmDtTokeyArray[i].id!=kErrorLexTId; ++i)
|
|
2269
|
+ if( cmLexRegisterToken(p->lexH, cmDtTokenArray[i].id, cmDtTokenArray[i].label) != kOkLexRC )
|
|
2270
|
+ {
|
|
2271
|
+ rc = cmErrMsg(&p->err,kLexFailDtRC,"The data object parser lexer could not register the '%s' token.",cmDtTokenArray[i].label);
|
|
2272
|
+ goto errLabel;
|
|
2273
|
+ }
|
|
2274
|
+
|
|
2275
|
+ if( cmStackAlloc(ctx, &p->stH, 1024, 1024, sizeof(cmDataStEle_t)) != kOkStRC )
|
|
2276
|
+ {
|
|
2277
|
+ rc = cmErrMsg(&p->err,kParseStackFailDtRC,"The data object parser stack create failed.");
|
|
2278
|
+ goto errLabel;
|
|
2279
|
+ }
|
|
2280
|
+
|
|
2281
|
+ hp->h = p;
|
|
2282
|
+
|
|
2283
|
+ errLabel:
|
|
2284
|
+ if( rc != kOkDtRC )
|
|
2285
|
+ _cmDataParserDestroy(p);
|
|
2286
|
+
|
|
2287
|
+ return kOkDtRC;
|
|
2288
|
+}
|
|
2289
|
+
|
|
2290
|
+cmDtRC_t cmDataParserDestroy( cmErr_t* err, cmDataParserH_t* hp )
|
|
2291
|
+{
|
|
2292
|
+ cmDtRC_t rc=kOkDtRC;
|
|
2293
|
+
|
|
2294
|
+ if( hp==NULL || cmDataParserIsValid(*hp)==false )
|
|
2295
|
+ return rc;
|
|
2296
|
+
|
|
2297
|
+ cmDataParser_t* p = _cmDataParserHandleToPtr(*hp);
|
|
2298
|
+
|
|
2299
|
+ if((rc = _cmDataParserDestroy(p)) != kOkDtRC )
|
|
2300
|
+ return rc;
|
|
2301
|
+
|
|
2302
|
+ hp->h = NULL;
|
|
2303
|
+
|
|
2304
|
+ return kOkDtRC;
|
|
2305
|
+}
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+bool cmDataParserIsValid( cmDataParserH_t h )
|
|
2309
|
+{ return h.h != NULL; }
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+cmDtRC_t _cmDataLexErrorV( cmErr_t* err, cmLexH_t lexH, const cmChar_t* fmt, va_list vl )
|
|
2313
|
+{
|
|
2314
|
+
|
|
2315
|
+}
|
|
2316
|
+
|
|
2317
|
+cmDtRC_t _cmDataLexError( cmErr_t* err, cmLexH_t lexH, const cmChar_t* fmt, ... )
|
|
2318
|
+{
|
|
2319
|
+ va_list vl;
|
|
2320
|
+ va_start(vl,fmt);
|
|
2321
|
+ cmDtRC_t rc, _cmDataLexErrorV(err,lexH,fmt,vl);
|
|
2322
|
+ va_end(vl);
|
|
2323
|
+ return rc;
|
|
2324
|
+}
|
|
2325
|
+
|
|
2326
|
+// {
|
|
2327
|
+// id0 : scalar_value
|
|
2328
|
+// id1 : ( heterogenous, array, value )
|
|
2329
|
+// id2 : [ homogeneous array values ]
|
|
2330
|
+// id3 :
|
|
2331
|
+// }
|
|
2332
|
+
|
|
2333
|
+enum
|
|
2334
|
+{
|
|
2335
|
+ kRecdStateId,
|
|
2336
|
+ kFieldValueStateId,
|
|
2337
|
+ kArrayValueStateId
|
|
2338
|
+};
|
|
2339
|
+
|
|
2340
|
+cmDtRC_t cmDataParserExec( cmDataParserH_t h, const cmChar_t* text, cmData_t** pp )
|
|
2341
|
+{
|
|
2342
|
+ cmDtRC_t rc = kOkDtRC;
|
|
2343
|
+ unsigned tokenId;
|
|
2344
|
+
|
|
2345
|
+ cmDataParser_t* p = _cmDataParserHandleToPtr(h);
|
|
2346
|
+ cmData_t* d = cmRecdAlloc(NULL);
|
|
2347
|
+
|
|
2348
|
+
|
|
2349
|
+ if( cmLexSetTextBuffer(p->lexH,text,strlen(text)) != kOkLexRC )
|
|
2350
|
+ return cmErrMsg(&p->err,kLexFailDtRC,"The data object lexer failed during reset.");
|
|
2351
|
+
|
|
2352
|
+ while((tokenId = cmLexGetNextToken(p->lexH)) != kEofLexTId )
|
|
2353
|
+ {
|
|
2354
|
+ case kRealLexTId: // real number (contains a decimal point or is in scientific notation)
|
|
2355
|
+ break;
|
|
2356
|
+
|
|
2357
|
+ case kIntLexTId: // decimal integer
|
|
2358
|
+ break;
|
|
2359
|
+
|
|
2360
|
+ case kHexLexTId: // hexidecimal integer
|
|
2361
|
+ break;
|
|
2362
|
+
|
|
2363
|
+ case kIdentLexTId: // identifier
|
|
2364
|
+ break;
|
|
2365
|
+
|
|
2366
|
+ case kQStrLexTId: // quoted string
|
|
2367
|
+ break;
|
|
2368
|
+
|
|
2369
|
+ case kLCurlyLexTId
|
|
2370
|
+ case kRCurlyLexTId:
|
|
2371
|
+ case kLParenLexTId:
|
|
2372
|
+ case kRParenLexTId:
|
|
2373
|
+ case kLBrackLexTId:
|
|
2374
|
+ case kRBrackLexTId:
|
|
2375
|
+ case kColonLexTId:
|
|
2376
|
+ case kCommaLexTId:
|
|
2377
|
+
|
|
2378
|
+
|
|
2379
|
+ case kBlockCmtLexTId: // block comment
|
|
2380
|
+ case kLineCmtLexTId: // line comment
|
|
2381
|
+ case kErrorLexTId: // the lexer was unable to identify the current token
|
|
2382
|
+ case kUnknownLexTId: // the token is of an unknown type (only used when kReturnUnknownLexFl is set)
|
|
2383
|
+ case kEofLexTId: // the lexer reached the end of input
|
|
2384
|
+ case kSpaceLexTId: // white space
|
|
2385
|
+ {
|
|
2386
|
+ rc = cmErrMsg(err,kLexFailDtRC,"The data object lexer failed with an unexpected token '%s' on line '%i'.",cmLexIdToLabel(lexH,tokenId),cmLexCurrentLineNumber(lexH));
|
|
2387
|
+ goto errLabel;
|
|
2388
|
+ }
|
|
2389
|
+
|
|
2390
|
+ }
|
|
2391
|
+
|
|
2392
|
+ errLabel:
|
|
2393
|
+ return rc;
|
|
2394
|
+}
|
|
2395
|
+
|
|
2396
|
+#endif
|
|
2397
|
+//============================================================================
|
|
2398
|
+//============================================================================
|
|
2399
|
+//============================================================================
|
|
2400
|
+
|
2176
|
2401
|
#define parr(rpt,fmt,arr,n) do{int i=0; cmRptPrintf(rpt,"[ "); for(;i<n;++i) cmRptPrintf(rpt,fmt,arr[i]); cmRptPrintf(rpt," ]"); }while(0)
|
2177
|
2402
|
|
2178
|
2403
|
void _cmDataPrintIndent( cmRpt_t* rpt, unsigned indent )
|