Esempio n. 1
0
            public (Token, string) Parse(string input)
            {
                var defKeyword = new Word("def").Parse(input);
                var sp1        = new SkipWhitespace().Parse(defKeyword.Item2);
                var recKeyword = new Word("rec").Parse(sp1.Item2);
                var sp2        = new SkipWhitespace().Parse(recKeyword.Item2);
                var name       = new Ident().Parse(sp2.Item2);
                var sp3        = new SkipWhitespace().Parse(name.Item2);
                var newLine    = new Many(new Char('\n')).Parse(sp3.Item2);
                var functions  = new Maybe(
                    new Many(
                        new Create(TokenType.FuncDef)
                {
                    new SkipWhitespace(), new MiniFuncDef(),
                    new SkipWhitespace(), new Many(new Char('\n'))
                }
                        )
                    ).Parse(newLine.Item2);
                var sp4        = new SkipWhitespace().Parse(functions.Item2);
                var endKeyword = new Word("end").Parse(sp4.Item2);

                var token = defKeyword.Item1 + recKeyword.Item1 + name.Item1;

                if (functions.Item1.type != TokenType.Failure)
                {
                    token += functions.Item1;
                }
                token     += endKeyword.Item1;
                token.type = TokenType.RecDef;

                return(token, endKeyword.Item2);
            }
Esempio n. 2
0
        public void MuplipleTextMatch()
        {
            var a = new Many(new Character('a'));

            Assert.True(a.Match("aaaabcd").Success());
            Assert.Equal("bcd", a.Match("aaaabcd").RemainingText());
        }
Esempio n. 3
0
        public void TextNullReturnTrue()
        {
            var a = new Many(new Character('a'));

            Assert.True(a.Match(null).Success());
            Assert.Null(a.Match(null).RemainingText());;
        }
Esempio n. 4
0
        public void StringAsParamReturnsCorectFormatForString()
        {
            var seqence = new Sequence(new Character('a'), new Character('b'));
            var digits  = new Many(seqence);

            Assert.Equal("ac", digits.Match("ababac").RemainingText());
        }
Esempio n. 5
0
        public Value()
        {
            var value = new Choice(
                new String(),
                new Number(),
                new Text("true"),
                new Text("false"),
                new Text("null")
                );

            var whitespace = new Many(new Any(" \r\n\t"));
            var separator  = new Sequence(whitespace, new Character(','), whitespace);
            var element    = new Sequence(whitespace, value, whitespace);

            var array = new Sequence(whitespace,
                                     new Character('['),
                                     new List(element, separator),
                                     new Character(']')
                                     );

            var objectSeparator = new Sequence(whitespace, new Character(':'), whitespace);
            var objectString    = new Sequence(whitespace, new String(), whitespace);
            var members         = new Sequence(objectString, objectSeparator, element);

            var jsonObject = new Sequence(whitespace,
                                          new Character('{'),
                                          new List(members, separator),
                                          new Character('}')
                                          );

            value.Add(array);
            value.Add(jsonObject);

            pattern = value;
        }
Esempio n. 6
0
        public void FirstCharacterMatchesManyCharPattern()
        {
            Many pattern = new Many(new Character('a'));

            Assert.True(pattern.Match("abc").Success());
            Assert.True(pattern.Match("abc").RemainingText() == "bc");
        }
Esempio n. 7
0
            public async Task <ResponseResult> Handle(CreateCommand request, CancellationToken cancellationToken)
            {
                _repository.IncludeInTrasation(_unitOfWork);

                var many = new Many(request.One, request.ManyProperty01);

                AddNotifications(many);
                _repository.Add(many);

                var toOneResponse = await _mediator.Send(new ToOneHandlers.CreateCommand
                {
                    Many       = many,
                    Property01 = request.ManyProperty01
                });

                var selfOneResponse = await _mediator.Send(new SelfOneHandlers.CreateCommand
                {
                    Many       = many,
                    Property01 = request.ManyProperty01
                });

                AddNotifications(selfOneResponse);
                AddNotifications(toOneResponse);

                return(new ResponseResult(many, this));
            }
Esempio n. 8
0
        public void For_IPattern_Char_a_And_String_bc_Should_Return_String_bc()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match("bc");

            Assert.Equal("bc", actual.RemainingText());
        }
Esempio n. 9
0
        public void For_IPattern_Char_a_And_String_EmptyString_Should_Return_True()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match(string.Empty);

            Assert.True(actual.Succes());
        }
Esempio n. 10
0
 public ResumeInfo(TimelinePosition checkpoint, Many <FlowKey> routes, Many <TimelinePoint> schedule, IConnectable subscription)
 {
     Checkpoint   = checkpoint;
     Routes       = routes;
     Schedule     = schedule;
     Subscription = subscription;
 }
Esempio n. 11
0
 public ResumeInfo(IConnectable subscription)
 {
     Checkpoint   = TimelinePosition.None;
     Routes       = new Many <FlowKey>();
     Schedule     = new Many <TimelinePoint>();
     Subscription = subscription;
 }
Esempio n. 12
0
        public void ReturnsTrueAndTextForNoMatchesRange()
        {
            var digits = new Many(new Range('0', '9'));

            Assert.True(digits.Match("ab").Success());
            Assert.Equal("ab", digits.Match("ab").RemainingText());
        }
Esempio n. 13
0
        public void ReturnsTrueAndRemainingForMatches()
        {
            var digits = new Many(new Range('0', '9'));

            Assert.True(digits.Match("12345ab123").Success());
            Assert.Equal("ab123", digits.Match("12345ab123").RemainingText());
        }
Esempio n. 14
0
        public void Should_Return__Correct_String_Hexadecimal_Sequence()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F')
                );

            var hexSeq = new Sequence(
                new Character('u'),
                new Sequence(
                    hex,
                    hex,
                    hex,
                    hex
                    )
                );
            var pattern = new Many(
                new Sequence(hexSeq)
                );

            var match = pattern.Match("u1234u1234u12Zabc");

            Assert.Equal("u12Zabc", match.RemainingText());
            Assert.True(match.Success());
        }
Esempio n. 15
0
        public void FirstCharMatchesManyDigitsPattern()
        {
            Many pattern = new Many(new Range('0', '9'));

            Assert.True(pattern.Match("ab").Success());
            Assert.True(pattern.Match("ab").RemainingText() == "ab");
        }
Esempio n. 16
0
        public void For_IPattern_Char_a_And_String_EmptyString_Should_Return_String_EmptyString()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match(string.Empty);

            Assert.Equal(string.Empty, actual.RemainingText());
        }
Esempio n. 17
0
        public void NullMatchesManyDigitRange()
        {
            Many pattern = new Many(new Range('0', '9'));

            Assert.True(pattern.Match(null).Success());
            Assert.True(pattern.Match(null).RemainingText() == null);
        }
Esempio n. 18
0
        public void For_IPattern_Range_0_9_And_String_12345ab123_Should_Return_True()
        {
            var    digits = new Many(new Range('0', '9'));
            IMatch actual = digits.Match("12345ab123");

            Assert.True(actual.Succes());
        }
Esempio n. 19
0
        public void TextMatchesManyTextPattern()
        {
            Many pattern = new Many(new Text("abc"));

            Assert.True(pattern.Match("abcabcd").Success());
            Assert.True(pattern.Match("abcabcd").RemainingText() == "d");
        }
Esempio n. 20
0
        public void For_IPattern_Range_0_9_And_String_12345ab123_Should_Return_ab123()
        {
            var    digits = new Many(new Range('0', '9'));
            IMatch actual = digits.Match("12345ab123");

            Assert.Equal("ab123", actual.RemainingText());
        }
Esempio n. 21
0
        public void StringAsParamReturnsTrueForString()
        {
            var seqence = new Sequence(new Character('a'), new Character('b'));
            var digits  = new Many(seqence);

            Assert.True(digits.Match("ababc").Success());
        }
Esempio n. 22
0
        public void Test_Many_Equality()
        {
            Many <int> empty = new Many <int>();
            Many <int> zero  = new Many <int>(0);
            Many <int> one   = new Many <int>(1);

            Many <int> empty2 = new Many <int>();
            Many <int> zero2  = new Many <int>(0);
            Many <int> one2   = new Many <int>(1);

            empty.Equals(empty2).ShouldBeTrue();
            empty.Equals(zero).ShouldBeFalse();
            empty.Equals(0).ShouldBeFalse();
            empty.Equals(one).ShouldBeFalse();
            empty.Equals(1).ShouldBeFalse();

            zero.Equals(empty).ShouldBeFalse();
            zero.Equals(zero2).ShouldBeTrue();
            zero.Equals(0).ShouldBeTrue();
            zero.Equals(one).ShouldBeFalse();
            zero.Equals(1).ShouldBeFalse();

            one.Equals(empty).ShouldBeFalse();
            one.Equals(zero).ShouldBeFalse();
            one.Equals(0).ShouldBeFalse();
            one.Equals(one2).ShouldBeTrue();
            one.Equals(1).ShouldBeTrue();
        }
Esempio n. 23
0
        public TimelinePoint(
            TimelinePosition position,
            TimelinePosition cause,
            EventType type,
            DateTimeOffset when,
            DateTimeOffset?whenOccurs,
            Id eventId,
            Id commandId,
            Id userId,
            FlowKey topic,
            Many <FlowKey> routes,
            Func <Event> readEvent)
        {
            Position   = position;
            Cause      = cause;
            Type       = type;
            When       = when;
            WhenOccurs = whenOccurs;
            EventId    = eventId;
            CommandId  = commandId;
            UserId     = userId;
            Topic      = topic;
            Routes     = routes;

            _event = new Lazy <Event>(readEvent);
        }
Esempio n. 24
0
        public void EmptyMatchesManyCharacterPattern()
        {
            Many pattern = new Many(new Character('a'));

            Assert.True(pattern.Match("").Success());
            Assert.True(pattern.Match("").RemainingText()?.Length == 0);
        }
Esempio n. 25
0
        protected override void OnSetUp()
        {
            base.OnSetUp();

            // create the objects to search on
            one        = new One();
            one.X      = 20;
            one.Manies = new HashedSet <Many>();

            Many many1 = new Many();

            many1.X   = 10;
            many1.One = one;
            one.Manies.Add(many1);

            Many many2 = new Many();

            many2.X   = 20;
            many2.One = one;
            one.Manies.Add(many2);

            using (ISession s = OpenSession())
                using (ITransaction t = s.BeginTransaction())
                {
                    s.Save(one);
                    s.Save(many1);
                    s.Save(many2);
                    t.Commit();
                }
        }
Esempio n. 26
0
        public void NullMatchesManyCharPattern()
        {
            Many pattern = new Many(new Character('a'));

            Assert.True(pattern.Match(null).Success());
            Assert.True(pattern.Match(null).RemainingText() == null);
        }
Esempio n. 27
0
        public void TextEmptyReturnTrue()
        {
            var a = new Many(new Character('a'));

            Assert.True(a.Match("").Success());
            Assert.Equal("", a.Match("").RemainingText());
        }
Esempio n. 28
0
        public void FirstNumberMatchManyDigitsPattern()
        {
            Many pattern = new Many(new Range('0', '9'));

            Assert.True(pattern.Match("12345ab123").Success());
            Assert.True(pattern.Match("12345ab123").RemainingText() == "ab123");
        }
Esempio n. 29
0
        public void IsInRange()
        {
            var digits = new Many(new Json.Range('0', '9'));

            Assert.True(digits.Match("12345ab123").Success());
            Assert.Equal("ab123", digits.Match("12345ab123").RemainingText());
        }
Esempio n. 30
0
        public void Then()
        {
            var startsWithA      = new StartsWithChar('A');
            var startsWithB      = new StartsWithChar('B');
            var startsWithAthenB = startsWithA + startsWithB;

            Do_Parser_Test(startsWithAthenB, "ABA", true, StringToList("AB"), "A");
            Do_Parser_Test(startsWithAthenB, "AC", false, null, "AC");
            Do_Parser_Test(startsWithAthenB, "BA", false, null, "BA");

            var ab = new List <object> {
                'A', 'B'
            };

            Do_Parser_Test(new Many(startsWithAthenB), "ABABABC", true, new List <List <object> >()
            {
                ab, ab, ab
            }, "C");

            var isDigit   = new StartsWithAnyChar("0123456789".ToCharArray());
            var isInteger = new Many(isDigit);
            var isPeriod  = new StartsWithChar('.');
            var isDecimal = (isInteger + isPeriod + isInteger) | isInteger;

            Do_Parser_Test(isDecimal, "1234.56", true, StringToList("1234.56"), "");
            Do_Parser_Test(isDecimal, "1234", true, StringToList("1234"), "");
            Do_Parser_Test(isDecimal, ".1234.", true, StringToList(".1234"), ".");
        }