// ni stands for "next int". int ni(buffer& buf) { int i = atoi(buf.front().c_str()); if (i == 0) for(char ch : buf.front()) if (!isdigit(ch)) error("Expected number, found \"" + buf.front() + "\"."); buf.pop_front(); return i; }
std::string comma_list(const buffer& buf) { std::string str; if (buf.size() == 0) str = ""; else if (buf.size() == 1) str = buf.front(); else if (buf.size() == 2) str = buf.front() + " and " + buf.back(); else { buffer::const_iterator it = buf.begin(); str = "and " + *(it++); for (;it != buf.end(); it++) str = *it + ", " + str; } return str; }
// ns stands for "next std::string". std::string ns(buffer& buf) { std::string s = buf.front(); buf.pop_front(); return s; }
// nch stands of "next char". char nch(buffer& buf) { char ch = (buf.front()[0]); buf.pop_front(); return ch; }