Fix infinite loops during table generation for left-recursive rules

Add function calls for arbitrary expressions and dot property access to javascript grammar
This commit is contained in:
Max Brunsfeld 2014-03-26 22:43:08 -07:00
parent 3f770ff3c3
commit 820b6f4020
7 changed files with 2824 additions and 2292 deletions

View file

@ -19,14 +19,19 @@ namespace tree_sitter {
class FirstSet : public rules::RuleFn<set<Symbol>> {
const PreparedGrammar grammar;
set<Symbol> visited_symbols;
public:
explicit FirstSet(const PreparedGrammar &grammar) : grammar(grammar) {}
void visit(const Symbol *rule) {
if (grammar.has_definition(*rule)) {
value = apply(grammar.rule(*rule));
} else {
value = set<Symbol>({ *rule });
if (visited_symbols.find(*rule) == visited_symbols.end()) {
visited_symbols.insert(*rule);
if (grammar.has_definition(*rule)) {
value = apply(grammar.rule(*rule));
} else {
value = set<Symbol>({ *rule });
}
}
}

View file

@ -1,4 +1,5 @@
#include "compiler/build_tables/rule_can_be_blank.h"
#include <set>
#include "tree_sitter/compiler.h"
#include "compiler/prepared_grammar.h"
#include "compiler/rules/symbol.h"
@ -8,6 +9,8 @@
#include "compiler/rules/blank.h"
namespace tree_sitter {
using std::set;
namespace build_tables {
class CanBeBlank : public rules::RuleFn<bool> {
protected:
@ -34,13 +37,17 @@ namespace tree_sitter {
class CanBeBlankRecursive : public CanBeBlank {
const PreparedGrammar grammar;
set<rules::Symbol> visited_symbols;
using CanBeBlank::visit;
public:
explicit CanBeBlankRecursive(const PreparedGrammar &grammar) : grammar(grammar) {}
void visit(const rules::Symbol *rule) {
value = grammar.has_definition(*rule) && apply(grammar.rule(*rule));
if (visited_symbols.find(*rule) == visited_symbols.end()) {
visited_symbols.insert(*rule);
value = grammar.has_definition(*rule) && apply(grammar.rule(*rule));
}
}
};