Moves in the generated parser
This commit is contained in:
parent
53f5093019
commit
3f524078c2
|
@ -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}}<Value>::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}}<Value>::parse() {
|
|||
case ACCEPT:
|
||||
assert(stateStack.size() == 2);
|
||||
assert(valueStack.size() == 1);
|
||||
return valueStack.top().value;
|
||||
return std::move(valueStack.top().value);
|
||||
default:
|
||||
//IMPOSSIBLE
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue