Ejemplo n.º 1
0
        public override IMatched <Unit> ParseStatement(ParseState state, Token[] tokens)
        {
            var className = tokens[3].Text;

            state.Colorize(tokens, Color.Keyword, Color.Whitespace, Color.Class);

            var values = new Hash <string, (IObject[], IRangeItem)>();
            var dataComparisandNames = new List <string>();
            var dataTypeClass        = new DataTypeClass(className);

            if (Module.Global.RegisterClass(dataTypeClass).If(out _, out var exception))
            {
                Module.Global.ForwardReference(className);
                IRangeItem ordinal = (Int)0;

                if (state.Advance().ValueOrOriginal(out _, out var original))
                {
                    while (state.More)
                    {
                        var parser = new DataComparisandParser(className, values, ordinal);
                        if (parser.Scan(state).If(out _, out var anyException))
                        {
                            if (dataTypeClass.RegisterDataComparisand(parser.Name, (IObject)parser.Ordinal).If(out _, out var regException))
                            {
                                dataComparisandNames.Add(parser.Name);
                                ordinal = parser.Ordinal.Successor;
                            }
                            else
                            {
                                return(failedMatch <Unit>(regException));
                            }
                        }
                        else if (anyException.If(out exception))
                        {
                            return(failedMatch <Unit>(exception));
                        }
                        else
                        {
                            break;
                        }
                    }

                    state.Regress();
                }
                else
                {
                    return(original);
                }

                state.AddStatement(new DataType(className, values.ToHash(i => i.Key, i =>
                {
                    var(data, rangeItem) = i.Value;
                    return(data, (IObject)rangeItem);
                })));

                return(Unit.Matched());
            }
Ejemplo n.º 2
0
        public override IEnumerable <IObject> List()
        {
            while (range.Compare(current, stop))
            {
                yield return(current.Object);

                current = range.NextValue(current);
            }
        }
Ejemplo n.º 3
0
 public override IMaybe <IObject> Next()
 {
     if (range.Compare(current, stop))
     {
         var result = current;
         current = range.NextValue(current);
         return(result.Object.Some());
     }
     else
     {
         return(none <IObject>());
     }
 }
Ejemplo n.º 4
0
        public Range(IRangeItem start, IObjectCompare stop, bool inclusive, int increment = 1) : this()
        {
            this.start     = start;
            startObj       = this.start.Object;
            this.stop      = stop;
            stopObj        = this.stop.Object;
            this.inclusive = inclusive;
            this.increment = increment;
            if (this.increment > 0)
            {
                next = i =>
                {
                    var current = i;
                    for (var j = 0; j < increment; j++)
                    {
                        current = current.Successor;
                    }

                    return(current);
                };
                if (inclusive)
                {
                    compare = (i, o) => i.Compare(o) <= 0;
                }
                else
                {
                    compare = (i, o) => i.Compare(o) < 0;
                }
            }
            else
            {
                next = i =>
                {
                    var current = i;
                    for (var j = 0; j < -increment; j++)
                    {
                        current = current.Predecessor;
                    }

                    return(current);
                };
                if (inclusive)
                {
                    compare = (i, o) => i.Compare(o) >= 0;
                }
                else
                {
                    compare = (i, o) => i.Compare(o) > 0;
                }
            }
        }
Ejemplo n.º 5
0
 public RangeIterator(Range range) : base(range)
 {
     this.range = range;
     current    = range.Start;
     stop       = range.StopObj;
 }