Exemplo n.º 1
0
        public void ShouldBuildStates3()
        {
            AutomatonTableFactory factory;

            State[] states;
            SituationSegmentFactory segmentFactory;
            ISituation rootSituation;


            segmentFactory = new SituationSegmentFactory();

            rootSituation = segmentFactory.BuildRootSituation(
                new Rule("A", Parse.Character('a').Then(Parse.Character('b').ThenCharacter('b').ThenCharacter('b').Perhaps()).ThenCharacter('c')),
                new Rule("B", Parse.Character('a').ThenCharacter('b').ThenCharacter('e'))
                );

            factory = new AutomatonTableFactory();
            states  = factory.BuildStates(rootSituation);

            Assert.AreEqual(7, states.Length);
            Assert.AreEqual("A", ParseStates(states, 'a', 'b', 'b', 'b', 'c'));
            Assert.AreEqual("A", ParseStates(states, 'a', 'c'));
            Assert.ThrowsException <InvalidOperationException>(() => ParseStates(states, 'a', 'b', 'b', 'b', 'e'));
            Assert.AreEqual("B", ParseStates(states, 'a', 'b', 'e'));
        }
Exemplo n.º 2
0
        public void ShouldNotBuildRootSituationAndThrowException()
        {
            ISituationSegmentFactory factory;


            factory = new SituationSegmentFactory();
            Assert.ThrowsException <ArgumentNullException>(() => factory.BuildRootSituation(null));
        }
Exemplo n.º 3
0
        public void ShouldBuildRootSituation()
        {
            IRule      rule;
            ISituation situation;
            ISituationSegmentFactory factory;

            rule = new Rule("A", Parse.Character('a'));

            factory   = new SituationSegmentFactory();
            situation = factory.BuildRootSituation(rule);
            Assert.IsNotNull(situation);
            Assert.IsTrue(ParseSegment(situation.Transitions, typeof(Character)));
        }
Exemplo n.º 4
0
        //private ICharReader reader;

        public Lexer(params IRule[] Rules)
        {
            if (Rules == null)
            {
                throw new ArgumentNullException("Rules");
            }


            IAutomatonTableFactory   automatonTableFactory;
            ISituationSegmentFactory situationSegmentFactory;
            ISituation rootSituation;

            situationSegmentFactory = new SituationSegmentFactory();
            rootSituation           = situationSegmentFactory.BuildRootSituation(Rules);

            automatonTableFactory = new AutomatonTableFactory();
            this.states           = automatonTableFactory.BuildStates(rootSituation);
        }
Exemplo n.º 5
0
        public void ShouldBuildStates()
        {
            AutomatonTableFactory factory;

            State[] states;
            SituationSegmentFactory segmentFactory;
            ISituation rootSituation;


            segmentFactory = new SituationSegmentFactory();

            rootSituation = segmentFactory.BuildRootSituation(
                new Rule("A", Parse.Character('a').ThenCharacter('b').ThenCharacter('c')),
                new Rule("B", Parse.Character('a').ThenCharacter('b').ThenAnyCharacter())
                );

            factory = new AutomatonTableFactory();
            states  = factory.BuildStates(rootSituation);

            Assert.AreEqual(5, states.Length);
            Assert.AreEqual("A", ParseStates(states, 'a', 'b', 'c'));
            Assert.AreEqual("B", ParseStates(states, 'a', 'b', 'd'));
        }