Skip to content

Commit e414a70

Browse files
committed
Avoid throwing for backtracking
This makes running under Windows much faster.
1 parent cc53cb2 commit e414a70

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

generator/dparsergen/generator/parsercodegen.d

+17-10
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,8 @@ void createParseFunction(ref CodeWriter code, LRGraph graph, size_t stateNr, con
11161116
foreach (i, s; node.backtrackStates)
11171117
{
11181118
prods ~= grammar.productionString(productions[i]);
1119+
if (i == 0)
1120+
code.writeln("lastError = null;");
11191121
mixin(genCode("code", q{
11201122
// try $(s) $(grammar.productionString(productions[i]))
11211123
try
@@ -1125,25 +1127,30 @@ void createParseFunction(ref CodeWriter code, LRGraph graph, size_t stateNr, con
11251127
gotoParent = $(parseFunctionName(graph, s))(r, rl);
11261128
if (gotoParent < 0)
11271129
{
1128-
throw lastError;
1130+
assert(lastError !is null);
11291131
}
1130-
if ($(tokenSetCode(grammar, node.elements[0].lookahead, "lexer", true)))
1132+
else if ($(tokenSetCode(grammar, node.elements[0].lookahead, "lexer", true)))
11311133
{
1132-
throw new SingleParseException!Location(text("unexpected \"", lexer.front.content, "\" \"", lexer.tokenName(lexer.front.symbol), "\""), lexer.front.currentLocation, lexer.front.currentTokenEnd);
1134+
lastError = new SingleParseException!Location(text("unexpected \"", lexer.front.content, "\" \"", lexer.tokenName(lexer.front.symbol), "\""), lexer.front.currentLocation, lexer.front.currentTokenEnd);
1135+
}
1136+
else
1137+
{
1138+
result = r;
1139+
resultLocation = rl;
1140+
return gotoParent;
11331141
}
1134-
result = r;
1135-
resultLocation = rl;
1136-
return gotoParent;
11371142
}
11381143
catch(ParseException e)
11391144
{
11401145
if (!e.allowBacktrack())
11411146
throw e;
1142-
lastError = null;
1143-
*lexer = savedLexer;
1144-
lastTokenEnd = savedLastTokenEnd;
1145-
exceptions[$(i)] = e;
1147+
lastError = e;
11461148
}
1149+
assert(lastError !is null);
1150+
*lexer = savedLexer;
1151+
lastTokenEnd = savedLastTokenEnd;
1152+
exceptions[$(i)] = lastError;
1153+
lastError = null;
11471154
}));
11481155
}
11491156
mixin(genCode("code", q{

0 commit comments

Comments
 (0)