munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.5k stars 1.01k forks source link

bug report #1058

Closed wuyueandrew closed 2 years ago

wuyueandrew commented 2 years ago

The function can match only first param and following params cannot be matched cuz the function is return after first loop. file location: craftinginterpreters/blob/master/java/com/craftinginterpreters/lox/Parser.java

private boolean match(TokenType... types) { for (TokenType type : types) { if (check(type)) { advance(); return true; } } return false; }

How about

private boolean match(TokenType... types) { for (TokenType type : types) { if (!check(type)) { return false; } advance(); } return true; }

wuyueandrew commented 2 years ago

i was wrong, the func means match anyone of the params, not all of them