Example #1
0
        private LinkedBuilderContext SwapParent(LinkedBuilderContext newParent)
        {
            if (this.parent == null)
                this.parser.DropContext(this);
            else
                this.parent.childs.Remove(this);

            this.parent = newParent;
            newParent.Add(this);

            return newParent;
        }
Example #2
0
 private LinkedListNode<LinkedBuilderContext> AddByCommand(InsertCommand command, 
     LinkedBuilderContext context)
 {
     return command == InsertCommand.First ? this.childs.AddFirst(context) : this.childs.AddLast(context);
 }
Example #3
0
 private LinkedListNode<LinkedBuilderContext> AddByNode(LinkedListNode<LinkedBuilderContext> node,
     LinkedBuilderContext context)
 {
     return this.childs.AddAfter(node, context);
 }
Example #4
0
        public INodeBuilderContext WrapContext(INodeBuilder wrapper)
        {
            this.TranslateOut();
            var preParent = this.parser.ActiveContext;
            var wrapperContext = new LinkedBuilderContext(parser, preParent, wrapper);
            preParent.Add(wrapperContext);

            return this.SwapParent(wrapperContext);
        }
Example #5
0
        private LinkedBuilderContext Add(LinkedBuilderContext context)
        {
            this.preSiblingPointer =
                this.insertCommand.HasValue
                    ? this.AddByCommand(this.insertCommand.Value, context)
                    : this.AddByNode(preSiblingPointer, context);

            return context;
        }
Example #6
0
        public INodeBuilderContext ChildContext(INodeBuilder child)
        {
            var context = new LinkedBuilderContext(parser, this, child);
            this.parser.SetActiveContext(context);

            return this.Add(context);
        }
Example #7
0
        public INodeBuilderContext SiblingContext(INodeBuilder sibling)
        {
            var context = new LinkedBuilderContext(parser, this.parent, sibling);
            if (this.parent != null)
                this.parent.Add(context);
            else
                this.parser.AddActiveContext(context);

            return context;
        }
Example #8
0
        public LinkedBuilderContext(NodeTreeParser parser, LinkedBuilderContext parent, INodeBuilder builder)
        {
            this.parser = parser;
            this.parent = parent;
            this.builder = builder;
            this.childs = new LinkedList<LinkedBuilderContext>();

            this.insertCommand = InsertCommand.Last;

            this.contextId = _lastId++;
        }
Example #9
0
 internal void SetActiveContext(LinkedBuilderContext context, bool contextless)
 {
     this.activeContext =
         context ??
         (contextless ? this.AddNewContext() : this.NewContext());
 }
Example #10
0
 internal void SetActiveContext(LinkedBuilderContext context)
 {
     SetActiveContext(context, false);
 }
Example #11
0
 internal void DropContext(LinkedBuilderContext context)
 {
     this.contexts.Remove(context);
 }
Example #12
0
 internal void AddActiveContext(LinkedBuilderContext context)
 {
     lock (contexts)
     {
         this.SetActiveContext(context);
         this.contexts.Add(activeContext);
     }
 }