public override IEnumerable <OutputRecord> Execute(ParseEngine context) { context.Log(ToString()); context.Log("{"); // if (!context.Grammar.IsTokenGrammar) // Console.WriteLine("Executing " + Name); IEnumerable <OutputRecord> nonterminal = context.ApplyNonterminal(this, context.Position); // if (!context.Grammar.IsTokenGrammar) // Console.WriteLine("Executed " + Name); // if (!context.IsFailure(nonterminal) && !context.Grammar.IsTokenGrammar) // Logger.WriteLine("Accepted " + Name + " (" + nonterminal.Concatenate(" ", o => o.OutputType == OutputType.None ? o.ToString() : "") + ")"); if (context.IsFailure(nonterminal)) { context.Log(ParseEngine.Indent + "Failed"); } else { context.Log(ParseEngine.Indent + "Succeeded"); } context.Log("}"); return(nonterminal); }
public IEnumerable <IEnumerable <OutputRecord> > GetResults(ParseEngine engine, IEnumerable <OutputRecord> first) { do { yield return(first); }while (!engine.IsFailure(first = Operand.Execute(engine))); }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { var result = NoResults; IEnumerable <OutputRecord> current; var mark = engine.Mark(); int count; for (count = 0; !engine.IsFailure(current = Operand.Execute(engine)); count++) { if (count > Max) { engine.Reset(mark); return(null); } result = result.Concat(current); } if (count < Min) { engine.Reset(mark); return(null); } return(result); }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { var mark = engine.Mark(); IEnumerable <OutputRecord> result = Operand.Execute(engine); engine.Reset(mark); return(!engine.IsFailure(result) ? NoResults : null); }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { IEnumerable <OutputRecord> result = Operand.Execute(engine); if (!engine.IsFailure(result)) { return(result); } return(NoResults); }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { var current = Enclosure.Execute(engine); if (engine.IsFailure(current)) { return(current); } Func <IEnumerable <OutputRecord> > predicate = () => { var mark = engine.Mark(); var result = Enclosure.Execute(engine); engine.Reset(mark); return(result); }; engine.AddInterceptor(predicate); try { var operandResult = Operand.Execute(engine); if (engine.IsFailure(operandResult)) { return(operandResult); } current = current.Concat(operandResult); } finally { engine.RemoveInterceptor(predicate); } var closeResult = Enclosure.Execute(engine); if (engine.IsFailure(closeResult)) { return(closeResult); } return(current.Concat(closeResult)); }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { IEnumerable <OutputRecord> result = NoResults; IEnumerable <OutputRecord> current; while (!engine.IsFailure(current = Operand.Execute(engine))) { result = result.Concat(current); } return(result); }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { IEnumerable <OutputRecord> first = Operand.Execute(engine); if (engine.IsFailure(first)) { return(first); } else { return(GetResults(engine, first).ToArray().SelectMany(o => o)); } }
public IEnumerable <OutputRecord> Eval(ParseEngine context) { int startPosition = context.Position; IEnumerable <OutputRecord> children = Expression.Execute(context); if (context.IsFailure(children)) { return(children); } else { int endPosition = context.Position; return(AsResult(children, startPosition, endPosition)); } }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { var mark = engine.Mark(); IEnumerable <OutputRecord> result = Operand.Execute(engine); IEnumerable <OutputRecord> returnValue; if (engine.IsFailure(result)) { returnValue = NoResults; } else { returnValue = null; } engine.Reset(mark); return(returnValue); }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { var mark = engine.Mark(); IEnumerable <OutputRecord> result = NoResults; foreach (Expression expression in Expressions) { IEnumerable <OutputRecord> current = expression.Execute(engine); if (engine.IsFailure(current)) { engine.Reset(mark); return(current); } result = result.Concat(current); } return(result); }
public override IEnumerable <OutputRecord> Execute(ParseEngine engine) { IEnumerable <OutputRecord> nullResult = null; foreach (Expression expression in Expressions) { var current = expression.Execute(engine); if (!engine.IsFailure(current)) { return(current); } else if (nullResult == null && current != null) { nullResult = current; } } return(nullResult); }