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); }
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); }
public FSM(JSONLexer lex) { lexer = lex; source = lexer.Source; tokens = lexer.m_Tokens; srcRef = lexer.SourceCodeReference; }
public void String_Escapes1() { var src = @"{""str\""ing""}"; var lxr = new JL(new StringSource(src)); Aver.AreEqual(@"str""ing", lxr.ElementAt(2).Text); }
public void String_Escapes6_ForwardSlash() { var src = @"{'male\/female'}"; var lxr = new JL(new StringSource(src)); Aver.AreEqual("male/female", lxr.ElementAt(2).Text); }
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); }
public void eUnterminatedString2() { var src = @"a: ""aaaa"; var lxr = new JL(new StringSource(src)); lxr.AnalyzeAll(); }
public void ePrematureEOF_Thrown() { var src = @""; var lxr = new JL(new StringSource(src)); lxr.AnalyzeAll(); }
public void String_Escapes5_Unicode() { var src = @"{""str\u8978ring""}"; var lxr = new JL(new StringSource(src)); Aver.AreEqual("str\u8978ring", lxr.ElementAt(2).Text); }
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); }
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); }
public void eUnterminatedString4_Verbatim() { var src = @"a: $'aa aa"; var lxr = new JL(new StringSource(src)); lxr.AnalyzeAll(); }
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)); }
public void eUnterminatedComment1() { var src = @"a: /*aa aa"; var lxr = new JL(new StringSource(src)); lxr.AnalyzeAll(); }
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)); }
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); }
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); }
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); }
public void Comments4() { var src = @"{ //comment text } "; var lxr = new JL(new StringSource(src)); Aver.AreEqual("comment text", lxr.ElementAt(2).Text); }
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); }
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); }
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); }
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); }
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)); }
public void Comments12withStrings() { //string is opened but line break var src = @"{ '|* /* //comment text " + "\n\r" + @" */ *|' } "; var lxr = new JL(new StringSource(src)); lxr.AnalyzeAll(); }
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)); }
/// <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); }
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); }
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)); }
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); }