示例#1
0
        public void ReturnFalseWhenTest7IsIncorrect()
        {
            var value = new Choice(
                new StringClass(),
                new Number(),
                new Text("true"),
                new Text("false"),
                new Text("null")
                );

            var whitespaces = new Many(new Any(" \r\n\t"));
            var element     = new Sequence(whitespaces, value, whitespaces);
            var elements    = new List(element, new Character(','));

            var array = new Sequence(whitespaces,
                                     new Character('['),
                                     whitespaces,
                                     elements,
                                     whitespaces,
                                     new Character(']'),
                                     whitespaces
                                     );


            var newObject = new Sequence(whitespaces, new Character('['), elements, new Character(']'), whitespaces);
            //var match = members.Match(" \"id\" \"file\" " );
            //var match = myObject.Match(" { \" name\" \"John\" } " );
            //var match = myObject.Match(" { \"menu\" : { \"id\" \"file\" } }");
            var match = newObject.Match("        [\"S\\ufefhi]");
            //var match = myObject.Match(" { \" name\" \"John\" }");
            var error = (Error)match;

            Assert.Equal(16, error.Position());
        }
示例#2
0
        public StringClass()
        {
            var singleChar = new Choice(
                new Range((char)31, (char)33),
                new Range((char)35, (char)91),
                new Range((char)93, (char)ushort.MaxValue)
                );
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F')
                );
            var hexSeq = new Sequence(
                new Character('u'),
                hex, hex, hex, hex
                );
            var escapeChars = new Choice(new Any("\"\\/bnrt"), hexSeq);
            var escapeSeq   = new Sequence(new Character('\\'), escapeChars);
            var character   = new Choice(
                singleChar,
                escapeSeq
                );
            var characters = new Many(character);

            pattern = new Sequence(new Character('"'),
                                   characters,
                                   new Character('"'));
        }
示例#3
0
        public void ReturnFalseWhenTest2InCorrect()
        {
            var whitespaces = new Many(new Any(" \r\n\t"));
            var result      = whitespaces.Match(" \r\t");

            Assert.True(result.Success());
            Assert.Equal("", result.RemainingText());
        }
示例#4
0
        public void ReturnFalseWhenTest1InCorrect()
        {
            var sequence = new Many(
                new Sequence(
                    new Character('a'),
                    new Character('b'),
                    new Character('c')
                    )
                );

            var result = (SpecialError)sequence.Match("abcabcabx");

            //
            // RT = ABX
            Assert.Equal(8, result.Position());
            Assert.Equal("abx", result.RemainingText());
        }
示例#5
0
文件: Value.cs 项目: thisisalin/JSON
        public Value()
        {
            var value = new Choice(
                new StringClass(),
                new Number(),
                new Text("true"),
                new Text("false"),
                new Text("null")
                );

            var whitespaces = new Many(new Any(" \r\n\t"));
            var element     = new Sequence(whitespaces, value, whitespaces);
            var elements    = new List(element, new Character(','));

            var array = new Sequence(whitespaces,
                                     new Character('['),
                                     whitespaces,
                                     elements,
                                     whitespaces,
                                     new Character(']'),
                                     whitespaces
                                     );

            value.Add(array);

            var member = new Sequence(whitespaces,
                                      new StringClass(),
                                      whitespaces,
                                      new Character(':'), element);

            var members = new List(member, new Character(','));

            var myObject = new Sequence(whitespaces,
                                        new Character('{'),
                                        whitespaces,
                                        members,
                                        whitespaces,
                                        new Character('}'),
                                        whitespaces
                                        );

            value.Add(myObject);
            pattern = value;
        }
示例#6
0
文件: List.cs 项目: thisisalin/JSON
 public List(IPattern element, IPattern separator)
 {
     this.element   = element;
     this.separator = separator;
     many           = new Many(new Sequence(separator, element));
 }