Exemple #1
0
/* parse_list • parsing ordered or unordered list block */
static size_t
parse_list(struct buf *ob, struct render *rndr,
			char *data, size_t size, int flags) {
	struct buf *work = new_work_buffer(rndr);
	size_t i = 0, j;

	while (i < size) {
		j = parse_listitem(work, rndr, data + i, size - i, &flags);
		i += j;
		if (!j || (flags & MKD_LI_END)) break; }

	if (rndr->make.list)
		rndr->make.list(ob, work, flags, rndr->make.opaque);
	release_work_buffer(rndr, work);
	return i; }
Exemple #2
0
//if singleline is non-zero, then parsing is for a single line
//All expressions using this are not strictly ordered (as in, a + b will be reordered to + a b)
parse_part parse_listitems(parser_state state, int singleln) {
    parse_part result;
    parse_part tmp;

    state.index -= 1;

    lexid exprid = EXPR_LEXID;
    exprid.attr.intval = 0; //Set strictness property to 0


    if (boundsCheck(state)) {
        exprid.loc = getCurrent(state).loc;
    }

    result.tree = lexid_tree_init(exprid);
    
    lexid current = SPACE_LEXID;

    while (singleln ? lexid_eq(current, SPACE_LEXID) : isWhite(current)) {
        while (singleln ? lexid_eq(current, SPACE_LEXID) : isWhite(current)) {
            state.index += 1;
            current = getCurrent(state);
        }
        if (singleln && isWhite(current)) {
            continue;
        }
        if (lexid_eq(current, COMMA_LEXID) || lexid_eq(current, RPAREN_LEXID)) {
            continue;
        }
        tmp = parse_listitem(state);
        result.tree = lexid_tree_addchild(result.tree, tmp.tree);
        state.index = tmp.state.index;
        current = getCurrent(state);
    }
    result.state = state;
    return result;
}
Exemple #3
0
group_t*
cfg_load(FILE *fp) {
    char line[MAXLINELEN];
    group_t *head = NULL, *curr = NULL;

    if (fp == NULL)
        return NULL;

    rewind(fp);

    lineno = 0;
    while(fgets(line, sizeof(line), fp)) {
        char *p = line;
	++lineno;
        /* Skip any whitespace at start of line */
        skip_whitespace(&p);
        /* Skip line if only whitespace */
        if (!*p) continue;

        switch(*p) {
            case '[':
                /* parse config group */
                {
                    group_t *newgrp = parse_group(p);
                    if (curr == NULL) {
                        head = curr = newgrp;
                    } else {
                        curr->next = newgrp;
                        curr = newgrp;
                    }
                }
                break;
            case '{':
                /* parse list item */
                {
                    variable_t *var = parse_listitem(p,head);
                    if (curr != NULL) {
                        add_var_to_group(curr, var);
                    } else {
                        fprintf(stderr, "%s:%d: Found list item but no current group!\n", __func__, lineno);
                    }
                }
                break;
            default:
                /* check for simple key/value */
                if (isalpha(*p)) {
                    variable_t *var = parse_keyvalue(&p,head);
                    if (curr != NULL) {
                        add_var_to_group(curr, var);
                    } else {
                        fprintf(stderr, "%s:%d: Found variable but no current group!\n", __func__, lineno);
                    }
                } else {
                    fprintf(stderr, "%s:%d: unknown line: %s\n", __func__, lineno, line);
                }
                break;
        }
    }

    //fclose(fp);

    return head;
}