Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed element end event in case of a complex content one child of interleave which isn't optional by quant but is because all of its constituents are optional.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tmp
Files: files | file ages | folders
SHA3-256: 4369e1130b28d5723d13257323611cc26c3dbe12da418bdc765cd3563aa86989
User & Date: rolf 2020-05-17 01:09:55
Context
2020-05-27
00:34
Integrated bug fix branch: Handling of not per quantifier but per all childs optional content particle. check-in: 32945e114c user: rolf tags: schema
2020-05-17
01:09
Fixed element end event in case of a complex content one child of interleave which isn't optional by quant but is because all of its constituents are optional. Closed-Leaf check-in: 4369e1130b user: rolf tags: tmp
2020-05-16
15:31
wip check-in: 8aa4152961 user: rolf tags: tmp
Changes

Changes to generic/schema.c.

845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
....
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
....
2215
2216
2217
2218
2219
2220
2221
2222

2223
2224
2225
2226
2227
2228

2229
2230
2231
2232
2233
2234
2235
....
2237
2238
2239
2240
2241
2242
2243

2244
2245
2246
2247
2248
2249
2250
....
2260
2261
2262
2263
2264
2265
2266

2267
2268
2269
2270
2271
2272
2273
....
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348



2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
    )
{
    SchemaCP *wrapperCP;
    SchemaCP *savedCP = NULL;
    unsigned int savedContenSize;

    if (sdata->cp->type == SCHEMA_CTYPE_CHOICE
         || sdata->cp->type == SCHEMA_CTYPE_INTERLEAVE) {
        if (pattern->type == SCHEMA_CTYPE_CHOICE) {
            if (pattern->flags & MIXED_CONTENT) {
                sdata->cp->flags |= MIXED_CONTENT;
            }
            wrapperCP = initSchemaCP (SCHEMA_CTYPE_PATTERN, NULL, NULL);
            REMEMBER_PATTERN (wrapperCP);
            wrapperCP->content[0] = pattern;
................................................................................
static int checkElementEnd (
    Tcl_Interp *interp,
    SchemaData *sdata
    )
{
    SchemaValidationStack *se;
    SchemaCP *cp, *ic;
    int hm, ac, i, thismayskip, rc;
    int isName = 0;

    DBG(fprintf (stderr, "checkElementEnd:\n");
        serializeStack(sdata););
    se = sdata->stack;
    getContext (cp, ac, hm);

    if (cp->type == SCHEMA_CTYPE_INTERLEAVE) {
        ac = 0; hm = 0;
    }
    switch (cp->type) {
    case SCHEMA_CTYPE_NAME:
        isName = 1;
        /* Fall through */
    case SCHEMA_CTYPE_INTERLEAVE:
    case SCHEMA_CTYPE_PATTERN:
................................................................................
        while (ac < cp->nc) {
            DBG(fprintf (stderr, "ac %d hm %d mayMiss: %d\n",
                         ac, hm, mayMiss (cp->quants[ac])));
            if (se->interleaveState) {
                if (se->interleaveState[ac]) {
                    ac++; continue;
                }
            } else {

                if (mayMiss (cp->quants[ac])) {
                    ac++; continue;
                }
            }
            switch (cp->content[ac]->type) {
            case SCHEMA_CTYPE_KEYSPACE_END:

                cp->content[ac]->keySpace->active--;
                if (!cp->content[ac]->keySpace->active) {
                    if (cp->content[ac]->keySpace->unknownIDrefs) {
                        if (!recover (interp, sdata, INVALID_KEYREF_MATCH_END,
                                      NULL, NULL,
                                      cp->content[ac]->keySpace->name, 0)) {
                            return 0;
................................................................................
                        cp->content[ac]->keySpace->unknownIDrefs = 0;
                    }
                    Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids);
                }
                break;

            case SCHEMA_CTYPE_KEYSPACE:

                if (!cp->content[ac]->keySpace->active) {
                    Tcl_InitHashTable (&cp->content[ac]->keySpace->ids,
                                       TCL_STRING_KEYS);
                    cp->content[ac]->keySpace->active = 1;
                    cp->content[ac]->keySpace->unknownIDrefs = 0;
                } else {
                    cp->content[ac]->keySpace->active++;
................................................................................
                        }
                        return 0;
                    }
                }
                break;

            case SCHEMA_CTYPE_CHOICE:

                thismayskip = 0;
                for (i = 0; i < cp->content[ac]->nc; i++) {
                    if (mayMiss (cp->content[ac]->quants[i])) {
                        thismayskip = 1;
                        break;
                    }
                    ic = cp->content[ac]->content[i];
................................................................................
                
            case SCHEMA_CTYPE_VIRTUAL:
                if (evalVirtual (interp, sdata, ac)) break;
                else return 0;
                
            case SCHEMA_CTYPE_PATTERN:
                if (recursivePattern (se, cp->content[ac])) {
                    thismayskip = 1;
                    break;
                }
                /* fall throu */
            case SCHEMA_CTYPE_INTERLEAVE:
                pushToStack (sdata, cp->content[ac]);
                rc = checkElementEnd (interp, sdata);
                popStack (sdata);
                if (rc) break;
                if (!recover (interp, sdata, MISSING_ELEMENT_MATCH_END, NULL,
                              NULL, NULL, 0)) {
                    return 0;
                }
                break;
                
            case SCHEMA_CTYPE_ANY:
            case SCHEMA_CTYPE_NAME:
                if (recover (interp, sdata, MISSING_ELEMENT_MATCH_END, NULL,
                             NULL, NULL, 0)) {
                    break;
                }
                return 0;
            }
            ac++;
        }



        if (isName) return 1;
        return -1;

    case SCHEMA_CTYPE_KEYSPACE_END:
    case SCHEMA_CTYPE_KEYSPACE:
    case SCHEMA_CTYPE_VIRTUAL:
    case SCHEMA_CTYPE_CHOICE:
    case SCHEMA_CTYPE_TEXT:
    case SCHEMA_CTYPE_ANY:
        /* Never pushed onto stack */
        Tcl_Panic ("Invalid CTYPE onto the validation stack!");

    case SCHEMA_CTYPE_INTERLEAVE:
        for (i = 0; i < cp->nc; i++) {
            if (mustMatch (cp->quants[i], se->interleaveState[i])) {
                if (recover (interp, sdata, MISSING_ELEMENT_MATCH_END, NULL,
                             NULL, NULL, 0)) {
                    break;
                }
                return 0;
            }
        }
        return -1;
    }
    /* Not reached */
    return 0;
}

static int
checkDocKeys (







|







 







|








|







 







<
>
|
|
<



>







 







>







 







>







 







<








|
|
|

|



|
|






>
>
>












<
<
<
<
<
<
<
<
<
<
<







845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
....
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
....
2215
2216
2217
2218
2219
2220
2221

2222
2223
2224

2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
....
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
....
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
....
2319
2320
2321
2322
2323
2324
2325

2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364











2365
2366
2367
2368
2369
2370
2371
    )
{
    SchemaCP *wrapperCP;
    SchemaCP *savedCP = NULL;
    unsigned int savedContenSize;

    if (sdata->cp->type == SCHEMA_CTYPE_CHOICE
        || sdata->cp->type == SCHEMA_CTYPE_INTERLEAVE) {
        if (pattern->type == SCHEMA_CTYPE_CHOICE) {
            if (pattern->flags & MIXED_CONTENT) {
                sdata->cp->flags |= MIXED_CONTENT;
            }
            wrapperCP = initSchemaCP (SCHEMA_CTYPE_PATTERN, NULL, NULL);
            REMEMBER_PATTERN (wrapperCP);
            wrapperCP->content[0] = pattern;
................................................................................
static int checkElementEnd (
    Tcl_Interp *interp,
    SchemaData *sdata
    )
{
    SchemaValidationStack *se;
    SchemaCP *cp, *ic;
    int hm, ac, i, thismayskip, mayskip = 0, rc;
    int isName = 0;

    DBG(fprintf (stderr, "checkElementEnd:\n");
        serializeStack(sdata););
    se = sdata->stack;
    getContext (cp, ac, hm);

    if (cp->type == SCHEMA_CTYPE_INTERLEAVE) {
        ac = 0; hm = 0; mayskip = 1;
    }
    switch (cp->type) {
    case SCHEMA_CTYPE_NAME:
        isName = 1;
        /* Fall through */
    case SCHEMA_CTYPE_INTERLEAVE:
    case SCHEMA_CTYPE_PATTERN:
................................................................................
        while (ac < cp->nc) {
            DBG(fprintf (stderr, "ac %d hm %d mayMiss: %d\n",
                         ac, hm, mayMiss (cp->quants[ac])));
            if (se->interleaveState) {
                if (se->interleaveState[ac]) {
                    ac++; continue;
                }

            }
            if (mayMiss (cp->quants[ac])) {
                ac++; continue;

            }
            switch (cp->content[ac]->type) {
            case SCHEMA_CTYPE_KEYSPACE_END:
                /* Don't happen as INTERLEAVE child */
                cp->content[ac]->keySpace->active--;
                if (!cp->content[ac]->keySpace->active) {
                    if (cp->content[ac]->keySpace->unknownIDrefs) {
                        if (!recover (interp, sdata, INVALID_KEYREF_MATCH_END,
                                      NULL, NULL,
                                      cp->content[ac]->keySpace->name, 0)) {
                            return 0;
................................................................................
                        cp->content[ac]->keySpace->unknownIDrefs = 0;
                    }
                    Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids);
                }
                break;

            case SCHEMA_CTYPE_KEYSPACE:
                /* Don't happen as INTERLEAVE child */
                if (!cp->content[ac]->keySpace->active) {
                    Tcl_InitHashTable (&cp->content[ac]->keySpace->ids,
                                       TCL_STRING_KEYS);
                    cp->content[ac]->keySpace->active = 1;
                    cp->content[ac]->keySpace->unknownIDrefs = 0;
                } else {
                    cp->content[ac]->keySpace->active++;
................................................................................
                        }
                        return 0;
                    }
                }
                break;

            case SCHEMA_CTYPE_CHOICE:
                /* Don't happen as INTERLEAVE child */
                thismayskip = 0;
                for (i = 0; i < cp->content[ac]->nc; i++) {
                    if (mayMiss (cp->content[ac]->quants[i])) {
                        thismayskip = 1;
                        break;
                    }
                    ic = cp->content[ac]->content[i];
................................................................................
                
            case SCHEMA_CTYPE_VIRTUAL:
                if (evalVirtual (interp, sdata, ac)) break;
                else return 0;
                
            case SCHEMA_CTYPE_PATTERN:
                if (recursivePattern (se, cp->content[ac])) {

                    break;
                }
                /* fall throu */
            case SCHEMA_CTYPE_INTERLEAVE:
                pushToStack (sdata, cp->content[ac]);
                rc = checkElementEnd (interp, sdata);
                popStack (sdata);
                if (rc) break;
                if (recover (interp, sdata, MISSING_ELEMENT_MATCH_END,
                             NULL, NULL, NULL, 0)) {
                    break;
                }
                return 0;
                
            case SCHEMA_CTYPE_ANY:
            case SCHEMA_CTYPE_NAME:
                if (recover (interp, sdata, MISSING_ELEMENT_MATCH_END,
                             NULL, NULL, NULL, 0)) {
                    break;
                }
                return 0;
            }
            ac++;
        }
        if (se->interleaveState) {
            if (!mayskip) return 0;
        }
        if (isName) return 1;
        return -1;

    case SCHEMA_CTYPE_KEYSPACE_END:
    case SCHEMA_CTYPE_KEYSPACE:
    case SCHEMA_CTYPE_VIRTUAL:
    case SCHEMA_CTYPE_CHOICE:
    case SCHEMA_CTYPE_TEXT:
    case SCHEMA_CTYPE_ANY:
        /* Never pushed onto stack */
        Tcl_Panic ("Invalid CTYPE onto the validation stack!");












    }
    /* Not reached */
    return 0;
}

static int
checkDocKeys (

Changes to tests/schema.test.

6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
....
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
....
6417
6418
6419
6420
6421
6422
6423


6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
....
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
....
6489
6490
6491
6492
6493
6494
6495





































6496
6497
6498
6499
6500
6501
6502
    } {
        lappend result [s validate $xml errMsg]
    }
    s delete
    set result
} {1 1 0}

test schema-16.17 {interleave with all content cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            element c ?
        }
................................................................................
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 1 1 1 1 1 0 1}

test schema-16.18 {interleave with all content cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            choice {
                element c ?
................................................................................
        <doc><b/></doc>
        <doc><c/></doc>
        <doc><a/><c/></doc>
        <doc><b/><c/></doc>
        <doc><c/><a/></doc>
        <doc><c/><a/><b/><d/></doc>
        <doc><c/><a/><b/></doc>


    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 1 1 1 1 1 1 0 1}

test schema-16.19 {interleave with all content cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            choice {
                element c ?
................................................................................
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 1 1 1 1 1 0 1}

test schema-16.20 {interleave with all content cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            group {
                element c ?
................................................................................
        <doc><d/></doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 1 1 1 1 1 0 1}






































test schema-17.1 {info} {
    tdom::schema s
    s define {
        foreach e {a b1 b11 b2 c} {
            defelement $e {}
        }







|







 







|







 







>
>





|

|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
....
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
....
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
....
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
....
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
    } {
        lappend result [s validate $xml errMsg]
    }
    s delete
    set result
} {1 1 0}

test schema-16.17 {interleave with all child cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            element c ?
        }
................................................................................
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 1 1 1 1 1 0 1}

test schema-16.18 {interleave with all child cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            choice {
                element c ?
................................................................................
        <doc><b/></doc>
        <doc><c/></doc>
        <doc><a/><c/></doc>
        <doc><b/><c/></doc>
        <doc><c/><a/></doc>
        <doc><c/><a/><b/><d/></doc>
        <doc><c/><a/><b/></doc>
        <doc><c2/><a/><b/></doc>
        <doc><c/><b/><a/><c1/></doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 1 1 1 1 1 1 0 1 1 0}

test schema-16.19 {interleave with all child cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            choice {
                element c ?
................................................................................
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 1 1 1 1 1 0 1}

test schema-16.20 {interleave with all child cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            group {
                element c ?
................................................................................
        <doc><d/></doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 1 1 1 1 1 0 1}

test schema-16.21 {interleave with all child cp optional} {
    tdom::schema s
    s defelement doc {
        interleave {
            element a ?
            element b ?
            group {
                element c ?
                element c1 ?
                element c2 ?
            }
        }
    }
    set result [list]
    foreach xml {
        <doc/>
        <doc><a/></doc>
        <doc><b/></doc>
        <doc><c/></doc>
        <doc><a/><c/></doc>
        <doc><b/><c/></doc>
        <doc><c/><a/></doc>
        <doc><c/><a/><b/><d/></doc>
        <doc><c/><a/><b/></doc>
        <doc><c2/><a/><b/></doc>
        <doc><c/><b/><a/><c1/></doc>
        <doc><b/><c/><c2/><a/></doc>
        <doc><b/><c/><c2/><a/><c1/></doc>
        <doc><b/><c/><c1/><c2/><a/></doc>
        <doc><b/><c/><c2/><c1/><a/></doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 1 1 1 1 1 1 0 1 1 0 1 0 1 0}

test schema-17.1 {info} {
    tdom::schema s
    s define {
        foreach e {a b1 b11 b2 c} {
            defelement $e {}
        }