Moves in the generated parser
This commit is contained in:
parent
53f5093019
commit
3f524078c2
|
@ -40,6 +40,7 @@ class {{name}} {
|
||||||
*/
|
*/
|
||||||
struct Token {
|
struct Token {
|
||||||
Token(const {{name}}_Symbol& sym, const Value& val) : symbol(sym), value(val) {}
|
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;
|
{{name}}_Symbol symbol;
|
||||||
Value value;
|
Value value;
|
||||||
};
|
};
|
||||||
|
@ -118,6 +119,9 @@ inline std::string to_string({{name}}_Symbol s) {
|
||||||
case {{name}}_Symbol::{{symbol}}:
|
case {{name}}_Symbol::{{symbol}}:
|
||||||
return "{{symbol}}";
|
return "{{symbol}}";
|
||||||
{{/symbols}}
|
{{/symbols}}
|
||||||
|
default:
|
||||||
|
//should not happen
|
||||||
|
return "?";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +163,8 @@ Value {{name}}<Value>::parse() {
|
||||||
if ((TABLE[top][i] & 0x3) != ERROR)
|
if ((TABLE[top][i] & 0x3) != ERROR)
|
||||||
expected.emplace_back(static_cast<{{name}}_Symbol>(i));
|
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) {
|
while (!valueStack.empty() && (TABLE[stateStack.top()][verr] & 0x3) == ERROR) {
|
||||||
valueStack.pop();
|
valueStack.pop();
|
||||||
|
@ -216,7 +221,7 @@ Value {{name}}<Value>::parse() {
|
||||||
case ACCEPT:
|
case ACCEPT:
|
||||||
assert(stateStack.size() == 2);
|
assert(stateStack.size() == 2);
|
||||||
assert(valueStack.size() == 1);
|
assert(valueStack.size() == 1);
|
||||||
return valueStack.top().value;
|
return std::move(valueStack.top().value);
|
||||||
default:
|
default:
|
||||||
//IMPOSSIBLE
|
//IMPOSSIBLE
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue