Added % suffix operator, as in "$1.00 * 10%"
This commit is contained in:
parent
d2062bb54c
commit
0e9f782a05
4 changed files with 22 additions and 4 deletions
|
|
@ -499,14 +499,14 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
|
|||
{
|
||||
// Invalid commodity characters:
|
||||
// SPACE, TAB, NEWLINE, RETURN
|
||||
// 0-9 . , ; - + * / ^ ? : & | ! =
|
||||
// 0-9 . , ; - + * / ^ ? : & | ! = %
|
||||
// < > { } [ ] ( ) @
|
||||
|
||||
static int invalid_chars[256] = {
|
||||
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
|
||||
/* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 20 */ 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* 20 */ 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* 30 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* 40 */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 50 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0,
|
||||
|
|
|
|||
|
|
@ -44,10 +44,23 @@ expr_t::parser_t::parse_value_term(std::istream& in,
|
|||
token_t& tok = next_token(in, tflags);
|
||||
|
||||
switch (tok.kind) {
|
||||
case token_t::VALUE:
|
||||
case token_t::VALUE: {
|
||||
node = new op_t(op_t::VALUE);
|
||||
node->set_value(tok.value);
|
||||
|
||||
token_t& postfix_tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT));
|
||||
if (postfix_tok.kind == token_t::PERCENT) {
|
||||
ptr_op_t prev(node);
|
||||
node = new op_t(op_t::O_DIV);
|
||||
node->set_left(prev);
|
||||
ptr_op_t hundred = new op_t(op_t::VALUE);
|
||||
hundred->set_value(100L);
|
||||
node->set_right(hundred);
|
||||
} else {
|
||||
push_token(postfix_tok);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case token_t::IDENT: {
|
||||
string ident = tok.value.as_string();
|
||||
|
|
|
|||
|
|
@ -278,6 +278,11 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
|
|||
kind = STAR;
|
||||
break;
|
||||
|
||||
case '%':
|
||||
in.get(c);
|
||||
kind = PERCENT;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
in.get(c);
|
||||
kind = QUERY;
|
||||
|
|
|
|||
|
|
@ -84,9 +84,9 @@ struct expr_t::token_t : public noncopyable
|
|||
KW_DIV, // div
|
||||
|
||||
EXCLAM, // !, not
|
||||
PERCENT, // %
|
||||
KW_AND, // &, &&, and
|
||||
KW_OR, // |, ||, or
|
||||
KW_MOD, // %
|
||||
|
||||
KW_IF, // if
|
||||
KW_ELSE, // else
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue