finished_lambdas = set()
for key, lambda_stack in new_lambda_stacks.items():
if not lambda_stack:
finished_lambdas.add(key)
for finished_lambda in finished_lambdas:
del new_lambda_stacks[finished_lambda]
return GrammarState(nonterminal_stack=new_stack,
After Change
assert all(self._lambda_stacks[key][-1] == left_side for key in self._lambda_stacks)
new_stack = self._nonterminal_stack[:-1]
new_lambda_stacks = {key: self._lambda_stacks[key][:-1] for key in self._lambda_stacks}
productions = self._get_productions_from_string(right_side)
// Looking for lambda productions, but not for cells or columns with the word "lambda" in
// them.
if "lambda" in productions[0] and "fb:" not in productions[0]:
production = productions[0]
if production[0] == """ and production[-1] == """:
// The production rule with a lambda is typically "<t,d> -> ["lambda x", d]". We
// need to strip the quotes.
production = production[1:-1]
lambda_variable = production.split(" ")[1]
// The left side must be formatted as "<t,d>", where "t" is the type of the lambda
// variable, and "d" is the return type of the lambda function. We need to pull out the
// "t" here. TODO(mattg): this is pretty limiting, but I"m not sure how general we
// should make this.
if len(left_side) != 5:
raise NotImplementedError("Can"t handle this type yet:", left_side)
lambda_type = left_side[1]
new_lambda_stacks[(lambda_type, lambda_variable)] = []
for production in reversed(productions):
if self._is_nonterminal(production):
new_stack.append(production)
for lambda_stack in new_lambda_stacks.values():
lambda_stack.append(production)
// If any of the lambda stacks have now become empty, we remove them from our dictionary.
new_lambda_stacks = {key: new_lambda_stacks[key]
for key in new_lambda_stacks if new_lambda_stacks[key]}
return GrammarState(nonterminal_stack=new_stack,
lambda_stacks=new_lambda_stacks,