Beispiel #1
0
/*
 * Test 2: (g1000 aaa bbb eee fff g)
 */
static void test2(pp_t *pp) {
  pp_push_token(pp, tag_open(opens + 5));   // g1000
  pp_push_token(pp, tag_atomic(atoms + 0)); // aaa
  pp_push_token(pp, tag_atomic(atoms + 1)); // bbb
  pp_push_token(pp, tag_atomic(atoms + 4)); // eee
  pp_push_token(pp, tag_atomic(atoms + 5)); // fff
  pp_push_token(pp, tag_atomic(atoms + 6)); // g
  pp_push_token(pp, tag_close(closes + 0));
  flush_pp(pp);
}
Beispiel #2
0
/*
 * Test 4: (f3 (f2 (f1 (f0 ccc)) h))
 */
static void test4(pp_t *pp) {
  pp_push_token(pp, tag_open(opens + 3)); // f3
  pp_push_token(pp, tag_open(opens + 2)); // f2
  pp_push_token(pp, tag_open(opens + 1)); // f1
  pp_push_token(pp, tag_open(opens + 0)); // f0
  pp_push_token(pp, tag_atomic(atoms + 2)); // cc
  pp_push_token(pp, tag_close(closes + 0));
  pp_push_token(pp, tag_close(closes + 0));
  pp_push_token(pp, tag_atomic(atoms + 7)); // h
  pp_push_token(pp, tag_close(closes + 0));
  pp_push_token(pp, tag_close(closes + 0));
  flush_pp(pp);
}
Beispiel #3
0
/*
 * Test1: (f0 aaa (h50000 (f2 bbb ccc)) ddd)
 */
static void test1(pp_t *pp) {
  pp_push_token(pp, tag_open(opens + 0)); // f0
  pp_push_token(pp, tag_atomic(atoms + 0)); // aaa
  pp_push_token(pp, tag_open(opens + 9));   // h50000
  pp_push_token(pp, tag_open(opens + 2));   // f2
  pp_push_token(pp, tag_atomic(atoms + 1)); // bbb
  pp_push_token(pp, tag_atomic(atoms + 2)); // ccc
  pp_push_token(pp, tag_close(closes + 0));
  pp_push_token(pp, tag_close(closes + 0));
  pp_push_token(pp, tag_atomic(atoms + 3)); // ddd
  pp_push_token(pp, tag_close(closes + 0));
  flush_pp(pp);
}
Beispiel #4
0
/*
 * Print atomic token tk then free it.
 * - it's always freed
 */
static void print_atomic_token(printer_t *p, pp_atomic_token_t *tk) {
  uint32_t new_col;

  if (p->area.truncate) {
    if (p->col + 4 <= p->margin) {
      /*
       * truncate mode, line not full, nothing pending
       */
      assert(!p->full_line && p->pending_tokens.size == 0);

      print_blank(p);
      new_col = p->col + tk->size;
      if (new_col + 4 <= p->margin) {
        // tk fits and there's room for ' ...' after it
        print_atomic(p, tk);
      } else if (new_col <= p->margin) {
        // we can't tell whether tk fits fully yet
        // because we may need ellipsis after tk.
        p->pending_col = p->col;
        p->col = new_col;
        pvector_push(&p->pending_tokens, tag_atomic(tk));
      } else {
        // tk does not fit: print it truncated followed by ellipsis
        print_atomic_truncated(p, tk);
        p->full_line = true;
      }

    } else if (!p->full_line) {
      /*
       * truncate mode, line not full, tokens pending
       */
      assert(p->col <= p->margin && p->pending_tokens.size > 0);

      // add tk to the pending tokens if it fits
      new_col = p->col + tk->size + (! p->no_space);
      if (new_col <= p->margin) {
        p->col = new_col;
        pvector_push(&p->pending_tokens, tag_atomic(tk));
      } else {
        // the pending tokens don't fit
        // print what we can + ellipsis
        print_pending_truncated(p);
        free_atomic_token(p, tk);
        p->full_line = true;
      }

    } else {
      /*
       * truncate mode, line full, nothing pending
       */
      assert(p->pending_tokens.size == 0);
      free_atomic_token(p, tk);
    }

  } else {
    /*
     * don't truncate
     */
    print_blank(p);
    print_atomic(p, tk);
  }
}
Beispiel #5
0
/*
 * Initialize an atomic token tk and return the tagged pointer tag_atomic(tk).
 * - size = token size (when converted to a string)
 * - user_tag = whatever the converter needs
 */
void *init_atomic_token(pp_atomic_token_t *tk, uint32_t size, uint32_t user_tag) {
  tk->size = size;
  tk->user_tag = user_tag;

  return tag_atomic(tk);
}