Relaxed parsing so that tabs are allowed in several places that
required spaces before.
This commit is contained in:
parent
0ac399d68f
commit
ced1d5a308
1 changed files with 28 additions and 28 deletions
56
textual.cc
56
textual.cc
|
|
@ -430,15 +430,12 @@ static inline void parse_symbol(char *& p, std::string& symbol)
|
||||||
symbol = std::string(p + 1, 0, q - p - 1);
|
symbol = std::string(p + 1, 0, q - p - 1);
|
||||||
p = q + 2;
|
p = q + 2;
|
||||||
} else {
|
} else {
|
||||||
char * q = std::strchr(p, ' ');
|
char * q = next_element(p);
|
||||||
if (q) {
|
symbol = p;
|
||||||
*q = '\0';
|
if (q)
|
||||||
symbol = std::string(p, 0, q - p);
|
p = q;
|
||||||
p = q + 1;
|
else
|
||||||
} else {
|
|
||||||
symbol = p;
|
|
||||||
p += symbol.length();
|
p += symbol.length();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (symbol.empty())
|
if (symbol.empty())
|
||||||
throw parse_error(path, linenum, "Failed to parse commodity");
|
throw parse_error(path, linenum, "Failed to parse commodity");
|
||||||
|
|
@ -599,15 +596,19 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
case 'P': { // a pricing entry
|
case 'P': { // a pricing entry
|
||||||
std::time_t date;
|
std::time_t date;
|
||||||
|
|
||||||
char * b = skip_ws(line + 1);
|
char * date_field = skip_ws(line + 1);
|
||||||
char * p = std::strchr(b, ' ');
|
char * time_field = next_element(date_field);
|
||||||
if (! p) break;
|
if (! time_field) break;
|
||||||
p = std::strchr(skip_ws(p), ' ');
|
char * symbol_and_price = next_element(time_field);
|
||||||
if (! p) break;
|
if (! symbol_and_price) break;
|
||||||
*p++ = '\0';
|
|
||||||
|
char date_buffer[64];
|
||||||
|
std::strcpy(date_buffer, date_field);
|
||||||
|
date_buffer[std::strlen(date_field)] = ' ';
|
||||||
|
std::strcpy(&date_buffer[std::strlen(date_field) + 1], time_field);
|
||||||
|
|
||||||
struct std::tm when;
|
struct std::tm when;
|
||||||
if (strptime(b, "%Y/%m/%d %H:%M:%S", &when)) {
|
if (strptime(date_buffer, "%Y/%m/%d %H:%M:%S", &when)) {
|
||||||
date = std::mktime(&when);
|
date = std::mktime(&when);
|
||||||
} else {
|
} else {
|
||||||
throw parse_error(path, linenum, "Failed to parse date");
|
throw parse_error(path, linenum, "Failed to parse date");
|
||||||
|
|
@ -616,8 +617,8 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
std::string symbol;
|
std::string symbol;
|
||||||
amount_t price;
|
amount_t price;
|
||||||
|
|
||||||
parse_symbol(p, symbol);
|
parse_symbol(symbol_and_price, symbol);
|
||||||
price.parse(skip_ws(p));
|
price.parse(symbol_and_price);
|
||||||
|
|
||||||
commodity_t * commodity = commodity_t::find_commodity(symbol, true);
|
commodity_t * commodity = commodity_t::find_commodity(symbol, true);
|
||||||
commodity->add_price(date, price);
|
commodity->add_price(date, price);
|
||||||
|
|
@ -646,12 +647,13 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '-': { // option setting
|
case '-': { // option setting
|
||||||
char * p = std::strchr(line, ' ');
|
char * p = next_element(line);
|
||||||
if (! p)
|
if (! p) {
|
||||||
p = std::strchr(line, '=');
|
p = std::strchr(line, '=');
|
||||||
if (p)
|
if (p)
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
process_option(config_options, line + 2, p ? skip_ws(p) : NULL);
|
}
|
||||||
|
process_option(config_options, line + 2, p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -701,16 +703,14 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
}
|
}
|
||||||
|
|
||||||
case '!': { // directive
|
case '!': { // directive
|
||||||
char * p = std::strchr(line, ' ');
|
char * p = next_element(line);
|
||||||
if (p)
|
|
||||||
*p++ = '\0';
|
|
||||||
std::string word(line + 1);
|
std::string word(line + 1);
|
||||||
if (word == "include") {
|
if (word == "include") {
|
||||||
push_var<std::string> save_path(path);
|
push_var<std::string> save_path(path);
|
||||||
push_var<unsigned int> save_src_idx(src_idx);
|
push_var<unsigned int> save_src_idx(src_idx);
|
||||||
push_var<unsigned int> save_linenum(linenum);
|
push_var<unsigned int> save_linenum(linenum);
|
||||||
|
|
||||||
path = skip_ws(p);
|
path = p;
|
||||||
if (path[0] != '/' && path[0] != '\\') {
|
if (path[0] != '/' && path[0] != '\\') {
|
||||||
std::string::size_type pos = save_path.prev.rfind('/');
|
std::string::size_type pos = save_path.prev.rfind('/');
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
|
|
@ -725,14 +725,14 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
}
|
}
|
||||||
else if (word == "account") {
|
else if (word == "account") {
|
||||||
account_t * acct;
|
account_t * acct;
|
||||||
acct = account_stack.front()->find_account(skip_ws(p));
|
acct = account_stack.front()->find_account(p);
|
||||||
account_stack.push_front(acct);
|
account_stack.push_front(acct);
|
||||||
}
|
}
|
||||||
else if (word == "end") {
|
else if (word == "end") {
|
||||||
account_stack.pop_front();
|
account_stack.pop_front();
|
||||||
}
|
}
|
||||||
else if (word == "alias") {
|
else if (word == "alias") {
|
||||||
char * b = skip_ws(p);
|
char * b = p;
|
||||||
if (char * e = std::strchr(b, '=')) {
|
if (char * e = std::strchr(b, '=')) {
|
||||||
char * z = e - 1;
|
char * z = e - 1;
|
||||||
while (std::isspace(*z))
|
while (std::isspace(*z))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue