Exemplo n.º 1
0
        public void PatternSearch4_LoopUntilMatch()
        {
            var src = @"{a: 'Budilnik', 'Name': 'Znatoki', q: 2, z: 148, 'hero': 0x7f}";

            var lxr = new JL(new StringSource(src));


            var capture = lxr.LazyFSM(
                (s, t) => s.LoopUntilMatch(
                    (ss, tk) => tk.LoopUntilAny(JSONTokenType.tStringLiteral),
                    (ss, tk) => tk.IsAnyOrAbort(JSONTokenType.tColon),
                    (ss, tk) => tk.IsAnyOrAbort(JSONTokenType.tStringLiteral),
                    (ss, tk) => FSMI.TakeAndComplete
                    ),
                (s, t) => s.Skip(3),
                (s, t) => t.LoopUntilAny(JSONTokenType.tStringLiteral),
                (s, t) => t.IsAnyOrAbort(JSONTokenType.tColon),
                (s, t) => FSMI.Take,
                (s, t) => t.IsAnyOrAbort(JSONTokenType.tBraceClose)
                );

            Aver.IsNotNull(capture);

            Aver.IsTrue(JSONTokenType.tIntLiteral == capture.Type);
            Aver.AreObjectsEqual(127, capture.Value);
        }
Exemplo n.º 2
0
        public void PatternSearch5_Skip()
        {
            var src = @"{a: 'Budilnik', 'Name': 'Znatoki', q:2, z: 148, 'hero': 0x7f}";

            var lxr = new JL(new StringSource(src));


            var capture = lxr.LazyFSM(
                (s, t) => s.Skip(1),
                (s, t) => FSMI.Take
                );

            Aver.IsNotNull(capture);
            Aver.IsTrue(JSONTokenType.tIdentifier == capture.Type);
            Aver.AreEqual("a", capture.Text);

            capture = lxr.LazyFSM(
                (s, t) => s.Skip(9),
                (s, t) => FSMI.Take
                );

            Aver.IsNotNull(capture);
            Aver.IsTrue(JSONTokenType.tIdentifier == capture.Type);
            Aver.AreEqual("q", capture.Text);
        }
Exemplo n.º 3
0
 public FSM(JSONLexer lex)
 {
     lexer  = lex;
     source = lexer.Source;
     tokens = lexer.m_Tokens;
     srcRef = lexer.SourceCodeReference;
 }
Exemplo n.º 4
0
        public void String_Escapes1()
        {
            var src = @"{""str\""ing""}";

            var lxr = new JL(new StringSource(src));

            Aver.AreEqual(@"str""ing", lxr.ElementAt(2).Text);
        }
Exemplo n.º 5
0
        public void String_Escapes6_ForwardSlash()
        {
            var src = @"{'male\/female'}";

            var lxr = new JL(new StringSource(src));

            Aver.AreEqual("male/female", lxr.ElementAt(2).Text);
        }
Exemplo n.º 6
0
        public void String_Escapes2_2()
        {
            var src = @"{a: -2, 'string\'': 2}";

            var lxr = new JL(new StringSource(src));

            Aver.AreEqual(@"string'", lxr.ElementAt(7).Text);
        }
Exemplo n.º 7
0
        public void eUnterminatedString2()
        {
            var src = @"a: ""aaaa";

            var lxr = new JL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemplo n.º 8
0
        public void ePrematureEOF_Thrown()
        {
            var src = @"";

            var lxr = new JL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemplo n.º 9
0
        public void String_Escapes5_Unicode()
        {
            var src = @"{""str\u8978ring""}";

            var lxr = new JL(new StringSource(src));

            Aver.AreEqual("str\u8978ring", lxr.ElementAt(2).Text);
        }
Exemplo n.º 10
0
        public void String_Escapes3()
        {
            var src = @"{'str\n\rring'}";

            var lxr = new JL(new StringSource(src));

            Aver.AreEqual("str\n\rring", lxr.ElementAt(2).Text);
        }
Exemplo n.º 11
0
        public void MinusInt()
        {
            var src = @"{-12}";

            var lxr = new JL(new StringSource(src));

            Aver.IsTrue(JSONTokenType.tMinus == lxr.ElementAt(2).Type);
            Aver.AreObjectsEqual(12, lxr.ElementAt(3).Value);
        }
Exemplo n.º 12
0
        public void eUnterminatedString4_Verbatim()
        {
            var src = @"a: $'aa
          
          aa";

            var lxr = new JL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemplo n.º 13
0
        public void String2()
        {
            var src = @"{""string""}";

            var lxr = new JL(new StringSource(src));

            var expected = new JSONTokenType[] { JSONTokenType.tBOF, JSONTokenType.tBraceOpen, JSONTokenType.tStringLiteral, JSONTokenType.tBraceClose, JSONTokenType.tEOF };

            Aver.IsTrue(lxr.Select(t => t.Type).SequenceEqual(expected));
        }
Exemplo n.º 14
0
        public void eUnterminatedComment1()
        {
            var src = @"a: /*aa
          
          aa";

            var lxr = new JL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemplo n.º 15
0
        public void BOF_EOF()
        {
            var src = @"a";

            var lxr = new JL(new StringSource(src));

            var expected = new JSONTokenType[] { JSONTokenType.tBOF, JSONTokenType.tIdentifier, JSONTokenType.tEOF };

            Aver.IsTrue(lxr.Select(t => t.Type).SequenceEqual(expected));
        }
Exemplo n.º 16
0
        public void Comments8()
        {
            var src = @"{
          /* //comment text " + "\r\n" + @" */
          }
          ";

            var lxr = new JL(new StringSource(src));

            Aver.AreEqual(" //comment text \r\n ", lxr.ElementAt(2).Text);
        }
Exemplo n.º 17
0
        public void Comments13withStrings()
        {
            var src = @"{       
          |*'aaaa /* //comment""text " + "\n\r" + @" */ *|
          }
          ";
            var lxr = new JL(new StringSource(src));

            Aver.IsTrue(JSONTokenType.tComment == lxr.ElementAt(2).Type);
            Aver.AreEqual("'aaaa /* //comment\"text \n\r */ ", lxr.ElementAt(2).Text);
        }
Exemplo n.º 18
0
        public void Comments10()
        {
            var src = @"{       
          |* /* //comment text " + "\n\r" + @" */ *|
          }
          ";

            var lxr = new JL(new StringSource(src));

            Aver.AreEqual(" /* //comment text \n\r */ ", lxr.ElementAt(2).Text);
        }
Exemplo n.º 19
0
        public void Comments4()
        {
            var src = @"{
           //comment text
          }
          ";

            var lxr = new JL(new StringSource(src));

            Aver.AreEqual("comment text", lxr.ElementAt(2).Text);
        }
Exemplo n.º 20
0
        public void JSONPatternMatchAttribute1()
        {
            var src = @"1,2,3,4,5,6,7,8,9 : 'Name': 'Znatoki' null 'ok'";

            var lxr = new JL(new StringSource(src));

            var match = JSONPatternMatchAttribute.Check(MethodBase.GetCurrentMethod(), lxr);


            Aver.IsFalse(match);
        }
Exemplo n.º 21
0
        public void JSONPatternMatchAttribute3()
        {
            var src = @"{ code: 1121982, color: red, 'first_name': 'Alex', DOB: null}";

            var lxr = new JL(new StringSource(src));

            var match = JSONPatternMatchAttribute.Check(MethodBase.GetCurrentMethod(), lxr);


            Aver.IsTrue(match);
        }
Exemplo n.º 22
0
 public override bool Match(Azos.CodeAnalysis.JSON.JSONLexer content)
 {
     return(content.LazyFSM(
                (s, t) => s.LoopUntilMatch(
                    (ss, tk) => tk.LoopUntilAny("First-Name", "FirstName", "first_name"),
                    (ss, tk) => tk.IsAnyOrAbort(JSONTokenType.tColon),
                    (ss, tk) => tk.IsAnyOrAbort(JSONTokenType.tStringLiteral),
                    (ss, tk) => FSMI.TakeAndComplete
                    ),
                (s, t) => FSMI.Take
                ) != null);
 }
Exemplo n.º 23
0
        public void Comments11withStrings()
        {
            var src = @"{       
          $'|* /* //comment text " + "\n\r" + @" */ *|'
          }
          ";

            var lxr = new JL(new StringSource(src));

            Aver.IsTrue(JSONTokenType.tStringLiteral == lxr.ElementAt(2).Type);
            Aver.AreEqual("|* /* //comment text \n\r */ *|", lxr.ElementAt(2).Text);
        }
Exemplo n.º 24
0
        public void ePrematureEOF_CouldLogButThrown()
        {
            var src = @"";

            var msgs = new MessageList();

            var lxr = new JL(new StringSource(src), msgs, throwErrors: true);

            lxr.AnalyzeAll();

            Aver.IsNotNull(msgs.FirstOrDefault(m => m.Type == MessageType.Error && m.Code == (int)JSONMsgCode.ePrematureEOF));
        }
Exemplo n.º 25
0
        public void Comments12withStrings()
        {
            //string is opened but line break
            var src = @"{       
          '|* /* //comment text " + "\n\r" + @" */ *|'
          }
          ";

            var lxr = new JL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemplo n.º 26
0
        public void Comments2()
        {
            var src = @"{
           /*'string'}*/
          }
          ";

            var lxr = new JL(new StringSource(src));

            var expected = new JSONTokenType[] { JSONTokenType.tBOF, JSONTokenType.tBraceOpen, JSONTokenType.tComment, JSONTokenType.tBraceClose, JSONTokenType.tEOF };

            Aver.IsTrue(lxr.Select(t => t.Type).SequenceEqual(expected));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Checks all pattern match attributes against specified member info until first match found
        /// </summary>
        public static bool Check(MemberInfo info, JSONLexer content)
        {
            var attrs = info.GetCustomAttributes(typeof(JSONPatternMatchAttribute), true).Cast <JSONPatternMatchAttribute>();

            foreach (var attr in attrs)
            {
                if (attr.Match(content))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 28
0
        public void PatternSearch()
        {
            var src = @"{a: 2, b: 'Znatoki', c: false, d: null, e: ['a','b','c']}";

            var lxr = new JL(new StringSource(src));


            var bvalue = lxr.LazyFSM(
                (s, t) => t.LoopUntilAny("b"),
                (s, t) => t.IsAnyOrAbort(JSONTokenType.tColon),
                (s, t) => FSMI.TakeAndComplete
                );

            Aver.AreEqual("Znatoki", bvalue.Text);
        }
Exemplo n.º 29
0
        public void BasicTokensWithIdentifierAndDoubleLiteral()
        {
            var src = @"{a: 2.2}";

            var lxr = new JL(new StringSource(src));

            var expected = new JSONTokenType[]
            {
                JSONTokenType.tBOF, JSONTokenType.tBraceOpen,
                JSONTokenType.tIdentifier, JSONTokenType.tColon, JSONTokenType.tDoubleLiteral,
                JSONTokenType.tBraceClose, JSONTokenType.tEOF
            };

            Aver.IsTrue(lxr.Select(t => t.Type).SequenceEqual(expected));
        }
Exemplo n.º 30
0
        public void PatternSearch3()
        {
            var src = @"{a: 2, b: 'Znatoki'}";

            var lxr = new JL(new StringSource(src));


            var bvalue = lxr.LazyFSM(
                (s, t) => t.LoopUntilAny("b"),
                (s, t) => t.IsAnyOrAbort(JSONTokenType.tColon),
                (s, t) => FSMI.Take,
                (s, t) => t.IsAnyOrAbort(JSONTokenType.tComma)
                );

            Aver.IsNull(bvalue);
        }