示例#1
0
        public override Value Evaluate()
        {
            if (isTrue())
            {
                var verbResult = verb.Evaluate();
                result   = statement.Map(s => s.Result).DefaultTo(() => "");
                typeName = statement.Map(s => s.TypeName).DefaultTo(() => "");
                Index    = statement.Map(s => s.Index).DefaultTo(() => 0);
                return(verbResult);
            }

            return(null);
        }
示例#2
0
        public override Value AlternateValue(string message)
        {
            if (stop == -1)
            {
                return(new Array());
            }

            var length = arrayLength.Map(l => l, () => (int)Ceiling((decimal)((stop - start) / increment)));
            var array  = length <= MAX_LOOP?Array.SliceRange(start, stop, length, Inside, increment) :
                             new IntLazyArray(start, stop, increment);

            return(array);
        }
示例#3
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = mutable.GetHashCode();
         hashCode = hashCode * 397 ^ (name?.GetHashCode() ?? 0);
         hashCode = hashCode * 397 ^ (label?.GetHashCode() ?? 0);
         hashCode = hashCode * 397 ^ (_defaultValue?.GetHashCode() ?? 0);
         hashCode = hashCode * 397 ^ _typeConstraint.Map(tc => tc.Hash).DefaultTo(() => 0);
         hashCode = hashCode * 397 ^ reference.GetHashCode();
         hashCode = hashCode * 397 ^ capturing.GetHashCode();
         return(hashCode);
     }
 }
示例#4
0
        public Value Next(int index)
        {
            if (_generator.IsNone)
            {
                _generator = value.Evaluate().IfCast <IGenerator>();
            }

            return(_generator.Map(generator => generator.Next(index)).DefaultTo(() => NilValue));
        }
示例#5
0
        public override Value Evaluate()
        {
            var value = expression.Map(e => e.Evaluate().AssignmentValue()).DefaultTo(() => new Nil());

            typeName           = value.Type.ToString();
            State.ReturnValue  = value;
            State.ReturnSignal = true;
            return(value);
        }
示例#6
0
文件: Finder.cs 项目: toddcoder/FGrep
        public Finder(string pattern, bool not, IMaybe <string> _unless, string include, string includeExt, string exclude, string excludeExt)
        {
            if (not)
            {
                matches = line => !line.IsMatch(pattern);
            }
            else
            {
                matches = line => line.IsMatch(pattern);
            }

            if (not)
            {
                getMatcher = _ => notMatched <Result>();
            }
            else
            {
                getMatcher = line => ((Matcher)pattern).Matches(line);
            }

            unless = _unless.Map(unless => (Func <string, bool>)(line => !line.IsMatch(unless))).DefaultTo(() => _ => false);

            if (include.IsNotEmpty())
            {
                includeFile = file => file.NameExtension.IsMatch(include);
            }
            else if (includeExt.IsNotEmpty())
            {
                includeFile = file => file.Extension.EndsWith(includeExt);
            }
            else
            {
                includeFile = _ => true;
            }

            if (exclude.IsNotEmpty())
            {
                excludeFile = file => !file.NameExtension.IsMatch(include);
            }
            else if (excludeExt.IsNotEmpty())
            {
                excludeFile = file => !file.Extension.EndsWith(excludeExt);
            }
            else
            {
                excludeFile = _ => false;
            }
        }
示例#7
0
 public override string ToString()
 {
     return($"?{selector}({arguments.Select(a => a.ToString()).ToString(", ")})" + lambda.Map(l => $" {l}").DefaultTo(() => ""));
 }
示例#8
0
 public override Value Clone()
 {
     return(new NSInnerComprehension((Parameters)parameters.Clone(), (Block)generatorSource.Clone(), ifBlock.Map(b => ((Block)b.Clone()).Some()))
     {
         NextComprehension = NextComprehension.Map(c => ((NSInnerComprehension)c.Clone()).Some())
     });
 }
示例#9
0
 public IMaybe <string> ReadLine() => textBoxInterface.Map(tbi => tbi.Reader.ReadLine().SomeIfNotNull());
示例#10
0
        public void Map_Theory(IMaybe <int> m1, Func <int, string> mapFn, object expectation)
        {
            var result = m1.Map(mapFn);

            Assert.Equal(expectation, result);
        }
示例#11
0
 public ObjectRegionPopper(IMaybe <ObjectRegion> objectRegion, string name)
     : base(null, name)
 {
     exists = objectRegion.IsSome;
     region = objectRegion.Map(r => r).DefaultTo(() => null);
 }
示例#12
0
 public static IObject AsOptional <T>(this IMaybe <T> maybe) where T : IObject
 {
     return(maybe.Map(o => Some.Object(o)).DefaultTo(() => None.NoneValue));
 }
示例#13
0
 public override string ToString() => $"maybe {fieldName} = {expression} ({ifTrue}){_ifFalse.Map(f => $" ({f})").DefaultTo(() => "")}";
示例#14
0
 public override string ToString()
 {
     return(stream() / fieldName / " " / _operation.Map(o => o.ToString()).DefaultTo(() => "") / "= " / expression);
 }
示例#15
0
        public override Value Clone()
        {
            var yielding = _yielding.Map(y => (Block)y.Clone());

            return(new LoopRange(variable, (Block)init.Clone(), positive, (Block)condition.Clone(), (Block)increment.Clone(), yielding, region.Clone()));
        }
示例#16
0
 public override string ToString()
 {
     return($"assert{_error.Map(_ => "!").DefaultTo(() => "?")} {condition} : {value}{_error.Map(e => $" : {e}").DefaultTo(() => "")}");
 }
示例#17
0
 public override string ToString()
 {
     return((StringStream)"" / (reference, "ref ") / (mutable, "var ") / label.Map(l => $"{l}: ") / name
            / _typeConstraint.Map(t => t.Image).DefaultTo(() => "") / _defaultValue.Map(i => $" = {i.Image}").DefaultTo(() => ""));
 }