Inheritance: ParseToken
示例#1
0
        /// <summary>
        /// remove pre
        /// </summary>
        static void RemoveFormating(ElementToken root)
        {
            var node = root.Tokens.First;

            while (node != null)
            {
                var item = node.Value;
                if (!(item is ElementToken))
                {
                    node = node.Next;
                    continue;
                }

                var el = (ElementToken)item;
                RemoveFormating(el);

                if (el.Name == "pre")
                {
                    foreach (var subNode in el.Tokens)
                    {
                        root.Tokens.AddBefore(node, subNode);
                    }

                    var next = node.Next;
                    root.Tokens.Remove(node);
                    node = next;
                }
                else
                {
                    node = node.Next;
                    continue;
                }
            }
        }
示例#2
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);
        }
示例#3
0
        private static Inline BuildFont(ElementToken token, Hint hint)
        {
            var span = new Span();

              string size;
              if (token.Attributes.TryGetValue("size", out size))
              {
            var fc = new FontSizeConverter();
            var sz = (double)fc.ConvertFromString(size);
            span.FontSize = sz;
              }

              string face;
              if (token.Attributes.TryGetValue("face", out face))
              {
            span.FontFamily = new FontFamily(face);
              }

              string color;
              if (token.Attributes.TryGetValue("color", out color))
              {
            var bc = new BrushConverter();
            var br = (Brush)bc.ConvertFromString(color);
            span.Foreground = br;
              }
              return span.Fill(token, hint);
        }
示例#4
0
        static ElementToken InsertElement(ElementToken token, int i1, int i2, string name)
        {
            var newToken = Split(token, i1);
            newToken.Name = name;
            token.Tokens.AddLast(newToken);

            var tmp = SplitBack(newToken, i2);
            foreach (var t in tmp.Tokens)
            {
                token.Tokens.AddLast(t);
            }

            return newToken;
        }
示例#5
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());
 }
示例#6
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());
 }
示例#7
0
        static ElementToken Split(ElementToken token, int index)
        {
            for (var node = token.Tokens.First; ; node = node.Next)
            {
                var r = node.Value;

                if (index == r.StartIndex)
                {
                    return(token.Split(node, false));
                }
                if (index < r.EndIndex)
                {
                    return(SplitNode(token, node, index, false));
                }
            }
        }
示例#8
0
        static ElementToken InsertElement(ElementToken token, int i1, int i2, string name)
        {
            var newToken = Split(token, i1);

            newToken.Name = name;
            token.Tokens.AddLast(newToken);

            var tmp = SplitBack(newToken, i2);

            foreach (var t in tmp.Tokens)
            {
                token.Tokens.AddLast(t);
            }

            return(newToken);
        }
示例#9
0
        static ElementToken SplitBack(ElementToken token, int index)
        {
            for (var node = token.Tokens.Last; ; node = node.Previous)
            {
                var r = node.Value;

                if (index == r.EndIndex)
                {
                    return(token.Split(node, true));
                }
                if (index > r.StartIndex)
                {
                    return(SplitNode(token, node, index, true));
                }
            }
        }
示例#10
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;
            }
        }
示例#11
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;
            }
        }
示例#12
0
        private static Inline BuildHint(ElementToken token, Hint hint)
        {
            Trace.Assert(token.Name == "hint");

              string handler;
              token.Attributes.TryGetValue("handler", out handler);

              string key;
              token.Attributes.TryGetValue("key", out key);

              string value = token.Attributes["value"];

              var hc = key == null ? new HintControl(token.ToString(), handler)
                           : new HintControl(key, hint.RaiseGetHintContent, handler);
              //Fill(hc.Inlines, token);
              hc.Inlines.Add(new Run(value));
              return new InlineUIContainer { Child = hc };
        }
示例#13
0
        static ElementToken FindParamToken(ElementToken rootToken, int i1, int i2)
        {
            foreach (var child in rootToken.Tokens)
            {
                var r = child;
                var a1 = r.Contains(i1);
                var a2 = r.Contains(i2);

                if (a1 && a2) // both
                {
                    if (child is TextToken) return rootToken;
                    return FindParamToken((ElementToken)child, i1, i2);
                }

                if (a1 || a2) return rootToken;
            }
            return null;
        }
示例#14
0
        public ElementToken Split(LinkedListNode<ParseToken> splitNode, bool after)
        {
            var token = splitNode.Value;
            var index = after ? token.EndIndex : token.StartIndex;

            var newToken = new ElementToken(index, _rangeList) { Name = Name };
            newToken.Attributes = this.Attributes;

            // split nodes
            var cur = after ? splitNode.Next : splitNode;
            while (cur != null)
            {
                var tmp = cur.Next;
                Tokens.Remove(cur);
                newToken.Tokens.AddLast(cur);
                cur = tmp;
            }
            return newToken;
        }
示例#15
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);
                }
            }
        }
示例#16
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;
        }
示例#17
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);
                }
            }
        }
示例#18
0
        private static Inline BuildParam(ElementToken token, Hint hint)
        {
            var pp = new ParamPanel();
              foreach (ParseToken pt in token.Tokens)
              {
            var et = pt as ElementToken;
            if (et != null)
            {
              var tb = new TextBlock().Fill(et, hint);
              pp.Children.Add(tb);
              if (et.Name == "pname")
            ParamPanel.SetNameColumn(tb, true);

              continue;
            }

            var tt = pt as TextToken;
            if (tt != null && pp.Children.Count > 0)
            {
              var elem = pp.Children[pp.Children.Count - 1] as TextBlock;
              if (elem != null)
            elem.Inlines.Add(GetInline(tt, hint));

              continue;
            }
              }

              var span = new Span();
              span.Inlines.Add(new SoftBreak());
              span.Inlines.Add(new InlineUIContainer
                       {
                         Child = pp,
                         BaselineAlignment = BaselineAlignment.Bottom
                       });
              span.Inlines.Add(new SoftBreak());
              return span;
        }
示例#19
0
        static ElementToken FindParamToken(ElementToken rootToken, int i1, int i2)
        {
            foreach (var child in rootToken.Tokens)
            {
                var r  = child;
                var a1 = r.Contains(i1);
                var a2 = r.Contains(i2);

                if (a1 && a2)                 // both
                {
                    if (child is TextToken)
                    {
                        return(rootToken);
                    }
                    return(FindParamToken((ElementToken)child, i1, i2));
                }

                if (a1 || a2)
                {
                    return(rootToken);
                }
            }
            return(null);
        }
示例#20
0
        static ElementToken SplitNode(ElementToken token, LinkedListNode <ParseToken> node, int index, bool back)
        {
            var curToken = node.Value;

            ParseToken newToken = null;

            if (curToken is TextToken)
            {
                // split text
                newToken = ((TextToken)curToken).Split(index);
            }
            else if (curToken is ElementToken)
            {
                newToken = back
                                                                                         ? SplitBack((ElementToken)curToken, index)
                                                                                         : Split((ElementToken)curToken, index);
            }

            // add new node after curNode
            token.Tokens.AddAfter(node, newToken);

            // split by node
            return(token.Split(node, true));
        }
示例#21
0
        public ElementToken Split(LinkedListNode <ParseToken> splitNode, bool after)
        {
            var token = splitNode.Value;
            var index = after ? token.EndIndex : token.StartIndex;

            var newToken = new ElementToken(index, _rangeList)
            {
                Name = Name
            };

            newToken.Attributes = this.Attributes;

            // split nodes
            var cur = after ? splitNode.Next : splitNode;

            while (cur != null)
            {
                var tmp = cur.Next;
                Tokens.Remove(cur);
                newToken.Tokens.AddLast(cur);
                cur = tmp;
            }
            return(newToken);
        }
示例#22
0
 private static TextBlock Fill(this TextBlock tb, ElementToken token, Hint hint)
 {
     Fill(tb.Inlines, token, hint);
       return tb;
 }
示例#23
0
 private static Span Fill(this Span span, ElementToken token, Hint hint)
 {
     Fill(span.Inlines, token, hint);
       return span;
 }
示例#24
0
        static ElementToken SplitBack(ElementToken token, int index)
        {
            for (var node = token.Tokens.Last; ; node = node.Previous)
            {
                var r = node.Value;

                if (index == r.EndIndex) return token.Split(node, true);
                if (index > r.StartIndex) return SplitNode(token, node, index, true);
            }
        }
示例#25
0
        static ElementToken Split(ElementToken token, int index)
        {
            for (var node = token.Tokens.First; ; node = node.Next)
            {
                var r = node.Value;

                if (index == r.StartIndex) return token.Split(node, false);
                if (index < r.EndIndex) return SplitNode(token, node, index, false);
            }
        }
示例#26
0
        private static Inline BuildRef(ElementToken token, Hint hint)
        {
            string handler;
              token.Attributes.TryGetValue("handler", out handler);

              string hintStr;
              token.Attributes.TryGetValue("hint", out hintStr);
              if (hintStr != null)
              {
            hintStr = "<code>" + hintStr + "</code>";
              }
              var hc = new HintControl(hintStr, handler);
              Fill(hc.Inlines, token, hint);
              return new InlineUIContainer { Child = hc };
        }
示例#27
0
        static ElementToken SplitNode(ElementToken token, LinkedListNode<ParseToken> node, int index, bool back)
        {
            var curToken = node.Value;

            ParseToken newToken = null;
            if (curToken is TextToken)
            {
                // split text
                newToken = ((TextToken)curToken).Split(index);
            }
            else if (curToken is ElementToken)
            {
                newToken = back
                                             ? SplitBack((ElementToken)curToken, index)
                                             : Split((ElementToken)curToken, index);
            }

            // add new node after curNode
            token.Tokens.AddAfter(node, newToken);

            // split by node
            return token.Split(node, true);
        }
示例#28
0
        /// <summary>
        /// remove pre
        /// </summary>
        static void RemoveFormating(ElementToken root)
        {
            var node = root.Tokens.First;
            while (node != null)
            {
                var item = node.Value;
                if (!(item is ElementToken))
                {
                    node = node.Next;
                    continue;
                }

                var el = (ElementToken)item;
                RemoveFormating(el);

                if (el.Name == "pre")
                {
                    foreach (var subNode in el.Tokens)
                    {
                        root.Tokens.AddBefore(node, subNode);
                    }

                    var next = node.Next;
                    root.Tokens.Remove(node);
                    node = next;
                }
                else
                {
                    node = node.Next;
                    continue;
                }
            }
        }
示例#29
0
 private static void Fill(InlineCollection inlines, ElementToken token, Hint hint)
 {
     foreach (var t in token.Tokens)
       {
     inlines.Add(GetInline(t, hint));
       }
 }
示例#30
0
 private static Inline BuildSymbol(ElementToken token, Hint hint)
 {
     string spanClass = token.Attributes["SpanClass"];
       string value     = token.Text;
       return new Run(value) { Foreground = hint.MapBrush(spanClass) };
 }
示例#31
0
        private static Inline BuildSymbolHint(ElementToken token, Hint hint)
        {
            Trace.Assert(token.Name == "Symbol");

              string handler;
              token.Attributes.TryGetValue("handler", out handler);

              string key       = token.Attributes["id"];
              string spanClass = token.Attributes["SpanClass"];

              string value = token.Text;

              var hc = new HintControl(key, hint.RaiseGetHintContent, handler);
              hc.Inlines.Add(new Run(value) { Foreground = hint.MapBrush(spanClass) });
              return new InlineUIContainer { Child = hc };
        }