Fix bug in FIRST set function

This commit is contained in:
Max Brunsfeld 2014-02-13 18:52:17 -08:00
parent 2ee9455174
commit bf07522026
3 changed files with 62 additions and 36 deletions

View file

@ -32,11 +32,16 @@ namespace tree_sitter {
value = set_union(apply(rule->left, grammar), apply(rule->right, grammar));
}
bool can_be_blank(const rule_ptr &rule) {
if (rule_can_be_blank(rule)) return true;
auto symbol = std::dynamic_pointer_cast<const Symbol>(rule);
return (symbol.get() && grammar.has_definition(*symbol) && rule_can_be_blank(grammar.rule(*symbol)));
}
void visit(const Seq *rule) {
if (rule_can_be_blank(rule->left)) {
value = set_union(apply(rule->left, grammar), apply(rule->right, grammar));
} else {
value = apply(rule->left, grammar);
value = apply(rule->left, grammar);
if (can_be_blank(rule->left)) {
value = set_union(value, apply(rule->right, grammar));
}
}