예제 #1
0
        public ParseList ParseTemplate(string template)
        {
            List <int> newLinePositions = new List <int>();

            for (int i = 0, len = template.Length; i < len; i++)
            {
                if (template[i] == '\n')
                {
                    newLinePositions.Add(i);
                }
            }

            ParseList parseList = new ParseList();

            MatchCollection matches = TagFinderRegex.Matches(template);

            int peekIndex = 0;

            foreach (Match match in matches)
            {
                Group g = match.Groups[0];

                if (g.Index > peekIndex)
                {
                    parseList.AddRange((ParseExpressions(template.Substring(peekIndex, g.Index - peekIndex))));
                }

                // determine the row number the tag is on and the character position
                int row = 1, pos = 0;
                int len = newLinePositions.Count;
                for (row = 1; row <= len; row++)
                {
                    if (g.Index < newLinePositions[row - 1])
                    {
                        pos = g.Index - ((row <= 1) ? 0 : newLinePositions[row - 2]);
                        break;
                    }
                }

                parseList.Add(tagFactory.ParseTag(g.Value, row, pos));

                // update the peekIndex to be the end of the match
                peekIndex = g.Index + g.Length;
            }

            if (peekIndex < template.Length)
            {
                parseList.AddRange(ParseExpressions(template.Substring(peekIndex)));
            }

            return(parseList);
        }
예제 #2
0
 private void ParseLine()
 {
     if (!IsParsed)
     {
         ParseList.AddRange(Line.Split(Delimiters, StringSplitOptions.None));
         IsParsed = true;
     }
 }
예제 #3
0
        public ParseList ParseTemplate(string template)
        {
            List<int> newLinePositions = new List<int>();
            for (int i = 0, len = template.Length; i < len; i++)
            {
                if (template[i] == '\n')
                {
                    newLinePositions.Add(i);
                }
            }

            ParseList parseList = new ParseList();

            MatchCollection matches = TagFinderRegex.Matches(template);

            int peekIndex = 0;

            foreach (Match match in matches)
            {
                Group g = match.Groups[0];

                if (g.Index > peekIndex)
                {
                    parseList.AddRange((ParseExpressions(template.Substring(peekIndex, g.Index - peekIndex))));
                }

                // determine the row number the tag is on and the character position
                int row = 1, pos = 0;
                int len = newLinePositions.Count;
                for (row = 1; row <= len; row++)
                {
                    if (g.Index < newLinePositions[row - 1])
                    {
                        pos = g.Index - ((row <= 1) ? 0 : newLinePositions[row - 2]);
                        break;
                    }
                }

                parseList.Add(tagFactory.ParseTag(g.Value, row, pos));

                // update the peekIndex to be the end of the match
                peekIndex = g.Index + g.Length;
            }

            if (peekIndex < template.Length)
            {
                parseList.AddRange(ParseExpressions(template.Substring(peekIndex)));
            }

            return parseList;
        }