Beispiel #1
0
        void Sequence_OnComplete(ExpressionEventArgs sender)
        {
            TestToken token    = sender.token as TestToken;
            Sequence  sequence = sender.term as Sequence;

            Object.Equals(token.Id, "seq2");
        }
Beispiel #2
0
        public void ParallelOperator1()
        {
            var term1 = new TestTerm()
            {
                Id = "par"
            };
            var term2 = new TestTerm()
            {
                Id = "par"
            };
            var parallel = new Parallel(new List <Term>(new Term[] { term1, term2 }));

            term1.OnComplete += Term1_OnComplete;
            term2.OnComplete += Term2_OnComplete;


            TestToken token = new TestToken()
            {
                Id = "par"
            };

            parallel.Fire(token);

            Assert.True(parallel.State == ExpressionState.Complete);
        }
Beispiel #3
0
        void Iterative_OnComplete(ExpressionEventArgs sender)
        {
            TestToken token     = sender.token as TestToken;
            Iterative iterative = sender.term as Iterative;

            Object.Equals(token.Id, "dummy");
        }
Beispiel #4
0
        public void SequenceOperator()
        {
            var term1 = new TestTerm
            {
                Id = "seq1"
            };
            var term2 = new TestTerm
            {
                Id = "seq2"
            };

            var sequence = new Sequence(new List <Term>(new Term[] { term1, term2 }));

            sequence.OnComplete += Sequence_OnComplete;
            var token1 = new TestToken
            {
                Id = "seq1"
            };
            var token2 = new TestToken
            {
                Id = "seq2"
            };

            Assert.False(sequence.LookAhead(token2));

            sequence.Fire(token1);

            Assert.True(sequence.State == ExpressionState.Default);
            Assert.True(sequence.LookAhead(token2));

            sequence.Fire(token2);
            Assert.True(sequence.State == ExpressionState.Complete);
        }
Beispiel #5
0
        void Term1_OnComplete1(ExpressionEventArgs sender)
        {
            TestToken token = sender.token as TestToken;
            TestTerm  term  = sender.term as TestTerm;

            Object.Equals(token.Id, "B");
        }
Beispiel #6
0
        public void ParallelOperator2()
        {
            var term1 = new TestTerm()
            {
                Id = "A"
            };
            var term2 = new TestTerm()
            {
                Id = "B"
            };

            var iterative1 = new Iterative(term1);
            var iterative2 = new Iterative(term2);
            var parallel   = new Parallel(new List <Term>(new Term[] { iterative1, iterative2 }));

            var tokenA = new TestToken()
            {
                Id = "A"
            };
            var tokenB = new TestToken()
            {
                Id = "B"
            };

            term1.OnComplete += Term1_OnComplete1;
            term2.OnComplete += Term2_OnComplete1;

            parallel.Fire(tokenA);
            parallel.Fire(tokenA);
            parallel.Fire(tokenB);

            Assert.True(parallel.State == ExpressionState.Complete);
        }
Beispiel #7
0
        public void ChoiceOperator()
        {
            var term1 = new TestTerm()
            {
                Id = "A"
            };

            var term2 = new TestTerm()
            {
                Id = "A"
            };

            var term3 = new TestTerm()
            {
                Id = "B"
            };

            var term4 = new TestTerm()
            {
                Id = "B"
            };

            var sequence = new Sequence(new List <Term>(new Term[] { term1, term2 }));
            var parallel = new Parallel(new List <Term>(new Term[] { term3, term4 }));

            var choice = new Choice(new List <Term>(new Term[] { sequence, parallel }));

            var tokenA = new TestToken()
            {
                Id = "A"
            };
            var tokenB = new TestToken()
            {
                Id = "B"
            };

            choice.Fire(tokenA);
            choice.Fire(tokenA);
            Assert.True(sequence.State == ExpressionState.Complete);
            Assert.True(choice.State == ExpressionState.Complete);

            choice.Reset();

            choice.Fire(tokenB);
            Assert.True(parallel.State == ExpressionState.Complete);
            Assert.True(choice.State == ExpressionState.Complete);
        }
Beispiel #8
0
        public void IterativeOperator()
        {
            var term1 = new TestTerm
            {
                Id = "dummy"
            };
            var iterative = new Iterative(term1);
            var token1    = new TestToken
            {
                Id = "dummy"
            };

            iterative.OnComplete += Iterative_OnComplete;

            iterative.Fire(token1);
            Assert.True(iterative.State == ExpressionState.Complete);

            // execute the term more than once
            iterative.Fire(token1);
            Assert.True(iterative.State == ExpressionState.Complete);
        }
Beispiel #9
0
        public void DisablingOperator()
        {
            var term1 = new TestTerm()
            {
                Id = "A"
            };

            var iterative1 = new Iterative(term1);

            var term2 = new TestTerm()
            {
                Id = "B"
            };

            var iterative2 = new Iterative(term2);

            var term3 = new TestTerm()
            {
                Id = "C"
            };

            var disabling = new Disabling(new List <Term>(new Term[] { iterative1, iterative2, term3 }));

            var tokenA = new TestToken()
            {
                Id = "A"
            };

            var tokenB = new TestToken()
            {
                Id = "B"
            };

            var tokenC = new TestToken()
            {
                Id = "C"
            };

            // una sequenza di token A
            disabling.Fire(tokenA);
            disabling.Fire(tokenA);

            // invio un token C e completo l'espressione
            disabling.Fire(tokenC);
            Assert.True(disabling.State == ExpressionState.Complete);

            disabling.Reset();

            // dopo un token B, l'espressione non accetta più A
            disabling.Fire(tokenA);
            disabling.Fire(tokenB);
            disabling.Fire(tokenA);

            Assert.True(disabling.State == ExpressionState.Error);

            disabling.Reset();

            //una sequenza di token A
            disabling.Fire(tokenA);
            disabling.Fire(tokenA);
            disabling.Fire(tokenA);
            disabling.Fire(tokenA);

            // stop della prima iterazione con uno o più token B
            disabling.Fire(tokenB);
            disabling.Fire(tokenB);
            Assert.True(iterative2.State == ExpressionState.Complete);

            // stop della seconda iterazione con un token C
            // invio un token C e completo l'espressione
            disabling.Fire(tokenC);
            Assert.True(disabling.State == ExpressionState.Complete);
        }