private void ParsePluralFormsHeader() { string pluralForms; if (!Headers.TryGetValue(PluralFormsHeaderKey, out pluralForms)) return; Script script = null; try { var scanner = new ExpressionEvaluator.Scanner(); scanner.SetSource(pluralForms, 0); var parser = new ExpressionEvaluator.Parser(scanner); parser.Parse(); script = parser.Script; } catch (Exception e) { throw new GettextException("Error parsing the plural forms header", e); } if (script == null) return; var assignmentNplurals = script.Assignments.SingleOrDefault(x => x.Var == "nplurals"); var assignmentN = script.Assignments.SingleOrDefault(x => x.Var == "plural"); if (assignmentNplurals == null || assignmentN == null) return; { var state = new ExpressionState(); assignmentNplurals.Execute(state); NPlurals = (int) state.GetVar("nplurals"); } { PluralExpression = assignmentN; GetPluralIndex = n => { var state = new ExpressionState(); state.SetVar("nplurals", NPlurals); state.SetVar("n", n); assignmentN.Execute(state); return (int) state.GetVar("plural"); }; } }
public long Execute(ExpressionState state) { var execute = Expr.Execute(state); state.SetVar(Var, execute); return execute; }