1 | /// @file |
---|---|
2 | /// @brief Base class for grammar productions |
3 | #include <typeinfo> |
4 | #include <stdexcept> |
5 | #include "prod.hh" |
6 | #include "impedance.hh" |
7 | |
8 | prod::prod(struct prod *parent) : pprod(parent) { |
9 | if (parent) { |
10 | level = parent->level + 1; |
11 | scope = parent->scope; |
12 | } else { |
13 | scope = 0; |
14 | level = 0; |
15 | } |
16 | } |
17 | |
18 | void prod::indent(std::ostream &out) { |
19 | out << std::endl; |
20 | for (int i = 0; i < level; i++) |
21 | out << " "; |
22 | } |
23 | |
24 | void prod::retry() { |
25 | impedance::retry(this); |
26 | if (retries++ <= retry_limit) |
27 | return; |
28 | |
29 | impedance::limit(this); |
30 | throw std::runtime_error(std::string("excessive retries in ") + typeid(*this).name()); |
31 | } |
32 | |
33 | void prod::match() { |
34 | if (!impedance::matched(this)) |
35 | throw std::runtime_error("impedance mismatch"); |
36 | } |
37 | |
38 | void prod::fail(const char *reason) { |
39 | impedance::fail(this); |
40 | throw std::runtime_error(reason); |
41 | } |
42 |