// Create a root document block. public static Syntax.Block make_document() { Syntax.Block e = new Syntax.Block(BlockTag.Document, 1, 1); e.Attributes.ReferenceMap = new Dictionary<string, Reference>(); e.Top = e; return e; }
// Add a block as child of another. Return pointer to child. public static Syntax.Block add_child(Syntax.Block parent, BlockTag block_type, int start_line, int start_column) { // if 'parent' isn't the kind of block that can accept this child, // then back up til we hit a block that can. while (!can_contain(parent.Tag, block_type)) { finalize(parent, start_line); parent = parent.Parent; } if (parent == null) throw new ArgumentNullException("parent"); Syntax.Block child = new Syntax.Block(block_type, start_line, start_column); child.Parent = parent; child.Top = parent.Top; if (parent.LastChild != null) { parent.LastChild.Next = child; child.Previous = parent.LastChild; } else { parent.FirstChild = child; child.Previous = null; } parent.LastChild = child; return child; }