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 ePrematureEOF_Thrown() { var src = @""; var lxr = new JL(new StringSource(src)); lxr.AnalyzeAll(); }
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 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 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_Escapes6_ForwardSlash() { var src = @"{'male\/female'}"; var lxr = new JL(new StringSource(src)); Aver.AreEqual("male/female", lxr.ElementAt(2).Text); }
public void eUnterminatedString2() { var src = @"a: ""aaaa"; var lxr = new JL(new StringSource(src)); lxr.AnalyzeAll(); }
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 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 eUnterminatedString4_Verbatim() { var src = @"a: $'aa aa"; var lxr = new JL(new StringSource(src)); lxr.AnalyzeAll(); }
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 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 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 Comments4() { var src = @"{ //comment text } "; var lxr = new JL(new StringSource(src)); Aver.AreEqual("comment text", 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 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 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 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 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 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 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 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 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); }