Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Starts to actually do something. Still some way to go. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | keyspaces |
Files: | files | file ages | folders |
SHA3-256: |
6eb6891a1e335f86f908a783dee93a6a |
User & Date: | rolf 2019-05-29 12:57:55.137 |
Context
2019-05-30
| ||
01:02 | If recovering from the error "text doesn't match constraint" pretent the text has matched so the not matched required text cp isn't reported again as missing text. check-in: 39651ce911 user: rolf tags: keyspaces | |
2019-05-29
| ||
12:57 | Starts to actually do something. Still some way to go. check-in: 6eb6891a1e user: rolf tags: keyspaces | |
2019-05-28
| ||
00:29 | Save work. check-in: 48be317469 user: rolf tags: keyspaces | |
Changes
Changes to generic/schema.c.
︙ | ︙ | |||
579 580 581 582 583 584 585 | } Tcl_DeleteHashTable (&sdata->idTables); for (h = Tcl_FirstHashEntry (&sdata->keySpaces, &search); h != NULL; h = Tcl_NextHashEntry (&search)) { ks = Tcl_GetHashValue (h); if (ks->active) { | | > | 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | } Tcl_DeleteHashTable (&sdata->idTables); for (h = Tcl_FirstHashEntry (&sdata->keySpaces, &search); h != NULL; h = Tcl_NextHashEntry (&search)) { ks = Tcl_GetHashValue (h); if (ks->active) { Tcl_DeleteHashTable (&ks->ids); } FREE (ks); } Tcl_DeleteHashTable (&sdata->keySpaces); FREE (sdata); } static void cleanupLastPattern ( SchemaData *sdata, unsigned int from |
︙ | ︙ | |||
983 984 985 986 987 988 989 | candidate->keySpace->active--; if (!candidate->keySpace->active) { if (candidate->keySpace->unknownIDrefs) { /* Recover or report error */ } Tcl_DeleteHashTable (&candidate->keySpace->ids); } | | > > | > > | 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | candidate->keySpace->active--; if (!candidate->keySpace->active) { if (candidate->keySpace->unknownIDrefs) { /* Recover or report error */ } Tcl_DeleteHashTable (&candidate->keySpace->ids); } ac++; hm = 0; continue; case SCHEMA_CTYPE_KEYSPACE: if (!candidate->keySpace->active) { Tcl_InitHashTable (&candidate->keySpace->ids, TCL_STRING_KEYS); candidate->keySpace->active = 1; candidate->keySpace->unknownIDrefs = 0; } else { candidate->keySpace->active++; } ac++; hm = 0; continue; } if (!mayskip && mustMatch (cp->quants[ac], hm)) { if (recover (interp, sdata, S("MISSING_CP"))) { /* Skip the just opened element tag and the following * content of the current. */ sdata->skipDeep = 2; return 1; |
︙ | ︙ | |||
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 | ac, hm, mayMiss (cp->quants[ac]))); if (mayMiss (cp->quants[ac])) { ac++; continue; } switch (cp->content[ac]->type) { case SCHEMA_CTYPE_KEYSPACE_END: break; case SCHEMA_CTYPE_KEYSPACE: break; case SCHEMA_CTYPE_TEXT: if (cp->content[ac]->nc) { if (!checkText (interp, cp->content[ac], "")) { if (recover (interp, sdata, S("MISSING_TEXT"))) { break; | > > > > > > > > > > > > > > > | 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 | ac, hm, mayMiss (cp->quants[ac]))); 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) { /* Recover or report error */ } 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++; } break; case SCHEMA_CTYPE_TEXT: if (cp->content[ac]->nc) { if (!checkText (interp, cp->content[ac], "")) { if (recover (interp, sdata, S("MISSING_TEXT"))) { break; |
︙ | ︙ | |||
1848 1849 1850 1851 1852 1853 1854 | break; case SCHEMA_CTYPE_VIRTUAL: if (!evalVirtual (interp, sdata, candidate)) return 0; break; case SCHEMA_CTYPE_KEYSPACE: | > > > > > > > | > > > > | > > > > | 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 | break; case SCHEMA_CTYPE_VIRTUAL: if (!evalVirtual (interp, sdata, candidate)) return 0; 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++; } break; case SCHEMA_CTYPE_KEYSPACE_END: cp->content[ac]->keySpace->active--; if (!cp->content[ac]->keySpace->active) { if (cp->content[ac]->keySpace->unknownIDrefs) { /* Recover or report error */ } Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids); } break; case SCHEMA_CTYPE_NAME: case SCHEMA_CTYPE_ANY: if (mustMatch (cp->quants[ac], hm)) { SetResult ("Unexpected text content"); return 0; } break; } ac++; } if (isName) { SetResult ("Unexpected text content"); return 0; } popStack (sdata); continue; case SCHEMA_CTYPE_KEYSPACE: case SCHEMA_CTYPE_KEYSPACE_END: 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!"); break; |
︙ | ︙ | |||
1919 1920 1921 1922 1923 1924 1925 | Tcl_Panic ("Keyspace child of INTERLEAVE"); case SCHEMA_CTYPE_VIRTUAL: break; } } | < < < < < < < | 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 | Tcl_Panic ("Keyspace child of INTERLEAVE"); case SCHEMA_CTYPE_VIRTUAL: break; } } break; } break; } return 0; } |
︙ | ︙ | |||
2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 | schemaReset ( SchemaData *sdata ) { Tcl_HashEntry *h; Tcl_HashSearch search; SchemaDocKey *dk; while (sdata->stack) popStack (sdata); sdata->validationState = VALIDATION_READY; sdata->skipDeep = 0; sdata->evalError = 0; Tcl_DStringSetLength (sdata->cdata, 0); if (sdata->ids.numEntries) { | > | 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 | schemaReset ( SchemaData *sdata ) { Tcl_HashEntry *h; Tcl_HashSearch search; SchemaDocKey *dk; SchemaKeySpace *ks; while (sdata->stack) popStack (sdata); sdata->validationState = VALIDATION_READY; sdata->skipDeep = 0; sdata->evalError = 0; Tcl_DStringSetLength (sdata->cdata, 0); if (sdata->ids.numEntries) { |
︙ | ︙ | |||
2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 | dk = Tcl_GetHashValue (h); if (&dk->ids.numEntries) { Tcl_DeleteHashTable (&dk->ids); Tcl_InitHashTable (&dk->ids, TCL_STRING_KEYS); dk->unknownIDrefs = 0; } } } } static int evalConstraints ( Tcl_Interp *interp, SchemaData *sdata, | > > > > > > > > > > > > > | 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 | dk = Tcl_GetHashValue (h); if (&dk->ids.numEntries) { Tcl_DeleteHashTable (&dk->ids); Tcl_InitHashTable (&dk->ids, TCL_STRING_KEYS); dk->unknownIDrefs = 0; } } } if (sdata->keySpaces.numEntries) { for (h = Tcl_FirstHashEntry (&sdata->keySpaces, &search); h != NULL; h = Tcl_NextHashEntry (&search)) { ks = Tcl_GetHashValue (h); if (ks->active && ks->ids.numEntries) { Tcl_DeleteHashTable (&ks->ids); Tcl_InitHashTable (&ks->ids, TCL_STRING_KEYS); } ks->unknownIDrefs = 0; ks->active = 0; } } } static int evalConstraints ( Tcl_Interp *interp, SchemaData *sdata, |
︙ | ︙ | |||
3861 3862 3863 3864 3865 3866 3867 | return TCL_ERROR; } if (Tcl_ListObjLength (interp, objv[1], &nrKeyspaces) != TCL_OK) { SetResult ("The <keyspace-name list> argument must be a valid tcl " "list"); return TCL_ERROR; } | < < < < < < < < < < > > > > > > > > > > > > > > | | 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 | return TCL_ERROR; } if (Tcl_ListObjLength (interp, objv[1], &nrKeyspaces) != TCL_OK) { SetResult ("The <keyspace-name list> argument must be a valid tcl " "list"); return TCL_ERROR; } for (i = 0; i < nrKeyspaces; i++) { Tcl_ListObjIndex (interp, objv[1], i, &ksObj); h = Tcl_CreateHashEntry (&sdata->keySpaces, Tcl_GetString (ksObj), &hnew); if (hnew) { ks = TMALLOC (SchemaKeySpace); ks->active = 0; ks->unknownIDrefs = 0; Tcl_SetHashValue (h, ks); } else { ks = Tcl_GetHashValue (h); } pattern = initSchemaCP (SCHEMA_CTYPE_KEYSPACE, Tcl_GetString (ksObj), NULL); pattern->keySpace = ks; REMEMBER_PATTERN (pattern); addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0); } sdata->currentEvals++; if (Tcl_EvalObjEx (interp, objv[2], TCL_EVAL_DIRECT) != TCL_OK) { return TCL_ERROR; } sdata->currentEvals--; for (i = 0; i < nrKeyspaces; i++) { Tcl_ListObjIndex (interp, objv[1], i, &ksObj); h = Tcl_FindHashEntry (&sdata->keySpaces, Tcl_GetString(ksObj)); pattern = initSchemaCP (SCHEMA_CTYPE_KEYSPACE_END, Tcl_GetString (ksObj), NULL); REMEMBER_PATTERN (pattern); pattern->keySpace = Tcl_GetHashValue (h); addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0); } return TCL_OK; } static int integerImpl ( |
︙ | ︙ | |||
5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 | dk = Tcl_GetHashValue (h); } sc->constraint = docidrefImpl; sc->constraintData = (void *)dk; } return TCL_OK; } static int base64Impl ( Tcl_Interp *interp, void *constraintData, char *text ) | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 | dk = Tcl_GetHashValue (h); } sc->constraint = docidrefImpl; sc->constraintData = (void *)dk; } return TCL_OK; } static int keyImpl ( Tcl_Interp *interp, void *constraintData, char *text ) { SchemaKeySpace *ks = (SchemaKeySpace *) constraintData; int hnew; Tcl_HashEntry *h; if (!ks->active) return 1; h = Tcl_CreateHashEntry (&ks->ids, text, &hnew); if (hnew) { Tcl_SetHashValue (h, 1); return 1; } if (Tcl_GetHashValue (h) == 0) { Tcl_SetHashValue (h, 1); ks->unknownIDrefs--; return 1; } else { /* Duplicate ID value */ return 0; } } static int keyTCObjCmd ( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { SchemaData *sdata = GETASI; SchemaConstraint *sc; Tcl_HashEntry *h; int hnew; SchemaKeySpace *ks; CHECK_TI CHECK_TOPLEVEL checkNrArgs (2,2,"key_space"); ADD_CONSTRAINT (sdata, sc) h = Tcl_CreateHashEntry (&sdata->keySpaces, Tcl_GetString (objv[1]), &hnew); if (hnew) { ks = TMALLOC (SchemaKeySpace); ks->active = 0; ks->unknownIDrefs = 0; Tcl_SetHashValue (h, ks); } else { ks = Tcl_GetHashValue (h); } sc->constraint = keyImpl; sc->constraintData = (void *) ks; return TCL_OK; } static int keyrefImpl ( Tcl_Interp *interp, void *constraintData, char *text ) { SchemaKeySpace *ks = (SchemaKeySpace *) constraintData; int hnew; Tcl_HashEntry *h; if (!ks->active) return 1; h = Tcl_CreateHashEntry (&ks->ids, text, &hnew); if (hnew) { Tcl_SetHashValue (h, 0); ks->unknownIDrefs++; } return 1; } static int keyrefTCObjCmd ( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { SchemaData *sdata = GETASI; SchemaConstraint *sc; Tcl_HashEntry *h; int hnew; SchemaKeySpace *ks; CHECK_TI CHECK_TOPLEVEL checkNrArgs (2,2,"key_space"); ADD_CONSTRAINT (sdata, sc) h = Tcl_CreateHashEntry (&sdata->keySpaces, Tcl_GetString (objv[1]), &hnew); if (hnew) { ks = TMALLOC (SchemaKeySpace); Tcl_InitHashTable (&ks->ids, TCL_STRING_KEYS); ks->unknownIDrefs = 0; Tcl_SetHashValue (h, ks); } else { ks = Tcl_GetHashValue (h); } sc->constraint = keyrefImpl; sc->constraintData = (void *)ks; return TCL_OK; } static int base64Impl ( Tcl_Interp *interp, void *constraintData, char *text ) |
︙ | ︙ | |||
5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 | splitTCObjCmd, NULL, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::id", idTCObjCmd, NULL, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::idref", idrefTCObjCmd, NULL, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::base64", base64TCObjCmd, NULL, NULL); } #endif /* #ifndef TDOM_NO_SCHEMA */ | > > > > | 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 | splitTCObjCmd, NULL, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::id", idTCObjCmd, NULL, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::idref", idrefTCObjCmd, NULL, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::base64", base64TCObjCmd, NULL, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::key", keyTCObjCmd, NULL, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::keyref", keyrefTCObjCmd, NULL, NULL); } #endif /* #ifndef TDOM_NO_SCHEMA */ |
Changes to generic/schema.h.
︙ | ︙ | |||
32 33 34 35 36 37 38 | SCHEMA_CTYPE_NAME, SCHEMA_CTYPE_CHOICE, SCHEMA_CTYPE_INTERLEAVE, SCHEMA_CTYPE_PATTERN, SCHEMA_CTYPE_TEXT, SCHEMA_CTYPE_VIRTUAL, SCHEMA_CTYPE_KEYSPACE, | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | SCHEMA_CTYPE_NAME, SCHEMA_CTYPE_CHOICE, SCHEMA_CTYPE_INTERLEAVE, SCHEMA_CTYPE_PATTERN, SCHEMA_CTYPE_TEXT, SCHEMA_CTYPE_VIRTUAL, SCHEMA_CTYPE_KEYSPACE, SCHEMA_CTYPE_KEYSPACE_END, } Schema_CP_Type; typedef enum { SCHEMA_CQUANT_ONE, SCHEMA_CQUANT_OPT, SCHEMA_CQUANT_REP, SCHEMA_CQUANT_PLUS, |
︙ | ︙ |
Changes to tests/schema.test.
︙ | ︙ | |||
4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 | proc postValidation {g xml} { set doc [dom parse $xml] set rc [$g domvalidate $doc errMsg] $doc delete return $rc } test schema-20.1 {domunique} { set schema { prefixns {ns1 http://tdom.org/test} defelement doc { domunique ${::schema-20.1} @ref } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 | proc postValidation {g xml} { set doc [dom parse $xml] set rc [$g domvalidate $doc errMsg] $doc delete return $rc } test schema-19.1 {keyspace} { tdom::schema s s define { defelement doc { element items * { keyspace ref { element item * { attribute ref ? { key ref } } } } } } set result [list] foreach xml { {<doc><items><item ref="1"/><item ref="foo"/></items></doc>} {<doc><items><item ref="1"/><item ref="1"/></items></doc>} {<doc><items><item ref="1"/><item ref="foo"/></items><items><item ref="1"/><item ref="foo"/></items></doc>} {<doc><items><item ref="1"/><item ref="foo"/></items><items><item ref="1"/><item ref="bar"/></items></doc>} {<doc><items><item ref="1"/><item ref="foo"/></items><items><item ref="2"/><item ref="bar"/></items></doc>} {<doc><items><item ref="1"/><item ref="foo"/></items><items><item ref="bar"/><item ref="bar"/></items></doc>} } { lappend result [s validate $xml] } s delete set result } {1 0 1 1 1 0} test schema-20.1 {domunique} { set schema { prefixns {ns1 http://tdom.org/test} defelement doc { domunique ${::schema-20.1} @ref } |
︙ | ︙ |