示例#1
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);
        }
示例#2
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;
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
文件: XmlParser.cs 项目: 4lx/Profiler
        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;
        }
示例#6
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;
        }