Lines Matching full:ctxt
51 ctxt->error = XML_REGEXP_COMPILE_ERROR; \
52 xmlRegexpErrCompile(ctxt, str);
53 #define NEXT ctxt->cur++
54 #define CUR (*(ctxt->cur))
55 #define NXT(index) (ctxt->cur[index])
58 #define NEXTL(l) ctxt->cur += l;
62 * when it's guaranteed that cur is not at the beginning of ctxt->string!
64 #define PREV (ctxt->cur[-1])
356 static void xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top);
378 xmlRegexpErrMemory(xmlRegParserCtxtPtr ctxt, const char *extra)
381 if (ctxt != NULL) {
382 regexp = (const char *) ctxt->string;
383 ctxt->error = XML_ERR_NO_MEMORY;
398 xmlRegexpErrCompile(xmlRegParserCtxtPtr ctxt, const char *extra)
403 if (ctxt != NULL) {
404 regexp = (const char *) ctxt->string;
405 idx = ctxt->cur - ctxt->string;
406 ctxt->error = XML_REGEXP_COMPILE_ERROR;
420 static int xmlFAComputesDeterminism(xmlRegParserCtxtPtr ctxt);
423 * @ctxt: the parser context used to build it
430 xmlRegEpxFromParse(xmlRegParserCtxtPtr ctxt) {
435 xmlRegexpErrMemory(ctxt, "compiling regexp");
439 ret->string = ctxt->string;
440 ret->nbStates = ctxt->nbStates;
441 ret->states = ctxt->states;
442 ret->nbAtoms = ctxt->nbAtoms;
443 ret->atoms = ctxt->atoms;
444 ret->nbCounters = ctxt->nbCounters;
445 ret->counters = ctxt->counters;
446 ret->determinist = ctxt->determinist;
447 ret->flags = ctxt->flags;
454 (ctxt->negs == 0) &&
476 xmlRegexpErrMemory(ctxt, "compiling regexp");
493 xmlRegexpErrMemory(ctxt, "compiling regexp");
500 xmlRegexpErrMemory(ctxt, "compiling regexp");
584 xmlRegexpErrMemory(ctxt, "compiling regexp");
666 ctxt->string = NULL;
667 ctxt->nbStates = 0;
668 ctxt->states = NULL;
669 ctxt->nbAtoms = 0;
670 ctxt->atoms = NULL;
671 ctxt->nbCounters = 0;
672 ctxt->counters = NULL;
704 * @ctxt: the regexp parser context
715 xmlRegNewRange(xmlRegParserCtxtPtr ctxt,
721 xmlRegexpErrMemory(ctxt, "allocating range");
756 xmlRegCopyRange(xmlRegParserCtxtPtr ctxt, xmlRegRangePtr range) {
762 ret = xmlRegNewRange(ctxt, range->neg, range->type, range->start,
769 xmlRegexpErrMemory(ctxt, "allocating range");
779 * @ctxt: the regexp parser context
787 xmlRegNewAtom(xmlRegParserCtxtPtr ctxt, xmlRegAtomType type) {
792 xmlRegexpErrMemory(ctxt, "allocating atom");
831 * @ctxt: the regexp parser context
839 xmlRegCopyAtom(xmlRegParserCtxtPtr ctxt, xmlRegAtomPtr atom) {
844 xmlRegexpErrMemory(ctxt, "copying atom");
858 xmlRegexpErrMemory(ctxt, "copying atom");
862 ret->ranges[i] = xmlRegCopyRange(ctxt, atom->ranges[i]);
876 xmlRegNewState(xmlRegParserCtxtPtr ctxt) {
881 xmlRegexpErrMemory(ctxt, "allocating state");
910 * @ctxt: the regexp parser context
915 xmlRegFreeParserCtxt(xmlRegParserCtxtPtr ctxt) {
917 if (ctxt == NULL)
920 if (ctxt->string != NULL)
921 xmlFree(ctxt->string);
922 if (ctxt->states != NULL) {
923 for (i = 0;i < ctxt->nbStates;i++)
924 xmlRegFreeState(ctxt->states[i]);
925 xmlFree(ctxt->states);
927 if (ctxt->atoms != NULL) {
928 for (i = 0;i < ctxt->nbAtoms;i++)
929 xmlRegFreeAtom(ctxt->atoms[i]);
930 xmlFree(ctxt->atoms);
932 if (ctxt->counters != NULL)
933 xmlFree(ctxt->counters);
934 xmlFree(ctxt);
1170 xmlRegPrintCtxt(FILE *output, xmlRegParserCtxtPtr ctxt) {
1173 fprintf(output, " ctxt: ");
1174 if (ctxt == NULL) {
1178 fprintf(output, "'%s' ", ctxt->string);
1179 if (ctxt->error)
1181 if (ctxt->neg)
1184 fprintf(output, "%d atoms:\n", ctxt->nbAtoms);
1185 for (i = 0;i < ctxt->nbAtoms; i++) {
1187 xmlRegPrintAtom(output, ctxt->atoms[i]);
1189 if (ctxt->atom != NULL) {
1191 xmlRegPrintAtom(output, ctxt->atom);
1193 fprintf(output, "%d states:", ctxt->nbStates);
1194 if (ctxt->start != NULL)
1195 fprintf(output, " start: %d", ctxt->start->no);
1196 if (ctxt->end != NULL)
1197 fprintf(output, " end: %d", ctxt->end->no);
1199 for (i = 0;i < ctxt->nbStates; i++) {
1200 xmlRegPrintState(output, ctxt->states[i]);
1202 fprintf(output, "%d counters:\n", ctxt->nbCounters);
1203 for (i = 0;i < ctxt->nbCounters; i++) {
1204 fprintf(output, " %d: min %d max %d\n", i, ctxt->counters[i].min,
1205 ctxt->counters[i].max);
1217 xmlRegAtomAddRange(xmlRegParserCtxtPtr ctxt, xmlRegAtomPtr atom,
1235 xmlRegexpErrMemory(ctxt, "adding ranges");
1245 xmlRegexpErrMemory(ctxt, "adding ranges");
1251 range = xmlRegNewRange(ctxt, neg, type, start, end);
1260 xmlRegGetCounter(xmlRegParserCtxtPtr ctxt) {
1261 if (ctxt->maxCounters == 0) {
1262 ctxt->maxCounters = 4;
1263 ctxt->counters = (xmlRegCounter *) xmlMalloc(ctxt->maxCounters *
1265 if (ctxt->counters == NULL) {
1266 xmlRegexpErrMemory(ctxt, "allocating counter");
1267 ctxt->maxCounters = 0;
1270 } else if (ctxt->nbCounters >= ctxt->maxCounters) {
1272 ctxt->maxCounters *= 2;
1273 tmp = (xmlRegCounter *) xmlRealloc(ctxt->counters, ctxt->maxCounters *
1276 xmlRegexpErrMemory(ctxt, "allocating counter");
1277 ctxt->maxCounters /= 2;
1280 ctxt->counters = tmp;
1282 ctxt->counters[ctxt->nbCounters].min = -1;
1283 ctxt->counters[ctxt->nbCounters].max = -1;
1284 return(ctxt->nbCounters++);
1288 xmlRegAtomPush(xmlRegParserCtxtPtr ctxt, xmlRegAtomPtr atom) {
1293 if (ctxt->maxAtoms == 0) {
1294 ctxt->maxAtoms = 4;
1295 ctxt->atoms = (xmlRegAtomPtr *) xmlMalloc(ctxt->maxAtoms *
1297 if (ctxt->atoms == NULL) {
1298 xmlRegexpErrMemory(ctxt, "pushing atom");
1299 ctxt->maxAtoms = 0;
1302 } else if (ctxt->nbAtoms >= ctxt->maxAtoms) {
1304 ctxt->maxAtoms *= 2;
1305 tmp = (xmlRegAtomPtr *) xmlRealloc(ctxt->atoms, ctxt->maxAtoms *
1308 xmlRegexpErrMemory(ctxt, "allocating counter");
1309 ctxt->maxAtoms /= 2;
1312 ctxt->atoms = tmp;
1314 atom->no = ctxt->nbAtoms;
1315 ctxt->atoms[ctxt->nbAtoms++] = atom;
1320 xmlRegStateAddTransTo(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr target,
1327 xmlRegexpErrMemory(ctxt, "adding transition");
1337 xmlRegexpErrMemory(ctxt, "adding transition");
1348 xmlRegStateAddTrans(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state,
1387 xmlRegexpErrMemory(ctxt, "adding transition");
1397 xmlRegexpErrMemory(ctxt, "adding transition");
1423 xmlRegStateAddTransTo(ctxt, target, state->no);
1427 xmlRegStatePush(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state) {
1429 if (ctxt->maxStates == 0) {
1430 ctxt->maxStates = 4;
1431 ctxt->states = (xmlRegStatePtr *) xmlMalloc(ctxt->maxStates *
1433 if (ctxt->states == NULL) {
1434 xmlRegexpErrMemory(ctxt, "adding state");
1435 ctxt->maxStates = 0;
1438 } else if (ctxt->nbStates >= ctxt->maxStates) {
1440 ctxt->maxStates *= 2;
1441 tmp = (xmlRegStatePtr *) xmlRealloc(ctxt->states, ctxt->maxStates *
1444 xmlRegexpErrMemory(ctxt, "adding state");
1445 ctxt->maxStates /= 2;
1448 ctxt->states = tmp;
1450 state->no = ctxt->nbStates;
1451 ctxt->states[ctxt->nbStates++] = state;
1457 * @ctxt: a regexp parser context
1464 xmlFAGenerateAllTransition(xmlRegParserCtxtPtr ctxt,
1468 to = xmlRegNewState(ctxt);
1469 xmlRegStatePush(ctxt, to);
1470 ctxt->state = to;
1473 xmlRegStateAddTrans(ctxt, from, NULL, to, -1, REGEXP_ALL_LAX_COUNTER);
1475 xmlRegStateAddTrans(ctxt, from, NULL, to, -1, REGEXP_ALL_COUNTER);
1480 * @ctxt: a regexp parser context
1486 xmlFAGenerateEpsilonTransition(xmlRegParserCtxtPtr ctxt,
1489 to = xmlRegNewState(ctxt);
1490 xmlRegStatePush(ctxt, to);
1491 ctxt->state = to;
1493 xmlRegStateAddTrans(ctxt, from, NULL, to, -1, -1);
1498 * @ctxt: a regexp parser context
1505 xmlFAGenerateCountedEpsilonTransition(xmlRegParserCtxtPtr ctxt,
1508 to = xmlRegNewState(ctxt);
1509 xmlRegStatePush(ctxt, to);
1510 ctxt->state = to;
1512 xmlRegStateAddTrans(ctxt, from, NULL, to, counter, -1);
1517 * @ctxt: a regexp parser context
1524 xmlFAGenerateCountedTransition(xmlRegParserCtxtPtr ctxt,
1527 to = xmlRegNewState(ctxt);
1528 xmlRegStatePush(ctxt, to);
1529 ctxt->state = to;
1531 xmlRegStateAddTrans(ctxt, from, NULL, to, -1, counter);
1536 * @ctxt: a regexp parser context
1544 xmlFAGenerateTransitions(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr from,
1558 if (xmlRegAtomPush(ctxt, atom) < 0) {
1566 xmlFAGenerateEpsilonTransition(ctxt, atom->stop, to);
1570 to = xmlRegNewState(ctxt);
1571 xmlRegStatePush(ctxt, to);
1572 ctxt->state = to;
1573 xmlFAGenerateEpsilonTransition(ctxt, atom->stop, to);
1585 xmlFAGenerateEpsilonTransition(ctxt, atom->start, 0);
1586 xmlFAGenerateEpsilonTransition(ctxt, atom->stop,
1587 ctxt->state);
1589 xmlFAGenerateEpsilonTransition(ctxt, atom->start, to);
1594 xmlFAGenerateEpsilonTransition(ctxt, atom->start, atom->stop);
1595 xmlFAGenerateEpsilonTransition(ctxt, atom->stop, atom->start);
1599 xmlFAGenerateEpsilonTransition(ctxt, atom->stop, atom->start);
1611 newstate = xmlRegNewState(ctxt);
1612 xmlRegStatePush(ctxt, newstate);
1632 copy = xmlRegCopyAtom(ctxt, atom);
1639 if (xmlFAGenerateTransitions(ctxt, atom->start, NULL, copy)
1642 inter = ctxt->state;
1643 counter = xmlRegGetCounter(ctxt);
1644 ctxt->counters[counter].min = atom->min - 1;
1645 ctxt->counters[counter].max = atom->max - 1;
1647 xmlFAGenerateCountedEpsilonTransition(ctxt, inter,
1650 xmlFAGenerateCountedTransition(ctxt, inter,
1653 xmlFAGenerateEpsilonTransition(ctxt, atom->start,
1661 counter = xmlRegGetCounter(ctxt);
1662 ctxt->counters[counter].min = atom->min - 1;
1663 ctxt->counters[counter].max = atom->max - 1;
1665 xmlFAGenerateCountedEpsilonTransition(ctxt, atom->stop,
1668 xmlFAGenerateCountedTransition(ctxt, atom->stop,
1672 xmlFAGenerateEpsilonTransition(ctxt, atom->start0,
1679 ctxt->state = newstate;
1692 to = xmlRegNewState(ctxt);
1694 xmlRegStatePush(ctxt, to);
1699 xmlFAGenerateEpsilonTransition(ctxt, from, to);
1700 ctxt->state = to;
1705 to = xmlRegNewState(ctxt);
1707 xmlRegStatePush(ctxt, to);
1722 tmp = xmlRegNewState(ctxt);
1724 xmlRegStatePush(ctxt, tmp);
1728 xmlFAGenerateEpsilonTransition(ctxt, tmp, to);
1731 if (xmlRegAtomPush(ctxt, atom) < 0) {
1741 xmlRegStateAddTrans(ctxt, from, atom, to, -1, -1);
1742 ctxt->state = end;
1746 xmlFAGenerateEpsilonTransition(ctxt, from, to);
1750 xmlFAGenerateEpsilonTransition(ctxt, from, to);
1751 xmlRegStateAddTrans(ctxt, to, atom, to, -1, -1);
1755 xmlRegStateAddTrans(ctxt, to, atom, to, -1, -1);
1759 xmlFAGenerateEpsilonTransition(ctxt, from, to);
1769 * @ctxt: a regexp parser context
1776 xmlFAReduceEpsilonTransitions(xmlRegParserCtxtPtr ctxt, int fromnr,
1785 from = ctxt->states[fromnr];
1788 to = ctxt->states[tonr];
1814 xmlRegStateAddTrans(ctxt, from, NULL,
1815 ctxt->states[newto],
1823 xmlFAReduceEpsilonTransitions(ctxt, fromnr,
1827 xmlFAReduceEpsilonTransitions(ctxt, fromnr,
1837 xmlRegStateAddTrans(ctxt, from, to->trans[transnr].atom,
1838 ctxt->states[newto],
1841 xmlRegStateAddTrans(ctxt, from, to->trans[transnr].atom,
1842 ctxt->states[newto], counter, -1);
1851 * @ctxt: a regexp parser context
1865 xmlFAEliminateSimpleEpsilonTransitions(xmlRegParserCtxtPtr ctxt) {
1869 for (statenr = 0;statenr < ctxt->nbStates;statenr++) {
1870 state = ctxt->states[statenr];
1896 tmp = ctxt->states[state->transTo[i]];
1904 xmlRegStateAddTrans(ctxt, tmp, tmp->trans[j].atom,
1905 ctxt->states[newto],
1912 ctxt->states[newto]->type = XML_REGEXP_FINAL_STATE;
1925 * @ctxt: a regexp parser context
1929 xmlFAEliminateEpsilonTransitions(xmlRegParserCtxtPtr ctxt) {
1934 if (ctxt->states == NULL) return;
1940 xmlFAEliminateSimpleEpsilonTransitions(ctxt);
1941 for (statenr = 0;statenr < ctxt->nbStates;statenr++) {
1942 state = ctxt->states[statenr];
1948 ctxt->states[statenr] = NULL;
1962 for (statenr = ctxt->nbStates - 1;statenr >= 0;statenr--) {
1963 state = ctxt->states[statenr];
1989 xmlFAReduceEpsilonTransitions(ctxt, statenr,
2005 for (statenr = 0;statenr < ctxt->nbStates;statenr++) {
2006 state = ctxt->states[statenr];
2023 for (statenr = 0;statenr < ctxt->nbStates;statenr++) {
2024 state = ctxt->states[statenr];
2028 state = ctxt->states[0];
2043 if (ctxt->states[newto] == NULL)
2045 if (ctxt->states[newto]->reached == XML_REGEXP_MARK_NORMAL) {
2046 ctxt->states[newto]->reached = XML_REGEXP_MARK_START;
2047 target = ctxt->states[newto];
2056 for (statenr = 1;statenr < ctxt->nbStates;statenr++) {
2057 state = ctxt->states[statenr];
2067 for (statenr = 0;statenr < ctxt->nbStates;statenr++) {
2068 state = ctxt->states[statenr];
2074 ctxt->states[statenr] = NULL;
2581 * @ctxt: a regexp parser context
2588 xmlFARecurseDeterminism(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state,
2601 if (ctxt->flags & AM_AUTOMATA_RNG)
2618 res = xmlFARecurseDeterminism(ctxt, ctxt->states[t1->to],
2640 * @ctxt: a regexp parser context
2647 xmlFAComputesDeterminism(xmlRegParserCtxtPtr ctxt) {
2657 xmlRegPrintCtxt(stdout, ctxt);
2659 if (ctxt->determinist != -1)
2660 return(ctxt->determinist);
2662 if (ctxt->flags & AM_AUTOMATA_RNG)
2668 for (statenr = 0;statenr < ctxt->nbStates;statenr++) {
2669 state = ctxt->states[statenr];
2710 for (statenr = 0;statenr < ctxt->nbStates;statenr++) {
2711 state = ctxt->states[statenr];
2749 ret = xmlFARecurseDeterminism(ctxt, ctxt->states[t1->to],
2784 ctxt->determinist = ret;
4597 * @ctxt: a regexp parser context
4602 xmlFAIsChar(xmlRegParserCtxtPtr ctxt) {
4606 cur = CUR_SCHAR(ctxt->cur, len);
4617 * @ctxt: a regexp parser context
4632 xmlFAParseCharProp(xmlRegParserCtxtPtr ctxt) {
4806 start = ctxt->cur;
4823 blockName = xmlStrndup(start, ctxt->cur - start);
4828 if (ctxt->atom == NULL) {
4829 ctxt->atom = xmlRegNewAtom(ctxt, type);
4830 if (ctxt->atom != NULL)
4831 ctxt->atom->valuep = blockName;
4832 } else if (ctxt->atom->type == XML_REGEXP_RANGES) {
4833 xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg,
4840 * @ctxt: a regexp parser context
4849 xmlFAParseCharClassEsc(xmlRegParserCtxtPtr ctxt) {
4853 if (ctxt->atom == NULL) {
4854 ctxt->atom = xmlRegNewAtom(ctxt, XML_REGEXP_ANYCHAR);
4855 } else if (ctxt->atom->type == XML_REGEXP_RANGES) {
4856 xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg,
4875 xmlFAParseCharProp(ctxt);
4888 xmlFAParseCharProp(ctxt);
4889 if (ctxt->atom != NULL)
4890 ctxt->atom->neg = 1;
4901 if (ctxt->atom == NULL) {
4902 ctxt->atom = xmlRegNewAtom(ctxt, XML_REGEXP_CHARVAL);
4903 if (ctxt->atom != NULL) {
4906 ctxt->atom->codepoint = '\n';
4909 ctxt->atom->codepoint = '\r';
4912 ctxt->atom->codepoint = '\t';
4915 ctxt->atom->codepoint = cur;
4918 } else if (ctxt->atom->type == XML_REGEXP_RANGES) {
4930 xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg,
4972 if (ctxt->atom == NULL) {
4973 ctxt->atom = xmlRegNewAtom(ctxt, type);
4974 } else if (ctxt->atom->type == XML_REGEXP_RANGES) {
4975 xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg,
4985 * @ctxt: a regexp parser context
4994 xmlFAParseCharRange(xmlRegParserCtxtPtr ctxt) {
5023 end = start = CUR_SCHAR(ctxt->cur, len);
5029 * Since we are "inside" a range, we can assume ctxt->cur is past
5030 * the start of ctxt->string, and PREV should be safe
5039 xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg,
5062 end = CUR_SCHAR(ctxt->cur, len);
5073 xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg,
5081 * @ctxt: a regexp parser context
5086 xmlFAParsePosCharGroup(xmlRegParserCtxtPtr ctxt) {
5089 xmlFAParseCharClassEsc(ctxt);
5091 xmlFAParseCharRange(ctxt);
5094 (CUR != 0) && (ctxt->error == 0));
5099 * @ctxt: a regexp parser context
5107 xmlFAParseCharGroup(xmlRegParserCtxtPtr ctxt) {
5108 int n = ctxt->neg;
5109 while ((CUR != ']') && (ctxt->error == 0)) {
5111 int neg = ctxt->neg;
5114 ctxt->neg = !ctxt->neg;
5115 xmlFAParsePosCharGroup(ctxt);
5116 ctxt->neg = neg;
5118 int neg = ctxt->neg;
5119 ctxt->neg = 2;
5122 xmlFAParseCharGroup(ctxt);
5129 ctxt->neg = neg;
5132 xmlFAParsePosCharGroup(ctxt);
5135 ctxt->neg = n;
5140 * @ctxt: a regexp parser context
5146 xmlFAParseCharClass(xmlRegParserCtxtPtr ctxt) {
5149 ctxt->atom = xmlRegNewAtom(ctxt, XML_REGEXP_RANGES);
5150 if (ctxt->atom == NULL)
5152 xmlFAParseCharGroup(ctxt);
5159 xmlFAParseCharClassEsc(ctxt);
5165 * @ctxt: a regexp parser context
5172 xmlFAParseQuantExact(xmlRegParserCtxtPtr ctxt) {
5189 * @ctxt: a regexp parser context
5198 xmlFAParseQuantifier(xmlRegParserCtxtPtr ctxt) {
5203 if (ctxt->atom != NULL) {
5205 ctxt->atom->quant = XML_REGEXP_QUANT_OPT;
5207 ctxt->atom->quant = XML_REGEXP_QUANT_MULT;
5209 ctxt->atom->quant = XML_REGEXP_QUANT_PLUS;
5218 cur = xmlFAParseQuantExact(ctxt);
5226 cur = xmlFAParseQuantExact(ctxt);
5241 if (ctxt->atom != NULL) {
5242 ctxt->atom->quant = XML_REGEXP_QUANT_RANGE;
5243 ctxt->atom->min = min;
5244 ctxt->atom->max = max;
5253 * @ctxt: a regexp parser context
5258 xmlFAParseAtom(xmlRegParserCtxtPtr ctxt) {
5261 codepoint = xmlFAIsChar(ctxt);
5263 ctxt->atom = xmlRegNewAtom(ctxt, XML_REGEXP_CHARVAL);
5264 if (ctxt->atom == NULL)
5266 codepoint = CUR_SCHAR(ctxt->cur, len);
5267 ctxt->atom->codepoint = codepoint;
5284 xmlFAGenerateEpsilonTransition(ctxt, ctxt->state, NULL);
5285 start0 = ctxt->state;
5286 xmlFAGenerateEpsilonTransition(ctxt, ctxt->state, NULL);
5287 start = ctxt->state;
5288 oldend = ctxt->end;
5289 ctxt->end = NULL;
5290 ctxt->atom = NULL;
5291 xmlFAParseRegExp(ctxt, 0);
5297 ctxt->atom = xmlRegNewAtom(ctxt, XML_REGEXP_SUBREG);
5298 if (ctxt->atom == NULL)
5300 ctxt->atom->start = start;
5301 ctxt->atom->start0 = start0;
5302 ctxt->atom->stop = ctxt->state;
5303 ctxt->end = oldend;
5306 xmlFAParseCharClass(ctxt);
5314 * @ctxt: a regexp parser context
5319 xmlFAParsePiece(xmlRegParserCtxtPtr ctxt) {
5322 ctxt->atom = NULL;
5323 ret = xmlFAParseAtom(ctxt);
5326 if (ctxt->atom == NULL) {
5329 xmlFAParseQuantifier(ctxt);
5335 * @ctxt: a regexp parser context
5344 xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr to) {
5348 previous = ctxt->state;
5349 ret = xmlFAParsePiece(ctxt);
5351 if (xmlFAGenerateTransitions(ctxt, previous,
5352 (CUR=='|' || CUR==')') ? to : NULL, ctxt->atom) < 0)
5354 previous = ctxt->state;
5355 ctxt->atom = NULL;
5357 while ((ret != 0) && (ctxt->error == 0)) {
5358 ret = xmlFAParsePiece(ctxt);
5360 if (xmlFAGenerateTransitions(ctxt, previous,
5361 (CUR=='|' || CUR==')') ? to : NULL, ctxt->atom) < 0)
5363 previous = ctxt->state;
5364 ctxt->atom = NULL;
5372 * @ctxt: a regexp parser context
5378 xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) {
5382 start = ctxt->state;
5383 ctxt->end = NULL;
5384 xmlFAParseBranch(ctxt, NULL);
5387 ctxt->state->no);
5389 ctxt->state->type = XML_REGEXP_FINAL_STATE;
5392 ctxt->end = ctxt->state;
5395 end = ctxt->state;
5396 while ((CUR == '|') && (ctxt->error == 0)) {
5402 ctxt->state = start;
5403 ctxt->end = NULL;
5404 xmlFAParseBranch(ctxt, end);
5407 ctxt->state = end;
5408 ctxt->end = end;
5468 xmlRegParserCtxtPtr ctxt;
5470 ctxt = xmlRegNewParserCtxt(regexp);
5471 if (ctxt == NULL)
5475 ctxt->end = NULL;
5476 ctxt->start = ctxt->state = xmlRegNewState(ctxt);
5477 xmlRegStatePush(ctxt, ctxt->start);
5480 xmlFAParseRegExp(ctxt, 1);
5484 if (ctxt->error != 0) {
5485 xmlRegFreeParserCtxt(ctxt);
5488 ctxt->end = ctxt->state;
5489 ctxt->start->type = XML_REGEXP_START_STATE;
5490 ctxt->end->type = XML_REGEXP_FINAL_STATE;
5493 xmlFAEliminateEpsilonTransitions(ctxt);
5496 if (ctxt->error != 0) {
5497 xmlRegFreeParserCtxt(ctxt);
5500 ret = xmlRegEpxFromParse(ctxt);
5501 xmlRegFreeParserCtxt(ctxt);
5616 xmlAutomataPtr ctxt;
5618 ctxt = xmlRegNewParserCtxt(NULL);
5619 if (ctxt == NULL)
5623 ctxt->end = NULL;
5624 ctxt->start = ctxt->state = xmlRegNewState(ctxt);
5625 if (ctxt->start == NULL) {
5626 xmlFreeAutomata(ctxt);
5629 ctxt->start->type = XML_REGEXP_START_STATE;
5630 if (xmlRegStatePush(ctxt, ctxt->start) < 0) {
5631 xmlRegFreeState(ctxt->start);
5632 xmlFreeAutomata(ctxt);
5635 ctxt->flags = 0;
5637 return(ctxt);
6404 * @ctxt: an expression context
6409 xmlExpFreeCtxt(xmlExpCtxtPtr ctxt) {
6410 if (ctxt == NULL)
6412 xmlDictFree(ctxt->dict);
6413 if (ctxt->table != NULL)
6414 xmlFree(ctxt->table);
6415 xmlFree(ctxt);
6472 static xmlExpNodePtr xmlExpNewNode(xmlExpCtxtPtr ctxt, xmlExpNodeType type);
6542 xmlExpNewNode(xmlExpCtxtPtr ctxt, xmlExpNodeType type) {
6545 if (ctxt->nb_nodes >= MAX_NODES)
6553 ctxt->nb_nodes++;
6554 ctxt->nb_cons++;
6569 xmlExpHashGetEntry(xmlExpCtxtPtr ctxt, xmlExpNodeType type,
6576 if (ctxt == NULL)
6592 xmlExpFree(ctxt, left);
6597 xmlExpFree(ctxt, left);
6608 xmlExpFree(ctxt, left);
6612 xmlExpFree(ctxt, right);
6634 xmlExpFree(ctxt, left);
6651 ctxt, XML_EXP_OR, left->exp_right, right,
6654 tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, left->exp_left, tmp,
6657 xmlExpFree(ctxt, left);
6666 tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, right->exp_right,
6669 tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, right->exp_left,
6671 xmlExpFree(ctxt, right);
6679 tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, left,
6682 tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, right->exp_left,
6684 xmlExpFree(ctxt, right);
6698 xmlExpFree(ctxt, right);
6702 xmlExpFree(ctxt, left);
6716 key = kbase % ctxt->size;
6717 if (ctxt->table[key] != NULL) {
6718 for (insert = ctxt->table[key]; insert != NULL;
6745 entry = xmlExpNewNode(ctxt, type);
6786 if (ctxt->table[key] != NULL)
6787 entry->next = ctxt->table[key];
6789 ctxt->table[key] = entry;
6790 ctxt->nbElems++;
6797 * @ctxt: the expression context
6803 xmlExpFree(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp) {
6811 key = exp->key % ctxt->size;
6812 if (ctxt->table[key] == exp) {
6813 ctxt->table[key] = exp->next;
6817 tmp = ctxt->table[key];
6828 xmlExpFree(ctxt, exp->exp_left);
6829 xmlExpFree(ctxt, exp->exp_right);
6831 xmlExpFree(ctxt, exp->exp_left);
6834 ctxt->nb_nodes--;
6852 * @ctxt: the expression context
6861 xmlExpNewAtom(xmlExpCtxtPtr ctxt, const xmlChar *name, int len) {
6862 if ((ctxt == NULL) || (name == NULL))
6864 name = xmlDictLookup(ctxt->dict, name, len);
6867 return(xmlExpHashGetEntry(ctxt, XML_EXP_ATOM, NULL, NULL, name, 0, 0));
6872 * @ctxt: the expression context
6879 * this is true even in case of failure (unless ctxt == NULL).
6884 xmlExpNewOr(xmlExpCtxtPtr ctxt, xmlExpNodePtr left, xmlExpNodePtr right) {
6885 if (ctxt == NULL)
6888 xmlExpFree(ctxt, left);
6889 xmlExpFree(ctxt, right);
6892 return(xmlExpHashGetEntry(ctxt, XML_EXP_OR, left, right, NULL, 0, 0));
6897 * @ctxt: the expression context
6904 * this is true even in case of failure (unless ctxt == NULL).
6909 xmlExpNewSeq(xmlExpCtxtPtr ctxt, xmlExpNodePtr left, xmlExpNodePtr right) {
6910 if (ctxt == NULL)
6913 xmlExpFree(ctxt, left);
6914 xmlExpFree(ctxt, right);
6917 return(xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, left, right, NULL, 0, 0));
6922 * @ctxt: the expression context
6930 * this is true even in case of failure (unless ctxt == NULL).
6935 xmlExpNewRange(xmlExpCtxtPtr ctxt, xmlExpNodePtr subset, int min, int max) {
6936 if (ctxt == NULL)
6940 xmlExpFree(ctxt, subset);
6943 return(xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, subset,
6954 xmlExpGetLanguageInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp,
6974 tmp = xmlExpGetLanguageInt(ctxt, exp->exp_left, list, len, nb);
6977 tmp2 = xmlExpGetLanguageInt(ctxt, exp->exp_right, list, len,
6988 * @ctxt: the expression context
6999 xmlExpGetLanguage(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp,
7001 if ((ctxt == NULL) || (exp == NULL) || (langList == NULL) || (len <= 0))
7003 return(xmlExpGetLanguageInt(ctxt, exp, langList, len, 0));
7007 xmlExpGetStartInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp,
7028 tmp = xmlExpGetStartInt(ctxt, exp->exp_left, list, len, nb);
7032 tmp2 = xmlExpGetStartInt(ctxt, exp->exp_right, list, len,
7040 tmp = xmlExpGetStartInt(ctxt, exp->exp_left, list, len, nb);
7043 tmp2 = xmlExpGetStartInt(ctxt, exp->exp_right, list, len,
7054 * @ctxt: the expression context
7067 xmlExpGetStart(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp,
7069 if ((ctxt == NULL) || (exp == NULL) || (tokList == NULL) || (len <= 0))
7071 return(xmlExpGetStartInt(ctxt, exp, tokList, len, 0));
7090 xmlExpStringDeriveInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, const xmlChar *str)
7119 tmp = xmlExpStringDeriveInt(ctxt, exp->exp_left, str);
7123 ret = xmlExpStringDeriveInt(ctxt, exp->exp_right, str);
7125 xmlExpFree(ctxt, tmp);
7128 ret = xmlExpHashGetEntry(ctxt, XML_EXP_OR, tmp, ret,
7136 ret = xmlExpStringDeriveInt(ctxt, exp->exp_left, str);
7144 ret = xmlExpStringDeriveInt(ctxt, exp->exp_right, str);
7151 ret = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret, exp->exp_right,
7161 ret = xmlExpStringDeriveInt(ctxt, exp->exp_left, str);
7181 tmp = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, exp->exp_left, NULL,
7192 return(xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret, tmp,
7201 * @ctxt: the expression context
7212 xmlExpStringDerive(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp,
7216 if ((exp == NULL) || (ctxt == NULL) || (str == NULL)) {
7223 input = xmlDictExists(ctxt->dict, str, len);
7227 return(xmlExpStringDeriveInt(ctxt, exp, input));
7247 static xmlExpNodePtr xmlExpExpDeriveInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp,
7251 * @ctxt: the expressions context
7265 xmlExpDivide(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, xmlExpNodePtr sub,
7277 tmp = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT,
7283 xmlExpFree(ctxt, tmp);
7286 tmp2 = xmlExpExpDeriveInt(ctxt, tmp, exp);
7288 xmlExpFree(ctxt, tmp);
7295 xmlExpFree(ctxt, tmp2);
7299 xmlExpFree(ctxt, tmp);
7305 xmlExpFree(ctxt, tmp);
7306 xmlExpFree(ctxt, tmp2);
7316 * @ctxt: the expressions context
7326 xmlExpExpDeriveInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, xmlExpNodePtr sub) {
7355 tmp = xmlExpExpDeriveInt(ctxt, exp, sub->exp_left);
7360 ret = xmlExpExpDeriveInt(ctxt, tmp, sub->exp_right);
7361 xmlExpFree(ctxt, tmp);
7368 tmp = xmlExpExpDeriveInt(ctxt, exp, sub->exp_left);
7373 ret = xmlExpExpDeriveInt(ctxt, exp, sub->exp_right);
7375 xmlExpFree(ctxt, tmp);
7378 return(xmlExpHashGetEntry(ctxt, XML_EXP_OR, tmp, ret, NULL, 0, 0));
7439 ret = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub);
7452 return(xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret,
7467 ret = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub->exp_left);
7483 tmp = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret,
7489 tmp2 = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT,
7492 xmlExpFree(ctxt, tmp);
7495 ret = xmlExpExpDeriveInt(ctxt, tmp, tmp2);
7496 xmlExpFree(ctxt, tmp);
7497 xmlExpFree(ctxt, tmp2);
7507 ret = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub);
7510 tmp = xmlExpExpDeriveInt(ctxt, exp->exp_right, sub);
7512 xmlExpFree(ctxt, ret);
7515 return(xmlExpHashGetEntry(ctxt, XML_EXP_OR, ret, tmp, NULL, 0, 0));
7523 tmp = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub->exp_left);
7532 mult = xmlExpDivide(ctxt, sub->exp_left, exp->exp_left,
7551 xmlExpFree(ctxt, tmp);
7571 xmlExpFree(ctxt, tmp);
7589 xmlExpFree(ctxt, tmp);
7610 xmlExpFree(ctxt, tmp);
7633 xmlExpFree(ctxt, tmp);
7647 tmp2 = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, exp->exp_left,
7652 ret = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, tmp, tmp2,
7656 tmp = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub);
7678 tmp2 = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, exp->exp_left,
7682 ret = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, tmp, tmp2,
7702 if (ctxt->tabSize == 0)
7703 ctxt->tabSize = 40;
7705 tab = (const xmlChar **) xmlMalloc(ctxt->tabSize *
7714 len = xmlExpGetStartInt(ctxt, sub, tab, ctxt->tabSize, 0);
7717 temp = (const xmlChar **) xmlRealloc((xmlChar **) tab, ctxt->tabSize * 2 *
7724 ctxt->tabSize *= 2;
7725 len = xmlExpGetStartInt(ctxt, sub, tab, ctxt->tabSize, 0);
7728 tmp = xmlExpStringDeriveInt(ctxt, exp, tab[i]);
7730 xmlExpFree(ctxt, ret);
7734 tmp2 = xmlExpStringDeriveInt(ctxt, sub, tab[i]);
7736 xmlExpFree(ctxt, tmp);
7737 xmlExpFree(ctxt, ret);
7741 tmp3 = xmlExpExpDeriveInt(ctxt, tmp, tmp2);
7742 xmlExpFree(ctxt, tmp);
7743 xmlExpFree(ctxt, tmp2);
7746 xmlExpFree(ctxt, ret);
7754 ret = xmlExpHashGetEntry(ctxt, XML_EXP_OR, ret, tmp3, NULL, 0, 0);
7767 * @ctxt: the expressions context
7780 xmlExpExpDerive(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, xmlExpNodePtr sub) {
7781 if ((exp == NULL) || (ctxt == NULL) || (sub == NULL))
7799 return(xmlExpExpDeriveInt(ctxt, exp, sub));
7804 * @ctxt: the expressions context
7814 xmlExpSubsume(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, xmlExpNodePtr sub) {
7817 if ((exp == NULL) || (ctxt == NULL) || (sub == NULL))
7839 tmp = xmlExpExpDeriveInt(ctxt, exp, sub);
7851 xmlExpFree(ctxt, tmp);
7854 xmlExpFree(ctxt, tmp);
7864 static xmlExpNodePtr xmlExpParseExpr(xmlExpCtxtPtr ctxt);
7867 #define CUR (*ctxt->cur)
7869 #define NEXT ctxt->cur++;
7872 #define SKIP_BLANKS while (IS_BLANK(*ctxt->cur)) ctxt->cur++;
7875 xmlExpParseNumber(xmlExpCtxtPtr ctxt) {
7893 xmlExpParseOr(xmlExpCtxtPtr ctxt) {
7899 base = ctxt->cur;
7900 if (*ctxt->cur == '(') {
7902 ret = xmlExpParseExpr(ctxt);
7904 if (*ctxt->cur != ')') {
7906 xmlExpFree(ctxt, ret);
7917 val = xmlDictLookup(ctxt->dict, BAD_CAST base, ctxt->cur - base);
7920 ret = xmlExpHashGetEntry(ctxt, XML_EXP_ATOM, NULL, NULL, val, 0, 0);
7929 min = xmlExpParseNumber(ctxt);
7931 xmlExpFree(ctxt, ret);
7937 max = xmlExpParseNumber(ctxt);
7942 xmlExpFree(ctxt, ret);
7946 ret = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, ret, NULL, NULL,
7951 ret = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, ret, NULL, NULL,
7956 ret = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, ret, NULL, NULL,
7961 ret = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, ret, NULL, NULL,
7970 xmlExpParseSeq(xmlExpCtxtPtr ctxt) {
7973 ret = xmlExpParseOr(ctxt);
7977 right = xmlExpParseOr(ctxt);
7979 xmlExpFree(ctxt, ret);
7982 ret = xmlExpHashGetEntry(ctxt, XML_EXP_OR, ret, right, NULL, 0, 0);
7990 xmlExpParseExpr(xmlExpCtxtPtr ctxt) {
7993 ret = xmlExpParseSeq(ctxt);
7997 right = xmlExpParseSeq(ctxt);
7999 xmlExpFree(ctxt, ret);
8002 ret = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret, right, NULL, 0, 0);
8011 * @ctxt: the expressions context
8027 xmlExpParse(xmlExpCtxtPtr ctxt, const char *expr) {
8030 ctxt->expr = expr;
8031 ctxt->cur = expr;
8033 ret = xmlExpParseExpr(ctxt);
8035 if (*ctxt->cur != 0) {
8036 xmlExpFree(ctxt, ret);
8149 * @ctxt: an expression context
8156 xmlExpCtxtNbNodes(xmlExpCtxtPtr ctxt) {
8157 if (ctxt == NULL)
8159 return(ctxt->nb_nodes);
8164 * @ctxt: an expression context
8171 xmlExpCtxtNbCons(xmlExpCtxtPtr ctxt) {
8172 if (ctxt == NULL)
8174 return(ctxt->nb_cons);