protected override List<CodeLexem> Parse(SourcePart text) { var list = new List<CodeLexem>(); while (text.Length > 0) { var lenght = text.Length; TryExtract(list, ref text, ByteOrderMark); TryExtract(list, ref text, "[", LexemType.Symbol); TryExtract(list, ref text, "{", LexemType.Symbol); if (TryExtract(list, ref text, "\"", LexemType.Quotes)) { ParseJsonPropertyName(list, ref text); // Extract Name TryExtract(list, ref text, "\"", LexemType.Quotes); TryExtract(list, ref text, ":", LexemType.Symbol); TrySpace(list, ref text); TryExtractValue(list, ref text); // Extract Value } ParseSymbol(list, ref text); // Parse extras TrySpace(list, ref text); TryExtract(list, ref text, "\r\n", LexemType.LineBreak); TryExtract(list, ref text, "\n", LexemType.LineBreak); TryExtract(list, ref text, "}", LexemType.Symbol); TryExtract(list, ref text, "]", LexemType.Symbol); if (lenght == text.Length) break; } return list; }
protected virtual List<CodeLexem> Parse(SourcePart text) { var list = new List<CodeLexem>(); var sourceString = text; LineBreaks(list, ref sourceString, sourceString.Length, LexemType.PlainText); return list; }
private void ParseJsonPropertyName(ICollection<CodeLexem> res, ref SourcePart text) { var index = text.IndexOf("\":"); if (index <= 0) return; res.Add(new CodeLexem(LexemType.Property, CutString(ref text, index))); }
protected virtual List <CodeLexem> Parse(SourcePart text) { var list = new List <CodeLexem>(); var sourceString = text; LineBreaks(list, ref sourceString, sourceString.Length, LexemType.PlainText); return(list); }
private void ParseSymbol(ICollection<CodeLexem> res, ref SourcePart text) { int index = text.IndexOfAny(XmlSymbol); if (index != 0) return; res.Add(new CodeLexem(LexemType.Symbol, text.Substring(0, 1))); text = text.Substring(1); }
protected string CutString(ref SourcePart text, int count) { if (count == 0) return string.Empty; previousSimbol = text[count - 1]; var result = text.Substring(0, count); text = text.Substring(count); return result; }
protected bool TryExtract(List<CodeLexem> res, ref SourcePart text, string lex, LexemType type) { if (text.StartsWith(lex)) { res.Add(new CodeLexem(type, CutString(ref text, lex.Length))); return true; } return false; }
protected void ParseValue(List<CodeLexem> res, ref SourcePart text) { const string lex = "\""; var index = text.IndexOf(lex); if (index < 0) return; LineBreaks(res, ref text, index + lex.Length - 1, LexemType.Value); }
protected bool TryExtract(List <CodeLexem> res, ref SourcePart text, string lex, LexemType type) { if (text.StartsWith(lex)) { res.Add(new CodeLexem(type, CutString(ref text, lex.Length))); return(true); } return(false); }
protected bool TryExtract(List <CodeLexem> res, ref SourcePart text, string lex) { if (text.StartsWith(lex)) { CutString(ref text, lex.Length); return(true); } return(false); }
protected bool TryExtract(List<CodeLexem> res, ref SourcePart text, string lex) { if (text.StartsWith(lex)) { CutString(ref text, lex.Length); return true; } return false; }
private void ParseJsonPropertyName(ICollection <CodeLexem> res, ref SourcePart text) { var index = text.IndexOf("\":"); if (index <= 0) { return; } res.Add(new CodeLexem(LexemType.Property, CutString(ref text, index))); }
private void ParseSymbol(ICollection <CodeLexem> res, ref SourcePart text) { int index = text.IndexOfAny(XmlSymbol); if (index != 0) { return; } res.Add(new CodeLexem(LexemType.Symbol, text.Substring(0, 1))); text = text.Substring(1); }
protected void ParseValue(List <CodeLexem> res, ref SourcePart text) { const string lex = "\""; var index = text.IndexOf(lex); if (index < 0) { return; } LineBreaks(res, ref text, index + lex.Length - 1, LexemType.Value); }
protected string CutString(ref SourcePart text, int count) { if (count == 0) { return(string.Empty); } previousSimbol = text[count - 1]; var result = text.Substring(0, count); text = text.Substring(count); return(result); }
protected void TrySpace(List<CodeLexem> res, ref SourcePart text) { var stringBuilder = new StringBuilder(); while (SpaceChars.Contains(text[0])) { stringBuilder.Append(CutString(ref text, 1)); } if (stringBuilder.Length > 0) { res.Add(new CodeLexem(LexemType.Space, stringBuilder.ToString())); } }
protected void TrySpace(List <CodeLexem> res, ref SourcePart text) { var stringBuilder = new StringBuilder(); while (SpaceChars.Contains(text[0])) { stringBuilder.Append(CutString(ref text, 1)); } if (stringBuilder.Length > 0) { res.Add(new CodeLexem(LexemType.Space, stringBuilder.ToString())); } }
protected override List <CodeLexem> Parse(SourcePart text) { var list = new List <CodeLexem>(); while (text.Length > 0) { if (TryExtract(list, ref text, "<!--", LexemType.Comment)) { TryExtractTo(list, ref text, "-->", LexemType.Comment); } if (text.StartsWith("<", StringComparison.Ordinal)) { IsInsideBlock = false; } if (TryExtract(list, ref text, "\"{}", LexemType.Value)) { TryExtractTo(list, ref text, "\"", LexemType.Value); } if (TryExtract(list, ref text, "</", LexemType.Symbol) || TryExtract(list, ref text, "<", LexemType.Symbol) || TryExtract(list, ref text, "{", LexemType.Symbol)) { ParseXmlKeyWord(list, ref text, LexemType.Object); } if (TryExtract(list, ref text, "\"", LexemType.Quotes)) { ParseValue(list, ref text); } ParseXmlKeyWord(list, ref text, IsInsideBlock ? LexemType.PlainText : LexemType.Property); TryExtract(list, ref text, "\"", LexemType.Quotes); TryExtract(list, ref text, "}", LexemType.Symbol); if (text.StartsWith(">", StringComparison.Ordinal)) { IsInsideBlock = true; } ParseSymbol(list, ref text); TrySpace(list, ref text); TryExtract(list, ref text, "\n", LexemType.LineBreak); } return(list); }
protected void TryExtractTo(List<CodeLexem> res, ref SourcePart text, string lex, LexemType type, string except = null) { var index = text.IndexOf(lex); if (except != null) { while (index >= 0 && text.Substring(0, index + 1).EndsWith(except)) { index = text.IndexOf(lex, index + 1); } } if (index < 0) return; LineBreaks(res, ref text, index + lex.Length, type); }
private void ParseXmlKeyWord(ICollection<CodeLexem> res, ref SourcePart text, LexemType type) { var index = text.IndexOfAny(XmlEndOfTerm); if (index <= 0) return; var delimiterIndex = text.IndexOf(XmlNamespaceDelimeter); if (delimiterIndex > 0 && delimiterIndex < index) { res.Add(new CodeLexem(type, CutString(ref text, delimiterIndex))); res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); res.Add(new CodeLexem(type, CutString(ref text, index - delimiterIndex - 1))); return; } res.Add(new CodeLexem(type, CutString(ref text, index))); }
protected void TryExtractTo(List <CodeLexem> res, ref SourcePart text, string lex, LexemType type, string except = null) { var index = text.IndexOf(lex); if (except != null) { while (index >= 0 && text.Substring(0, index + 1).EndsWith(except)) { index = text.IndexOf(lex, index + 1); } } if (index < 0) { return; } LineBreaks(res, ref text, index + lex.Length, type); }
protected void LineBreaks(List <CodeLexem> res, ref SourcePart text, int to, LexemType type) { while (text.Length > 0 && to > 0) { var index = text.IndexOf("\n"); if (index >= to) { res.Add(new CodeLexem(type, CutString(ref text, to))); return; } if (index != 0) { res.Add(new CodeLexem(type, CutString(ref text, index))); } res.Add(new CodeLexem(LexemType.LineBreak, CutString(ref text, 1))); to -= index + 1; } }
protected void LineBreaks(List<CodeLexem> res, ref SourcePart text, int to, LexemType type) { while (text.Length > 0 && to > 0) { var index = text.IndexOf("\n"); if (index >= to) { res.Add(new CodeLexem(type, CutString(ref text, to))); return; } if (index != 0) { res.Add(new CodeLexem(type, CutString(ref text, index))); } res.Add(new CodeLexem(LexemType.LineBreak, CutString(ref text, 1))); to -= index + 1; } }
private void ParseXmlKeyWord(ICollection <CodeLexem> res, ref SourcePart text, LexemType type) { var index = text.IndexOfAny(XmlEndOfTerm); if (index <= 0) { return; } var delimiterIndex = text.IndexOf(XmlNamespaceDelimeter); if (delimiterIndex > 0 && delimiterIndex < index) { res.Add(new CodeLexem(type, CutString(ref text, delimiterIndex))); res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); res.Add(new CodeLexem(type, CutString(ref text, index - delimiterIndex - 1))); return; } res.Add(new CodeLexem(type, CutString(ref text, index))); }
protected override List<CodeLexem> Parse(SourcePart text) { var list = new List<CodeLexem>(); while (text.Length > 0) { if (TryExtract(list, ref text, "<!--", LexemType.Comment)) TryExtractTo(list, ref text, "-->", LexemType.Comment); if (text.StartsWith("<", StringComparison.Ordinal)) IsInsideBlock = false; if (TryExtract(list, ref text, "\"{}", LexemType.Value)) TryExtractTo(list, ref text, "\"", LexemType.Value); if (TryExtract(list, ref text, "</", LexemType.Symbol) || TryExtract(list, ref text, "<", LexemType.Symbol) || TryExtract(list, ref text, "{", LexemType.Symbol)) { ParseXmlKeyWord(list, ref text, LexemType.Object); } if (TryExtract(list, ref text, "\"", LexemType.Quotes)) { ParseValue(list, ref text); } ParseXmlKeyWord(list, ref text, IsInsideBlock ? LexemType.PlainText : LexemType.Property); TryExtract(list, ref text, "\"", LexemType.Quotes); TryExtract(list, ref text, "}", LexemType.Symbol); if (text.StartsWith(">", StringComparison.Ordinal)) IsInsideBlock = true; ParseSymbol(list, ref text); TrySpace(list, ref text); TryExtract(list, ref text, "\n", LexemType.LineBreak); } return list; }
protected override List <CodeLexem> Parse(SourcePart text) { var list = new List <CodeLexem>(); while (text.Length > 0) { var lenght = text.Length; TryExtract(list, ref text, ByteOrderMark); TryExtract(list, ref text, "[", LexemType.Symbol); TryExtract(list, ref text, "{", LexemType.Symbol); if (TryExtract(list, ref text, "\"", LexemType.Quotes)) { ParseJsonPropertyName(list, ref text); // Extract Name TryExtract(list, ref text, "\"", LexemType.Quotes); TryExtract(list, ref text, ":", LexemType.Symbol); TrySpace(list, ref text); TryExtractValue(list, ref text); // Extract Value } ParseSymbol(list, ref text); // Parse extras TrySpace(list, ref text); TryExtract(list, ref text, "\r\n", LexemType.LineBreak); TryExtract(list, ref text, "\n", LexemType.LineBreak); TryExtract(list, ref text, "}", LexemType.Symbol); TryExtract(list, ref text, "]", LexemType.Symbol); if (lenght == text.Length) { break; } } return(list); }
private void TryExtractValue(List <CodeLexem> res, ref SourcePart text) { if (text[0] == '{') { res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); } else if (text[0] == '[') { res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); } else if (text[0] == '"') { res.Add(new CodeLexem(LexemType.Quotes, CutString(ref text, 1))); var end = text.IndexOf('"'); res.Add(new CodeLexem(LexemType.Value, CutString(ref text, end))); res.Add(new CodeLexem(LexemType.Quotes, CutString(ref text, 1))); } else { var end = text.IndexOfAny(new[] { ',', '}' }); res.Add(new CodeLexem(LexemType.Value, CutString(ref text, end))); res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); } }
private void TryExtractValue(List<CodeLexem> res, ref SourcePart text) { if (text[0] == '{') { res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); } else if (text[0] == '[') { res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); } else if (text[0] == '"') { res.Add(new CodeLexem(LexemType.Quotes, CutString(ref text, 1))); var end = text.IndexOf('"'); res.Add(new CodeLexem(LexemType.Value, CutString(ref text, end))); res.Add(new CodeLexem(LexemType.Quotes, CutString(ref text, 1))); } else { var end = text.IndexOfAny(new[] { ',', '}' }); res.Add(new CodeLexem(LexemType.Value, CutString(ref text, end))); res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); } }