Esempio n. 1
0
/** Checks for next tag */
static
void proc_before(
   PPOS*                 ppos                /**< input stream position */
   )
{
   int c;

   assert(ppos        != NULL);
   assert(ppos->state == STATE_BEFORE);

   c = skip_space(ppos);

   if (c != '<')
   {
      xml_error(ppos, "Expecting '<'");
      ppos->state = STATE_ERROR;
   }
   else
   {
      c = getsymbol(ppos);

      switch(c)
      {
      case EOF :
         xml_error(ppos, "Unexpected EOF");
         ppos->state = STATE_ERROR;
         break;
      case '!' :
         handle_decl(ppos);
         break;
      case '?' :
         handle_pi(ppos);
         break;
      case '/' :
         handle_endtag(ppos);
         break;
      default :
         ungetsymbol(ppos, c);
         handle_starttag(ppos);
         break;
      }
   }
}
Esempio n. 2
0
static int
lexer_callback(tdi_lexer_event *event_, void *self_)
{
    tdi_soup_parser *self = self_;
    tdi_parser_event event;

    switch (event_->type) {
    case TDI_LEXER_EVENT_STARTTAG:
        return handle_starttag(self, &event, event_);

    case TDI_LEXER_EVENT_ENDTAG:
        return handle_endtag(self, &event, event_);

    case TDI_LEXER_EVENT_TEXT:
        if (self->inempty && close_empty(self) == -1) return -1;

        event.type = TDI_PARSER_EVENT_TEXT;
        event.info.text.data = event_->info.text.data;
        return !self->cb(&event, self->cb_ctx) ? 0 : -1;

    case TDI_LEXER_EVENT_COMMENT:
        if (self->inempty && close_empty(self) == -1) return -1;

        event.type = TDI_PARSER_EVENT_COMMENT;
        event.info.comment.data = event_->info.comment.data;
        return !self->cb(&event, self->cb_ctx) ? 0 : -1;

    case TDI_LEXER_EVENT_MSECTION:
        if (self->inempty && close_empty(self) == -1) return -1;

        event.type = TDI_PARSER_EVENT_MSECTION;
        event.info.msection.data = event_->info.msection.data;
        event.info.msection.name = event_->info.msection.name;
        event.info.msection.value = event_->info.msection.value;
        return !self->cb(&event, self->cb_ctx) ? 0 : -1;

    case TDI_LEXER_EVENT_DECL:
        if (self->inempty && close_empty(self) == -1) return -1;

        event.type = TDI_PARSER_EVENT_DECL;
        event.info.decl.data = event_->info.decl.data;
        event.info.decl.name = event_->info.decl.name;
        event.info.decl.value = event_->info.decl.value;
        return !self->cb(&event, self->cb_ctx) ? 0 : -1;

    case TDI_LEXER_EVENT_PI:
        if (self->inempty && close_empty(self) == -1) return -1;

        event.type = TDI_PARSER_EVENT_PI;
        event.info.pi.data = event_->info.pi.data;
        return !self->cb(&event, self->cb_ctx) ? 0 : -1;

    case TDI_LEXER_EVENT_ESCAPE:
        break;
    }

    /* Should not happen */
    PyErr_SetNone(PyExc_AssertionError);
    self->last_error = TDI_PARSER_ERR_ENV;
    return -1;
}