summaryrefslogtreecommitdiff
path: root/xmlregexp.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2004-04-19 05:38:48 +0000
committerMike Hommey <mh@glandium.org>2004-04-19 05:38:48 +0000
commit81bcf076ea11e114a60e429338a15748066de163 (patch)
tree276010ab5d17f27a96c05f77004aa84a1763af7b /xmlregexp.c
parentd09ab089457ae3c20cc98f9afa03379c6ebf9598 (diff)
downloadlibxml2-81bcf076ea11e114a60e429338a15748066de163.tar.gz
Load /tmp/tmp.LovooJ/libxml2-2.6.9 intoupstream/2.6.9
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'xmlregexp.c')
-rw-r--r--xmlregexp.c69
1 files changed, 36 insertions, 33 deletions
diff --git a/xmlregexp.c b/xmlregexp.c
index 057458b..d1e6f38 100644
--- a/xmlregexp.c
+++ b/xmlregexp.c
@@ -1214,14 +1214,15 @@ xmlRegStateAddTrans(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state,
#ifdef DEBUG_REGEXP_GRAPH
printf("Add trans from %d to %d ", state->no, target->no);
if (count == REGEXP_ALL_COUNTER)
- printf("all transition");
+ printf("all transition\n");
else if (count >= 0)
- printf("count based %d", count);
+ printf("count based %d\n", count);
else if (counter >= 0)
- printf("counted %d", counter);
+ printf("counted %d\n", counter);
else if (atom == NULL)
- printf("epsilon transition");
- printf("\n");
+ printf("epsilon transition\n");
+ else if (atom != NULL)
+ xmlRegPrintAtom(stdout, atom);
#endif
state->trans[state->nbTrans].atom = atom;
@@ -3862,50 +3863,33 @@ xmlFAParsePiece(xmlRegParserCtxtPtr ctxt) {
/**
* xmlFAParseBranch:
* @ctxt: a regexp parser context
- * @first: is taht the first
*
* [2] branch ::= piece*
8
*/
static int
-xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, int first) {
+xmlFAParseBranch(xmlRegParserCtxtPtr ctxt) {
xmlRegStatePtr previous;
- xmlRegAtomPtr prevatom = NULL;
int ret;
previous = ctxt->state;
ret = xmlFAParsePiece(ctxt);
if (ret != 0) {
- if (first) {
- if (xmlFAGenerateTransitions(ctxt, previous, NULL, ctxt->atom) < 0)
- return(-1);
- previous = ctxt->state;
- } else {
- prevatom = ctxt->atom;
- }
+ if (xmlFAGenerateTransitions(ctxt, previous, NULL, ctxt->atom) < 0)
+ return(-1);
+ previous = ctxt->state;
ctxt->atom = NULL;
}
while ((ret != 0) && (ctxt->error == 0)) {
ret = xmlFAParsePiece(ctxt);
if (ret != 0) {
- if (first) {
- if (xmlFAGenerateTransitions(ctxt, previous, NULL,
- ctxt->atom) < 0)
+ if (xmlFAGenerateTransitions(ctxt, previous, NULL,
+ ctxt->atom) < 0)
return(-1);
- } else {
- if (xmlFAGenerateTransitions(ctxt, previous, NULL,
- prevatom) < 0)
- return(-1);
- prevatom = ctxt->atom;
- }
previous = ctxt->state;
ctxt->atom = NULL;
}
}
- if (!first) {
- if (xmlFAGenerateTransitions(ctxt, previous, ctxt->end, prevatom) < 0)
- return(-1);
- }
return(0);
}
@@ -3918,12 +3902,21 @@ xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, int first) {
*/
static void
xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) {
- xmlRegStatePtr start, end, oldend;
+ xmlRegStatePtr start, end, oldend, oldstart;
oldend = ctxt->end;
+ oldstart = ctxt->state;
+ /* if not top start should have been generated by an epsilon trans */
start = ctxt->state;
- xmlFAParseBranch(ctxt, (ctxt->end == NULL));
+ ctxt->end = NULL;
+ xmlFAParseBranch(ctxt);
+ if (top) {
+#ifdef DEBUG_REGEXP_GRAPH
+ printf("State %d is final\n", ctxt->state->no);
+#endif
+ ctxt->state->type = XML_REGEXP_FINAL_STATE;
+ }
if (CUR != '|') {
ctxt->end = ctxt->state;
return;
@@ -3932,11 +3925,21 @@ xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) {
while ((CUR == '|') && (ctxt->error == 0)) {
NEXT;
ctxt->state = start;
+ ctxt->end = NULL;
+ xmlFAParseBranch(ctxt);
+ if (top) {
+ ctxt->state->type = XML_REGEXP_FINAL_STATE;
+#ifdef DEBUG_REGEXP_GRAPH
+ printf("State %d is final\n", ctxt->state->no);
+#endif
+ } else {
+ xmlFAGenerateEpsilonTransition(ctxt, ctxt->state, end);
+ }
+ }
+ if (!top) {
+ ctxt->state = end;
ctxt->end = end;
- xmlFAParseBranch(ctxt, 0);
}
- if (!top)
- ctxt->end = oldend;
}
/************************************************************************