-
Notifications
You must be signed in to change notification settings - Fork 26
/
parsetype.cc
92 lines (77 loc) · 1.96 KB
/
parsetype.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "parsetype.hpp"
std::ostream &operator<<(std::ostream &out, const parse_t &obj)
{
char op = obj.op;
// '#' should never be output as operator
switch ( op ) {
case 'I':
case 'F':
case 'f':
case ' ': out << obj.val; op = ','; break;
case 'n': out << '-'; op = '#'; break;
case '!': out << '!'; op = '#'; break;
case '(': op = '#'; break;
case 'E': out << "ISEOF"; op = '#'; break;
case 'M': out << "MATCH"; op = '#'; break;
case 'U': out << "UNIQUE"; op = ','; break;
case 'A': out << "INARRAY"; op = ','; break;
}
// Special case quote strings
if ( op=='S' ) return out << '"' << obj.val << '"';
// Special case compare operators, as these are not stored in 'op'
if ( op=='?' ) {
if ( obj.nargs()!=2 ) return out << "#error in compare#";
out << obj.args[0] << obj.val << obj.args[1];
return out;
}
// Special case array variable using []
if ( op=='v' ) {
out << obj.val;
if ( obj.nargs()>0 ) {
out << '[' << obj.args[0];
for(size_t i=1; i<obj.nargs(); i++) out << ',' << obj.args[i];
out << ']';
}
return out;
}
// Special case variable assignment
if ( op=='a' ) {
out << obj.args[0] << '=' << obj.args[1];
return out;
}
if ( obj.nargs()>0 ) {
out << '(' << obj.args[0];
for(size_t i=1; i<obj.nargs(); i++) out << op << obj.args[i];
out << ')';
}
return out;
}
namespace checktestdata {
std::ostream& operator<<(std::ostream& os, const none_t&) {
return os << "<no value>";
}
value_t::operator bigint() const
{
return boost::get<bigint>(val);
}
value_t::operator mpf_class() const
{
if(const bigint* p = boost::get<bigint>(&val))
return (*p).to_mpz();
return boost::get<mpf_class>(val);
}
std::ostream& operator <<(std::ostream &os, const value_t &val)
{
return os << val.val;
}
std::string value_t::getstr() const
{
return boost::get<std::string>(val);
}
std::string value_t::tostr() const
{
std::stringstream ss;
ss << *this;
return ss.str();
}
} // namespace checktestdata