Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | wip |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | deviation |
Files: | files | file ages | folders |
SHA3-256: |
5aac7f85df4bc5f17b160f5752cdb3f3 |
User & Date: | rolf 2019-10-05 12:32:14 |
Context
2019-10-05
| ||
12:32 | wip Closed-Leaf check-in: 5aac7f85df user: rolf tags: deviation | |
00:16 | More minor doc tweaking. check-in: 43e20be75b user: rolf tags: wip | |
Changes
Changes to generic/schema.c.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 ... 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 ... 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 .... 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 .... 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 .... 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 .... 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 .... 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 .... 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 |
#if defined(DEBUG) || defined(DDEBUG) static char *Schema_CP_Type2str[] = { "ANY", "NAME", "CHOICE", "INTERLEAVE", "PATTERN", "TEXT" "VIRTUAL", "KEYSPACE_START", "KEYSPACE_END" }; static char *Schema_Quant_Type2str[] = { "ONE", "OPT", "REP", "PLUS", "NM" }; #endif #ifndef TCL_THREADS static SchemaData *activeSchemaData = 0; # define GETASI activeSchemaData ................................................................................ Tcl_Interp *interp, SchemaData *sdata, char *name, char *namespace ) { SchemaCP *cp, *candidate, *icp; int hm, ac, i, mayskip, rc; int isName = 0; SchemaValidationStack *se; if (!sdata->stack) return 0; se = sdata->stack; getContext (cp, ac, hm); ................................................................................ switch (cp->type) { case SCHEMA_CTYPE_NAME: isName = 1; /* fall through */ case SCHEMA_CTYPE_PATTERN: while (ac < cp->nc) { candidate = cp->content[ac]; mayskip = 0; switch (candidate->type) { case SCHEMA_CTYPE_TEXT: if (candidate->nc) { if (!checkText (interp, candidate, "")) { if (recover (interp, sdata, S("MISSING_TEXT"), 1, ac)) { return 1; ................................................................................ pushToStack (sdata, icp, ac); rc = matchElementStart (interp, sdata, name, namespace); if (rc == 1) { updateStack (se, cp, ac); return 1; } popStack (sdata); if (rc == -1) mayskip = 1; break; case SCHEMA_CTYPE_VIRTUAL: Tcl_Panic ("Virtual constrain in MIXED or CHOICE"); case SCHEMA_CTYPE_KEYSPACE_END: case SCHEMA_CTYPE_KEYSPACE: Tcl_Panic ("Keyspace constrain in MIXED or CHOICE"); } if (!mayskip && mayMiss (candidate->quants[i])) mayskip = 1; } break; case SCHEMA_CTYPE_VIRTUAL: if (evalVirtual (interp, sdata, ac)) { /* Virtual contraints are always quant ONE, so * that the virtual constraints are called while * looking if an element can end. Therefor we use * here the already present mayskip mechanism to * try further, after calling the tcl script. */ mayskip = 1; break; } else return 0; case SCHEMA_CTYPE_INTERLEAVE: case SCHEMA_CTYPE_PATTERN: pushToStack (sdata, candidate, ac); ................................................................................ } else { candidate->keySpace->active++; } ac++; hm = 0; continue; } if (!mayskip && mustMatch (cp->quants[ac], hm)) { if (recover (interp, sdata, S("MISSING_CP"), 1, ac)) { /* Skip the just opened element tag and the following * content of the current. */ return 1; } return 0; } ................................................................................ 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: mayskip = 1; for (i = 0; i < cp->nc; i++) { if (se->interleaveState[i]) { if (maxOne (cp->quants[i])) continue; } else { if (minOne (cp->quants[i])) mayskip = 0; } icp = cp->content[i]; switch (icp->type) { case SCHEMA_CTYPE_TEXT: if (icp->nc) { if (!checkText (interp, icp, "")) { mayskip = 0; } } break; case SCHEMA_CTYPE_ANY: if (icp->namespace && icp->namespace == namespace) { break; } sdata->skipDeep = 1; if (mayskip && minOne (cp->quants[i])) mayskip = 0; se->hasMatched = 1; se->interleaveState[i] = 1; return 1; case SCHEMA_CTYPE_NAME: if (icp->name == name && icp->namespace == namespace) { ................................................................................ rc = matchElementStart (interp, sdata, name, namespace); if (rc == 1) { se->hasMatched = 1; se->interleaveState[i] = 1; return 1; } popStack (sdata); if (mayskip && rc != -1) mayskip = 0; break; case SCHEMA_CTYPE_VIRTUAL: Tcl_Panic ("Virtual constraint child of INTERLEAVE"); break; case SCHEMA_CTYPE_KEYSPACE_END: case SCHEMA_CTYPE_KEYSPACE: Tcl_Panic ("Keyspace constraint child of INTERLEAVE"); break; } } if (mayskip) break; if (recover (interp, sdata, S("MISSING_ONE_OF_INTERLEAVE"), 1, ac)) { return 1; } return 0; } return -1; } static void * getNamespacePtr ( SchemaData *sdata, ................................................................................ } while (ac < cp->nc) { DBG(fprintf (stderr, "ac %d hm %d mayMiss: %d\n", 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) { if (!recover (interp, sdata, S("UNKNOWN_KEYREF"), 0, 0)) { return 0; ................................................................................ * cmd. */ pattern->content = MALLOC (sizeof (Tcl_Obj*) * (objc)); for (i = 1; i < objc; i++) { pattern->content[i-1] = (SchemaCP *) objv[i]; Tcl_IncrRefCount (objv[i]); } pattern->nc = objc; addToContent (sdata, pattern, SCHEMA_CQUANT_OPT, 0, 0); return TCL_OK; } static int domuniquePatternObjCmd ( ClientData clientData, Tcl_Interp *interp, |
| | > | < < < < < < < < < | | | | | < < < < < < < < | < < > < > | | | | > < | |
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 ... 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 ... 977 978 979 980 981 982 983 984 985 986 987 988 989 990 .... 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 .... 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 .... 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 .... 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 .... 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 .... 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 |
#if defined(DEBUG) || defined(DDEBUG) static char *Schema_CP_Type2str[] = { "ANY", "NAME", "CHOICE", "INTERLEAVE", "PATTERN", "TEXT", "VIRTUAL", "KEYSPACE_START", "KEYSPACE_END" }; static char *Schema_Quant_Type2str[] = { "ONE", "OPT", "REP", "PLUS", "NM", "ERROR" }; #endif #ifndef TCL_THREADS static SchemaData *activeSchemaData = 0; # define GETASI activeSchemaData ................................................................................ Tcl_Interp *interp, SchemaData *sdata, char *name, char *namespace ) { SchemaCP *cp, *candidate, *icp; int hm, ac, i, rc, missing; int isName = 0; SchemaValidationStack *se; if (!sdata->stack) return 0; se = sdata->stack; getContext (cp, ac, hm); ................................................................................ switch (cp->type) { case SCHEMA_CTYPE_NAME: isName = 1; /* fall through */ case SCHEMA_CTYPE_PATTERN: while (ac < cp->nc) { candidate = cp->content[ac]; switch (candidate->type) { case SCHEMA_CTYPE_TEXT: if (candidate->nc) { if (!checkText (interp, candidate, "")) { if (recover (interp, sdata, S("MISSING_TEXT"), 1, ac)) { return 1; ................................................................................ pushToStack (sdata, icp, ac); rc = matchElementStart (interp, sdata, name, namespace); if (rc == 1) { updateStack (se, cp, ac); return 1; } popStack (sdata); break; case SCHEMA_CTYPE_VIRTUAL: Tcl_Panic ("Virtual constrain in MIXED or CHOICE"); case SCHEMA_CTYPE_KEYSPACE_END: case SCHEMA_CTYPE_KEYSPACE: Tcl_Panic ("Keyspace constrain in MIXED or CHOICE"); } } break; case SCHEMA_CTYPE_VIRTUAL: if (evalVirtual (interp, sdata, ac)) { hm = 1; break; } else return 0; case SCHEMA_CTYPE_INTERLEAVE: case SCHEMA_CTYPE_PATTERN: pushToStack (sdata, candidate, ac); ................................................................................ } else { candidate->keySpace->active++; } ac++; hm = 0; continue; } if (mustMatch (cp->quants[ac], hm)) { if (recover (interp, sdata, S("MISSING_CP"), 1, ac)) { /* Skip the just opened element tag and the following * content of the current. */ return 1; } return 0; } ................................................................................ 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: missing = 0; for (i = 0; i < cp->nc; i++) { if (se->interleaveState[i] && maxOne (cp->quants[i])) continue; icp = cp->content[i]; switch (icp->type) { case SCHEMA_CTYPE_TEXT: break; case SCHEMA_CTYPE_ANY: if (icp->namespace && icp->namespace != namespace) { break; } sdata->skipDeep = 1; se->hasMatched = 1; se->interleaveState[i] = 1; return 1; case SCHEMA_CTYPE_NAME: if (icp->name == name && icp->namespace == namespace) { ................................................................................ rc = matchElementStart (interp, sdata, name, namespace); if (rc == 1) { se->hasMatched = 1; se->interleaveState[i] = 1; return 1; } popStack (sdata); break; case SCHEMA_CTYPE_VIRTUAL: Tcl_Panic ("Virtual constraint child of INTERLEAVE"); break; case SCHEMA_CTYPE_KEYSPACE_END: case SCHEMA_CTYPE_KEYSPACE: Tcl_Panic ("Keyspace constraint child of INTERLEAVE"); break; } if (!missing && minOne (cp->quants[i])) missing = 1; } if (missing) { if (recover (interp, sdata, S("MISSING_ONE_OF_INTERLEAVE"), 1, ac)) { return 1; } return 0; } } return -1; } static void * getNamespacePtr ( SchemaData *sdata, ................................................................................ } while (ac < cp->nc) { DBG(fprintf (stderr, "ac %d hm %d mayMiss: %d\n", 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) { if (!recover (interp, sdata, S("UNKNOWN_KEYREF"), 0, 0)) { return 0; ................................................................................ * cmd. */ pattern->content = MALLOC (sizeof (Tcl_Obj*) * (objc)); for (i = 1; i < objc; i++) { pattern->content[i-1] = (SchemaCP *) objv[i]; Tcl_IncrRefCount (objv[i]); } pattern->nc = objc; addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0); return TCL_OK; } static int domuniquePatternObjCmd ( ClientData clientData, Tcl_Interp *interp, |
Changes to tests/schema.test.
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 .... 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 .... 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 .... 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 .... 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 |
<doc><a/><a/><a/><c/></doc> <doc><b/><b/><b/><c/></doc> <doc><c/></doc> } { lappend result [s validate $xml] } set result } {0 0 1 0 1 1 1} test schema-7.15a {choice with optional choices} { tdom::schema create s s define { defelement doc { choice { element a * ................................................................................ <doc><aa/><ab/><aa/><c/></doc> <doc><aa/><ab/><aa/><aa/><ab/><c/></doc> <doc><c/></doc> } { lappend result [s validate $xml] } set result } {0 0 1 0 1 1 1 1 1} test schema-7.17 {choice with optional choices} { tdom::schema create s s define { defelement doc { choice { element a * ................................................................................ <doc><aa/><ab/><aa/><c/></doc> <doc><aa/><ab/><aa/><aa/><ab/><c/></doc> <doc><c/></doc> } { lappend result [s validate $xml] } set result } {0 0 1 0 1 1 0 0 1} test schema-7.18 {choice} { tdom::schema create s s define { defelement doc { choice { element a ................................................................................ <doc><aa/><ab/><aa/><c/></doc> <doc><aa/><ab/><aa/><aa/><ab/><c/></doc> <doc><c/></doc> } { lappend result [s validate $xml] } set result } {0 0 1 1 0 0 0 1 0 0 1} test schema-7.20 {group with only optional content} { tdom::schema create s s define { defelement doc { element a group { ................................................................................ <doc>12</doc> } { lappend result [s validate $xml] } s delete set result } {0 1 0 1 0 1 1 0} test schema-16.16 {interleave} { tdom::schema s s define { foreach e {a b1 b11 b2 c} { defelement $e {} } |
| | | | < |
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 .... 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 .... 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 .... 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 .... 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 |
<doc><a/><a/><a/><c/></doc> <doc><b/><b/><b/><c/></doc> <doc><c/></doc> } { lappend result [s validate $xml] } set result } {0 0 1 0 1 1 0} test schema-7.15a {choice with optional choices} { tdom::schema create s s define { defelement doc { choice { element a * ................................................................................ <doc><aa/><ab/><aa/><c/></doc> <doc><aa/><ab/><aa/><aa/><ab/><c/></doc> <doc><c/></doc> } { lappend result [s validate $xml] } set result } {0 0 1 0 1 1 1 1 0} test schema-7.17 {choice with optional choices} { tdom::schema create s s define { defelement doc { choice { element a * ................................................................................ <doc><aa/><ab/><aa/><c/></doc> <doc><aa/><ab/><aa/><aa/><ab/><c/></doc> <doc><c/></doc> } { lappend result [s validate $xml] } set result } {0 0 1 0 1 1 0 0 0} test schema-7.18 {choice} { tdom::schema create s s define { defelement doc { choice { element a ................................................................................ <doc><aa/><ab/><aa/><c/></doc> <doc><aa/><ab/><aa/><aa/><ab/><c/></doc> <doc><c/></doc> } { lappend result [s validate $xml] } set result } {0 0 1 1 0 0 0 1 0 0 0} test schema-7.20 {group with only optional content} { tdom::schema create s s define { defelement doc { element a group { ................................................................................ <doc>12</doc> } { lappend result [s validate $xml] } s delete set result } {0 1 0 1 0 1 1 0} test schema-16.16 {interleave} { tdom::schema s s define { foreach e {a b1 b11 b2 c} { defelement $e {} } |