summaryrefslogtreecommitdiff
path: root/token.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-08-01 01:56:13 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-08-01 01:56:13 -0400
commitc98be731733176c9e9afb690619d806630ec9090 (patch)
treeaedd210699a652a2b77b2a1985c14a1bdd9c227a /token.cc
parent567902b1731db6f1ace85a7bc384b55ffd0948ab (diff)
downloadfork-ledger-c98be731733176c9e9afb690619d806630ec9090.tar.gz
fork-ledger-c98be731733176c9e9afb690619d806630ec9090.tar.bz2
fork-ledger-c98be731733176c9e9afb690619d806630ec9090.zip
Re-implemented ?: parsing in value expressions. "a ? b : c" is implemented by
translating it into the equivalent syntax tree "(a & b) | c", since this expression evaluates to the value of b if a is true, otherwise c.
Diffstat (limited to 'token.cc')
-rw-r--r--token.cc22
1 files changed, 16 insertions, 6 deletions
diff --git a/token.cc b/token.cc
index adc7069f..27180e99 100644
--- a/token.cc
+++ b/token.cc
@@ -164,7 +164,7 @@ void expr_t::token_t::next(std::istream& in, const unsigned int pflags)
char buf[256];
READ_INTO_(in, buf, 255, c, length, c != ']');
if (c != ']')
- unexpected(c, ']');
+ expected(']', c);
in.get(c);
length++;
@@ -182,7 +182,7 @@ void expr_t::token_t::next(std::istream& in, const unsigned int pflags)
char buf[4096];
READ_INTO_(in, buf, 4095, c, length, c != delim);
if (c != delim)
- unexpected(c, delim);
+ expected(delim, c);
in.get(c);
length++;
kind = VALUE;
@@ -196,7 +196,7 @@ void expr_t::token_t::next(std::istream& in, const unsigned int pflags)
temp.parse(in, AMOUNT_PARSE_NO_MIGRATE);
in.get(c);
if (c != '}')
- unexpected(c, '}');
+ expected('}', c);
length++;
kind = VALUE;
value = temp;
@@ -231,6 +231,16 @@ void expr_t::token_t::next(std::istream& in, const unsigned int pflags)
kind = STAR;
break;
+ case '?':
+ in.get(c);
+ kind = QUERY;
+ break;
+
+ case ':':
+ in.get(c);
+ kind = COLON;
+ break;
+
case 'c':
case 'C':
case 'p':
@@ -266,7 +276,7 @@ void expr_t::token_t::next(std::istream& in, const unsigned int pflags)
char buf[256];
READ_INTO_(in, buf, 255, c, length, c != '/');
if (c != '/')
- unexpected(c, '/');
+ expected('/', c);
in.get(c);
length++;
@@ -379,9 +389,9 @@ void expr_t::token_t::unexpected()
}
}
-void expr_t::token_t::unexpected(char c, char wanted)
+void expr_t::token_t::expected(char wanted, char c)
{
- if (static_cast<unsigned char>(c) == 0xff) {
+ if (c == '\0') {
if (wanted)
throw_(parse_error, "Missing '" << wanted << "'");
else