struct token *lexer_next_token(struct lexer_book *bk, struct dag_lookup_set *s) { struct token *head; if(list_size(bk->token_queue) == 0) { if(bk->eof) return NULL; lexer_read_line(bk); return lexer_next_token(bk, s); } head = list_pop_head(bk->token_queue); if(head->type == SUBSTITUTION) { char *substitution = dag_lookup(head->lexeme, s); struct lexer_book *bk_s; if(!substitution) { debug(D_NOTICE, "Variable %s has not yet been defined at line %d.\n", head->lexeme, bk->line_number); return lexer_next_token(bk, s); } bk_s = lexer_init_book(STRING, dag_lookup(head->lexeme, s), bk->line_number, bk->column_number); lexer_append_all_tokens(bk, bk_s); lexer_free_book(bk_s); lexer_free_token(head); head = list_pop_head(bk->token_queue); } return head; }
char *dag_lookup_str(const char *name, void *arg) { struct dag_variable_value *v = dag_lookup(name, arg); if(v) return xxstrdup(v->value); else return NULL; }
void dag_parse_append_variable(struct lexer_book *bk, int nodeid, struct dag_node *n, const char *name, const char *value) { struct dag_lookup_set sd = { bk->d, NULL, NULL, NULL }; struct dag_variable_value *vd = dag_lookup(name, &sd); struct dag_variable_value *v; if(n) { v = dag_get_variable_value(name, n->variables, nodeid); if(v) { dag_variable_value_append_or_create(v, value); } else { char *new_value; if(vd) { new_value = string_format("%s %s", vd->value, value); } else { new_value = xxstrdup(value); } dag_variable_add_value(name, n->variables, nodeid, new_value); free(new_value); } } else { if(vd) { dag_variable_value_append_or_create(vd, value); } else { dag_variable_add_value(name, bk->d->variables, nodeid, value); } } }