Skip to content

Commit

Permalink
Stop adding tokens when we arrive at our last defined token
Browse files Browse the repository at this point in the history
  • Loading branch information
raidiant committed Sep 6, 2018
1 parent e3c4ff7 commit dbc1fc8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/parser.lemon
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
// Mostly based on the following SO post, but we instead put it in a std::vector
// https://stackoverflow.com/questions/11705737/expected-token-using-lemon-parser-generator/13010096#13010096
std::vector<std::string> expectedTokens;
int n = sizeof(yyTokenName) / sizeof(yyTokenName[0]);
for (int i = 0; i < n; ++i) {

// we loop over all known tokens, if we exceed our defined tokens we exit
// our last defined token is TOKEN_STRING, so we halt when we go past it
for (int i = 0; i <= TOKEN_STRING; ++i) {
int a = yy_find_shift_action(yypParser, (YYCODETYPE)i);
if (a < YYNSTATE + YYNRULE) expectedTokens.emplace_back(yyTokenName[i]);
}
Expand Down

0 comments on commit dbc1fc8

Please sign in to comment.