Logo Search packages:      
Sourcecode: yaz version File versions

struct ccl_token* ccl_parser_tokenize ( CCL_parser  cclp,
const char *  command 
) [read]

Splits CCL command string into individual tokens using a CCL parser.

Definition at line 205 of file ccltoken.c.

References ccl_parser::bibset, ccl_qual_search_special(), ccl_parser::ccl_token_and, ccl_parser::ccl_token_not, ccl_parser::ccl_token_or, ccl_parser::ccl_token_set, ccl_token::kind, ccl_token::len, ccl_token::name, ccl_token::next, and ccl_token::prev.

Referenced by ccl_find_str(), and ccl_tokenize().

{
    const char *aliases;
    const unsigned char *cp = (const unsigned char *) command;
    struct ccl_token *first = NULL;
    struct ccl_token *last = NULL;

    while (1)
    {
      while (*cp && strchr (" \t\r\n", *cp))
      {
          cp++;
          continue;
      }
      if (!first)
      {
          first = last = (struct ccl_token *)xmalloc (sizeof (*first));
          ccl_assert (first);
          last->prev = NULL;
      }
      else
      {
          last->next = (struct ccl_token *)xmalloc (sizeof(*first));
          ccl_assert (last->next);
          last->next->prev = last;
          last = last->next;
      }
      last->next = NULL;
      last->name = (const char *) cp;
      last->len = 1;
      switch (*cp++)
      {
        case '\0':
            last->kind = CCL_TOK_EOL;
            return first;
      case '(':
          last->kind = CCL_TOK_LP;
          break;
      case ')':
          last->kind = CCL_TOK_RP;
          break;
      case ',':
          last->kind = CCL_TOK_COMMA;
          break;
      case '%':
      case '!':
          last->kind = CCL_TOK_PROX;
            while (isdigit(*cp))
          {
            ++ last->len;
            cp++;
          }
          break;
      case '>':
      case '<':
      case '=':
          if (*cp == '=' || *cp == '<' || *cp == '>')
          {
            cp++;
            last->kind = CCL_TOK_REL;
            ++ last->len;
          }
          else if (cp[-1] == '=')
            last->kind = CCL_TOK_EQ;
          else
            last->kind = CCL_TOK_REL;
          break;
      case '\"':
          last->kind = CCL_TOK_TERM;
          last->name = (const char *) cp;
          last->len = 0;
          while (*cp && *cp != '\"')
          {
            cp++;
            ++ last->len;
          }
          if (*cp == '\"')
            cp++;
          break;
      default:
          if (!strchr ("(),%!><= \t\n\r", cp[-1]))
          {
            while (*cp && !strchr ("(),%!><= \t\n\r", *cp))
            {
                cp++;
                ++ last->len;
            }
          }
          last->kind = CCL_TOK_TERM;

          aliases = ccl_qual_search_special(cclp->bibset, "and");
          if (!aliases)
            aliases = cclp->ccl_token_and;
          if (token_cmp (cclp, aliases, last))
              last->kind = CCL_TOK_AND;

          aliases = ccl_qual_search_special(cclp->bibset, "or");
          if (!aliases)
            aliases = cclp->ccl_token_or;
          if (token_cmp (cclp, aliases, last))
              last->kind = CCL_TOK_OR;

          aliases = ccl_qual_search_special(cclp->bibset, "not");
          if (!aliases)
            aliases = cclp->ccl_token_not;
            if (token_cmp (cclp, aliases, last))
              last->kind = CCL_TOK_NOT;

          aliases = ccl_qual_search_special(cclp->bibset, "set");
          if (!aliases)
            aliases = cclp->ccl_token_set;

          if (token_cmp (cclp, aliases, last))
              last->kind = CCL_TOK_SET;
      }
    }
    return first;
}


Generated by  Doxygen 1.6.0   Back to index