示例#1
0
        public ElementToken(int index, RangeList rangeList)
            : base(rangeList)
        {
            _startIndex = index;
            _rangeList = rangeList;

            Tokens = new LinkedList<ParseToken>();
            Attributes = new Dictionary<string, string>();
        }
示例#2
0
        public static RootToken Parse(string text)
        {
            var root = XElement.Parse(text, LoadOptions.PreserveWhitespace);

            var rlist = new RangeList(root.Value);
            var rn = new RootToken(root, rlist);

            //ParamParser.Parse(rn);
            RemoveWhitespaces(rn, rlist);
            RemoveFormating(rn);
            return rn;
        }
示例#3
0
 static ParseToken Create(XNode node, int index, RangeList list)
 {
     if (node is XText)
     {
         var len = ((XText)node).Value.Length;
         return new TextToken(index, len, list);
     }
     if (node is XElement)
     {
         var el = (XElement)node;
         var en = new ElementToken(index, list);
         ParseElement(en, el, index, list);
         return en;
     }
     throw new NotSupportedException(node.NodeType.ToString());
 }
示例#4
0
        static void ParseElement(ElementToken en, XElement el, int index, RangeList list)
        {
            // parse name & attributes
            en.Name = el.Name.ToString();
            foreach (var attr in el.Attributes())
            {
                en.Attributes[attr.Name.ToString()] = attr.Value;
            }

            // parse nodes
            foreach (var node in el.Nodes())
            {
                var pn = Create(node, index, list);
                en.Tokens.AddLast(pn);
                index += pn.Length;
            }
        }
示例#5
0
        static void ClearParamsInPre(ElementToken token, RangeList list)
        {
            foreach (var node in token.Tokens)
            {
                if (!(node is ElementToken)) continue;

                var el = (ElementToken)node;
                if (el.Name != "params")
                {
                    ClearParamsInPre(el, list);
                }
                else
                {
                    var i1 = el.StartIndex;
                    var i2 = el.EndIndex;
                    // clear range
                    ClearRange(i1, i2, list);
                }
            }
        }
示例#6
0
        static void ClearRange(int i1, int i2, RangeList list)
        {
            if (i1 == i2) return;

            var str = list.GetText(i1, i2 - i1);

            // find seq-s of whitespace
            var regex = new Regex("\\s+");
            var ms = regex.Matches(str);

            foreach (Match m in ms)
            {
                var j1 = i1 + m.Index;
                var j2 = j1 + m.Length;
                list.Chars[j1] = ' ';
                for (var i = j1 + 1; i < j2; i++)
                {
                    list.Chars[i] = '\0';
                }
            }
        }
示例#7
0
        static int Clear(int i1, ElementToken root, RangeList list)
        {
            foreach (var node in root.Tokens)
            {
                var i2 = node.StartIndex;
                if (!(node is ElementToken)) continue;

                var el = (ElementToken)node;
                if (el.Name != "pre")
                {
                    i1 = Clear(i1, el, list);
                }
                else
                {
                    ClearParamsInPre(el, list);
                    // clear range
                    ClearRange(i1, i2, list);
                    i1 = el.EndIndex;
                }
            }
            return i1;
        }
示例#8
0
 static void RemoveWhitespaces(RootToken rt, RangeList list)
 {
     //var i1 = Clear(rt.StartIndex, rt, list);
     //ClearRange(i1, rt.EndIndex, list);
 }
示例#9
0
 private TextToken(RangeList rangeList)
     : base(rangeList)
 {
 }
示例#10
0
 public TextToken(int index, int len, RangeList rangeList)
     : base(rangeList)
 {
     Range = _rangeList.AddRange(index, len);
 }
示例#11
0
 public RootToken(XElement root, RangeList rangeList)
     : base(0, rangeList)
 {
     ParseElement(this, root, 0, _rangeList);
 }
示例#12
0
 protected ParseToken(RangeList rangeList)
 {
     _rangeList = rangeList;
     Tokens = new LinkedList<ParseToken>();
 }
示例#13
0
 protected ParseToken(RangeList rangeList)
 {
     _rangeList = rangeList;
     Tokens     = new LinkedList <ParseToken>();
 }
示例#14
0
 public RootToken(XElement root, RangeList rangeList)
     : base(0, rangeList)
 {
     ParseElement(this, root, 0, _rangeList);
 }