示例#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);
        }
示例#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);
        }
示例#3
0
 public FSM(JSONLexer lex)
 {
     lexer  = lex;
     source = lexer.Source;
     tokens = lexer.m_Tokens;
     srcRef = lexer.SourceCodeReference;
 }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#7
0
        public void eUnterminatedString2()
        {
            var src = @"a: ""aaaa";

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

            lxr.AnalyzeAll();
        }
示例#8
0
        public void ePrematureEOF_Thrown()
        {
            var src = @"";

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

            lxr.AnalyzeAll();
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#12
0
        public void eUnterminatedString4_Verbatim()
        {
            var src = @"a: $'aa
          
          aa";

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

            lxr.AnalyzeAll();
        }
示例#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));
        }
示例#14
0
        public void eUnterminatedComment1()
        {
            var src = @"a: /*aa
          
          aa";

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

            lxr.AnalyzeAll();
        }
示例#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));
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#19
0
        public void Comments4()
        {
            var src = @"{
           //comment text
          }
          ";

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

            Aver.AreEqual("comment text", lxr.ElementAt(2).Text);
        }
示例#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);
        }
示例#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);
        }
示例#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);
 }
示例#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);
        }
示例#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));
        }
示例#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();
        }
示例#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));
        }
示例#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);
        }
示例#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);
        }
示例#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));
        }
示例#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);
        }