Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
        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)));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        protected bool TryExtract(List <CodeLexem> res, ref SourcePart text, string lex)
        {
            if (text.StartsWith(lex))
            {
                CutString(ref text, lex.Length);
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        protected bool TryExtract(List<CodeLexem> res, ref SourcePart text, string lex)
        {
            if (text.StartsWith(lex))
            {
                CutString(ref text, lex.Length);
                return true;
            }

            return false;
        }
Exemplo n.º 12
0
        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)));
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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()));
            }
        }
Exemplo n.º 17
0
        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()));
            }
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
0
 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)));
 }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        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;
            }
        }
Exemplo n.º 23
0
        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;
            }
        }
Exemplo n.º 24
0
        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)));
        }
Exemplo n.º 25
0
        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;
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
 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)));
     }
 }
Exemplo n.º 28
0
 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)));
     }
 }