Ejemplo n.º 1
0
                public static FTL.AST.Member Parse(CharStream cs)
                {
                    WhiteSpace.Parse(cs);

                    bool isDefault = false;

                    if (cs.PeekNext() == '*')
                    {
                        cs.SkipNext();
                        isDefault = true;
                    }

                    // Parse the MemberKey
                    cs.SkipCharacter('[');
                    FTL.AST.INode key = Memberkey.Parse(cs);
                    cs.SkipCharacter(']');

                    // skip optional space
                    WhiteSpace.Parse(cs);

                    // Parse the actual pattern
                    FTL.AST.Pattern pattern = Pattern.Parse(cs);

                    // and return it all
                    return(new FTL.AST.Member(key, pattern, isDefault));
                }
Ejemplo n.º 2
0
        private void checkValidMemberkey <T>(string input, string rest = "")
        {
            var cs        = NCS(input);
            var memberKey = Memberkey.Parse(cs);

            Assert.IsNotNull(memberKey);
            Assert.AreEqual(rest, cs.ReadUntilEnd());
            Assert.AreEqual(typeof(T), memberKey.GetType());
        }
Ejemplo n.º 3
0
        public void MemberKeyTests()
        {
            // the three possible MemberKeys
            checkValidMemberkey <L20n.FTL.AST.StringPrimitive>("keyword");
            checkValidMemberkey <L20n.FTL.AST.Attribute>("identifier/keyword");
            checkValidMemberkey <L20n.FTL.AST.Number>("42");

            // some invalid examples
            Throws(() => Memberkey.Parse(NCS("@#")));

            // for more examples check the individual types (keyword, identifier and number)
        }
Ejemplo n.º 4
0
        public void AttributeTests()
        {
            // good examples
            Assert.IsNotNull(Memberkey.Parse(NCS("bar")));
            Assert.IsNotNull(Memberkey.Parse(NCS("foo/bar")));
            Assert.IsNotNull(Memberkey.Parse(NCS("42")));
            Assert.IsNotNull(Memberkey.Parse(NCS("42.0")));

            // bad examples
            Throws(() => Memberkey.Parse(NCS("foo/42")));

            // check identifier-, keyword- and number- tests for more info
        }