/// <summary> /// Parse all portions of a multi block /// </summary> private void PBComma(Block Item) { ParseNextPortion: //We are already a multi, parse all next portions if (Item.Type == Block.eType.Multi) { while (true) { //Parse the implicit multi block Block bl = new Block(); bl.Parent = Item; ParseBlock(bl, true); //Don't add a block with 1 item if (bl.Elements.Count == 1) { var el = bl.Elements[0]; bl.Elements.Clear(); //Update the parent if it is a block Block bl2 = el as Block; if (bl2 != null) bl2.Parent = Item; //Add the item Item.Elements.Add(el); } else //Add the block Item.Elements.Add(bl); //Got another portion? if (!_caret.WS().Match(@",")) break; } //Update last element's annotation if (Item.Elements.Count > 0) { var el = Item.Elements[Item.Elements.Count - 1]; if (el != null) Item.Annotation.SourcePosition.End = el.Annotation.SourcePosition.End; } } //We now become a multi - prepare first portion else { //We can't allow empty portions if (Item.Elements.Count == 0) Item.Elements.Add(null); else if (Item.Elements.Count > 1) { //Create a new block Block bl = new Block(); bl.TransferFrom(Item); bl.Parent = Item; //bl.TextPosition.Start = bl.Elements[0].TextPosition.Start; bl.Annotation.SourcePosition.End = bl.Elements[bl.Elements.Count - 1].Annotation.SourcePosition.End; //Add the block Item.Elements.Add(bl); } Item.Type = Block.eType.Multi; //Parse next portion goto ParseNextPortion; //return PBComma(Item); //Is this more elegant than a goto? Dunno, but //C# doesn't allow non-parent-block jumps, and //this provides the exact same functionality } }