void wpl_text::parse_value(wpl_namespace *parent_namespace) { ignore_string_match(NEWLINE, NON_NEWLINE_WS); const char *start = get_string_pointer(); const char *end; int par_level = 1; while (par_level > 0 && !at_end()) { end = get_string_pointer(); if (ignore_letter('{')) { if (ignore_string("@LOOP")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); chunks.emplace_back(new wpl_text_chunks::loop(text, exp)); parse_expression(parent_namespace, exp); ignore_string_match(NEWLINE, NON_NEWLINE_WS); parse_text(parent_namespace, text); start = get_string_pointer(); } else if (ignore_string("@CONDITION")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); wpl_text *text_else = NULL; wpl_text_chunks::condition *condition = new wpl_text_chunks::condition(text, exp); chunks.emplace_back(condition); parse_expression(parent_namespace, exp); ignore_string_match(NEWLINE, NON_NEWLINE_WS); parse_text(parent_namespace, text); start = get_string_pointer(); } else if (ignore_string("@TEMPLATE")) { push_chunk (start, end); wpl_matcher_position pos = get_position(); char name[WPL_VARNAME_SIZE]; ignore_whitespace(); get_word(name); wpl_template *my_template = parent_namespace->find_template(name); if (!my_template) { load_position(pos); THROW_ELEMENT_EXCEPTION("Unknown template name"); } chunks.emplace_back(new wpl_text_chunks::html_template(my_template)); ignore_whitespace(); if (!ignore_letter ('}')) { THROW_ELEMENT_EXCEPTION("Expected } after TEMPLATE call definition"); } start = get_string_pointer(); } else if (ignore_string("@")) { push_chunk (start, end); wpl_expression *exp = new wpl_expression_loose_end(); chunks.emplace_back(new wpl_text_chunks::expression(exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(WHITESPACE, 0); if (!ignore_letter('}')) { THROW_ELEMENT_EXCEPTION("Expected '}' after expression-in-TEXT"); } start = get_string_pointer(); } else { par_level++; } } else if (ignore_letter('}')) { par_level--; } else { if (!ignore_string_match(NON_CURLY|UTF8, 0)) { cerr << "Unknown character '" << hex << get_letter(ALL) << "'\n"; THROW_ELEMENT_EXCEPTION("Syntax error in text-string"); } } } if (par_level != 0) { THROW_ELEMENT_EXCEPTION("Excepted '}' after TEXT-block"); } end = get_string_pointer() - 2; while (M_NON_NEWLINE_WHITESPACE (*end)) { end--; } end++; if (end > start) { push_chunk (start, end); } }
void wpl_text::parse_value(wpl_namespace *parent_namespace) { ignore_string_match(NEWLINE, NON_NEWLINE_WS); const char *start = get_string_pointer(); const char *end; int par_level = 1; while (par_level > 0 && !at_end()) { end = get_string_pointer(); if (ignore_letter('{')) { if (ignore_string("@LOOP")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); chunks.emplace_back(new wpl_text_chunks::loop(text, exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(NEWLINE, NON_NEWLINE_WS); text->load_position(get_position()); text->parse_value(parent_namespace); load_position(text->get_position()); start = get_string_pointer(); } else if (ignore_string("@")) { push_chunk (start, end); wpl_expression *exp = new wpl_expression_loose_end(); chunks.emplace_back(new wpl_text_chunks::expression(exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(WHITESPACE, 0); if (!ignore_letter('}')) { THROW_ELEMENT_EXCEPTION("Expected '}' after expression-in-TEXT"); } start = get_string_pointer(); } else { par_level++; } } else if (ignore_letter('}')) { par_level--; } else { if (!ignore_string_match(NON_CURLY|UTF8, 0)) { cerr << "Unknown character '" << hex << get_letter(ALL) << "'\n"; THROW_ELEMENT_EXCEPTION("Syntax error in text-string"); } } } if (par_level != 0) { THROW_ELEMENT_EXCEPTION("Excepted '}' after TEXT-block"); } end = get_string_pointer() - 2; while (M_NON_NEWLINE_WHITESPACE (*end)) { end--; } end++; if (end > start) { push_chunk (start, end); } }