| #include <errno.h> | #include <errno.h> | ||||
| int BXParser::get() { | int BXParser::get() { | ||||
| int ch = stream_.get(); | |||||
| if (ch == '\n') { | |||||
| line_ += 1; | |||||
| ch_ = 1; | |||||
| if (dataidx_ < datalen_) { | |||||
| return buf_[dataidx_++]; | |||||
| } | |||||
| dataidx_ = 0; | |||||
| stream_.read(buf_, sizeof(buf_)); | |||||
| datalen_ = stream_.gcount(); | |||||
| if (datalen_ == 0) { | |||||
| return EOF; | |||||
| } | |||||
| return buf_[dataidx_++]; | |||||
| } | |||||
| int BXParser::peek() { | |||||
| if (dataidx_ < datalen_) { | |||||
| return buf_[dataidx_]; | |||||
| } else { | } else { | ||||
| ch_ += 1; | |||||
| return stream_.peek(); | |||||
| } | } | ||||
| } | |||||
| return ch; | |||||
| int BXParser::peek2() { | |||||
| if (dataidx_ + 1 < datalen_) { | |||||
| return buf_[dataidx_ + 1]; | |||||
| } else { | |||||
| stream_.get(); | |||||
| int ch = stream_.peek(); | |||||
| stream_.unget(); | |||||
| return ch; | |||||
| } | |||||
| } | } | ||||
| BXParser::Operator BXParser::readOperator() { | BXParser::Operator BXParser::readOperator() { |
| void parse(BXVariables &vars); | void parse(BXVariables &vars); | ||||
| void parseList(const BXVariables &vars, std::vector<std::string> &values); | void parseList(const BXVariables &vars, std::vector<std::string> &values); | ||||
| int peek() { return stream_.peek(); } | |||||
| int peek2() { stream_.get(); int ch = peek(); stream_.unget(); return ch; } | |||||
| int get(); | int get(); | ||||
| void skip(char); | |||||
| int peek(); | |||||
| int peek2(); | |||||
| void skip(char expected); | |||||
| void skip() { get(); } | void skip() { get(); } | ||||
| int line() const { return line_; } | int line() const { return line_; } | ||||
| int line_; | int line_; | ||||
| int ch_; | int ch_; | ||||
| std::istream &stream_; | std::istream &stream_; | ||||
| char buf_[1024]; | |||||
| size_t dataidx_ = 0; | |||||
| size_t datalen_ = 0; | |||||
| }; | }; | ||||
| class BXWriter { | class BXWriter { |