diff --git a/templates/c++/lr.h b/templates/c++/lr.h index 2fc88f7..7a86463 100644 --- a/templates/c++/lr.h +++ b/templates/c++/lr.h @@ -40,6 +40,7 @@ class {{name}} { */ struct Token { Token(const {{name}}_Symbol& sym, const Value& val) : symbol(sym), value(val) {} + Token(const {{name}}_Symbol& sym, Value&& val) : symbol(sym), value(std::move(val)) {} {{name}}_Symbol symbol; Value value; }; @@ -118,6 +119,9 @@ inline std::string to_string({{name}}_Symbol s) { case {{name}}_Symbol::{{symbol}}: return "{{symbol}}"; {{/symbols}} + default: + //should not happen + return "?"; } } @@ -159,7 +163,8 @@ Value {{name}}::parse() { if ((TABLE[top][i] & 0x3) != ERROR) expected.emplace_back(static_cast<{{name}}_Symbol>(i)); } - Value errorVal = error(tok, expected); + Token report = Token{tok.symbol, std::move(tok.value)}; + Value errorVal = error(report, expected); while (!valueStack.empty() && (TABLE[stateStack.top()][verr] & 0x3) == ERROR) { valueStack.pop(); @@ -216,7 +221,7 @@ Value {{name}}::parse() { case ACCEPT: assert(stateStack.size() == 2); assert(valueStack.size() == 1); - return valueStack.top().value; + return std::move(valueStack.top().value); default: //IMPOSSIBLE break;