Exemple #1
0
        public String()
        {
            // aici construiește patternul pentru
            // un JSON string
            var quote = new Character('"');

            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 escapeSeq = new Sequence(
                new Character('\\'),
                new Choice(
                    new Any("\"\\/bfnrt"),
                    hexSeq));

            var character = new Choice(
                new Range(Convert.ToChar(0x20), Convert.ToChar(0xFFFF), "\"\\"),
                escapeSeq,
                hexSeq);

            var characters = new Many(character);

            pattern = new Sequence(quote, characters, quote);
        }
Exemple #2
0
        public Value()
        {
            // aici construiește patternul pentru
            // un JSON value
            // ai grijă să ți seama de `spații albe`
            var stringValue = new String();
            var number      = new Number();

            var value = new Choice(
                stringValue,
                number,
                new Text("true"),
                new Text("false"),
                new Text("null"));

            var quote        = new Character('"');
            var openBracket  = new Character('[');
            var closeBracket = new Character(']');
            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 elements = new List(element, separator);

            var array = new Sequence(openBracket, whitespace, elements, closeBracket);

            value.Add(array);

            var openCurlyBracket  = new Character('{');
            var closeCurlyBracket = new Character('}');

            var member  = new Sequence(whitespace, stringValue, whitespace, new Character(':'), element);
            var members = new List(member, separator);

            var objectValue = new Sequence(openCurlyBracket, whitespace, members, closeCurlyBracket);

            value.Add(objectValue);

            pattern = element;
        }