summaryrefslogtreecommitdiff
path: root/libadhocutil/lexer.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-10-15 01:50:25 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-10-15 01:50:25 +0100
commit1316de20367d3e2b4772a062ea374bc69818d5ce (patch)
tree209c30b3a9d2bc3ea6239258c76fcaddb6e20ce9 /libadhocutil/lexer.cpp
parentFix possible test failure if a new resource happens to get the same address a... (diff)
downloadlibadhocutil-1316de20367d3e2b4772a062ea374bc69818d5ce.tar.bz2
libadhocutil-1316de20367d3e2b4772a062ea374bc69818d5ce.tar.xz
libadhocutil-1316de20367d3e2b4772a062ea374bc69818d5ce.zip
Minor tidy up and add basic doxygen commentslibadhocutil-0.3.6
Diffstat (limited to 'libadhocutil/lexer.cpp')
-rw-r--r--libadhocutil/lexer.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/libadhocutil/lexer.cpp b/libadhocutil/lexer.cpp
index 95e079b..83d2666 100644
--- a/libadhocutil/lexer.cpp
+++ b/libadhocutil/lexer.cpp
@@ -15,7 +15,7 @@ namespace AdHoc {
Lexer::extract(const gchar * string, size_t length) const
{
ExecuteState es;
- while (es.position < length) {
+ while (es.pos < length) {
const Rule * selected = nullptr;
for (const auto & r : rules) {
const auto & s = boost::get<0>(r);
@@ -23,24 +23,23 @@ namespace AdHoc {
continue;
}
const auto & p = boost::get<1>(r);
- if (p->matches(string, length, es.position)) {
+ if (p->matches(string, length, es.pos)) {
selected = &r;
break;
}
}
if (!selected) {
- throw std::runtime_error(std::string("Unexpected input in state (" + es.getState() + ") at ") + (string + es.position));
+ throw std::runtime_error(std::string("Unexpected input in state (" + es.getState() + ") at ") + (string + es.pos));
}
- es.pattern = boost::get<1>(*selected);
+ es.pat = boost::get<1>(*selected);
const auto & h = boost::get<2>(*selected);
h(&es);
- es.position += es.pattern->matchedLength();
+ es.pos += es.pat->matchedLength();
}
-
}
Lexer::ExecuteState::ExecuteState() :
- position(0)
+ pos(0)
{
stateStack.push_back(InitialState);
}
@@ -74,5 +73,17 @@ namespace AdHoc {
{
return stateStack.size();
}
+
+ size_t
+ Lexer::ExecuteState::position() const
+ {
+ return pos;
+ }
+
+ Lexer::PatternPtr
+ Lexer::ExecuteState::pattern() const
+ {
+ return pat;
+ }
}