Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public IEnumerable <IEnumerable <OutputRecord> > GetResults(ParseEngine engine, IEnumerable <OutputRecord> first)
 {
     do
     {
         yield return(first);
     }while (!engine.IsFailure(first = Operand.Execute(engine)));
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public override IEnumerable <OutputRecord> Execute(ParseEngine engine)
        {
            IEnumerable <OutputRecord> result = Operand.Execute(engine);

            if (!engine.IsFailure(result))
            {
                return(result);
            }
            return(NoResults);
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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));
            }
        }
Ejemplo n.º 9
0
        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));
            }
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }