forked from anse1/sqlsmith
-
Notifications
You must be signed in to change notification settings - Fork 8
/
prod.cc
48 lines (42 loc) · 870 Bytes
/
prod.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
/// @file
/// @brief Base class for grammar productions
#include <typeinfo>
#include <stdexcept>
#include "prod.hh"
#include "impedance.hh"
prod::prod(struct prod *parent)
: pprod(parent)
{
if (parent) {
level = parent->level + 1;
scope = parent->scope;
} else {
scope = 0;
level = 0;
}
}
void prod::indent(std::ostream &out)
{
out << std::endl;
for (int i = 0; i < level; i++)
out << " ";
}
void prod::retry()
{
impedance::retry(this);
if (retries++ <= retry_limit)
return;
impedance::limit(this);
throw std::runtime_error(std::string("excessive retries in ")
+ typeid(*this).name());
}
void prod::match()
{
if (!impedance::matched(this))
throw std::runtime_error("impedance mismatch");
}
void prod::fail(const char *reason)
{
impedance::fail(this);
throw std::runtime_error(reason);
}