예제 #1
0
int Validator_StartElement(PyObject *self, PyObject *name)
{
  PyObject *element_type;
  Context *context;
  PyObject *dfa;

  if (!Validator_Check(self)) {
    PyErr_BadInternalCall();
    return -1;
  }

#ifdef DEBUG_VALIDATION
  fprintf(stderr, "Validator_StartElement(name=");
  PyObject_Print(name, stderr, 0);
  fprintf(stderr, ")\n");
#endif

  /* Switch to this element's content model.  element_type will be NULL
   * if not found, following code will just consider that as an ANY content
   * model to allow for continued  processing if error reporting doesn't
   * raise an exception. */
  element_type = PyDict_GetItem(Validator_Elements(self), name);
  context = Validator_FreeContext(self);
  if (context == NULL) {
    /* create a new context */
    context = Context_New(element_type);
    if (context == NULL) {
      return -1;
    }
  } else {
    /* reuse an existing context */
    Validator_FreeContext(self) = context->next;
    context->element = element_type;
  }

  /* setup initial state */
  if (element_type != NULL) {
    dfa = ElementType_GET_MODEL(element_type);
    /* dfa may be NULL for an ANY content model */
    if (dfa != NULL) {
      context->state = DFA_GetInitialState(dfa);
    } else {
      context->state = NULL;
    }
  }

  /* make it the active context */
  context->next = Validator_Context(self);
  Validator_Context(self) = context;

  return element_type != NULL;
}
예제 #2
0
파일: builder.c 프로젝트: abed-hawa/amara
ParserState_AddContext(ParserState *self, NodeObject *node)
{
  Context *context = self->free_context;
  if (context != NULL) {
    /* reuse an existing context */
    context->node = node;

    /* Set the node children working set */
    _Container_SetWorkingChildren(node,context->children,context->children_allocated);

    self->free_context = context->next;
  } else {
    /* create a new context */
    context = Context_New(node);
    if (context == NULL) return NULL;
  }

  /* make it the active context */
  context->next = self->context;
  self->context = context;
  return context;
}