private (CommentGroup comments, int endline) ConsumeCommentGroup(int n) { var list = new slice <Comment>(); var endline = tok.Pos.Line; while (tok.Type == TokenType.COMMENT && tok.Pos.Line <= endline + n) { Comment comment; (comment, endline) = ConsumeComment(); list = list.Append(comment); } // add comment group to the comments list var comments = new CommentGroup { List = list }; this.comments = this.comments.Append(comments); return(comments, endline); }
public void Add(ObjectItem item) { Items = Items.Append(item); }
public void Add(INode node) { List = List.Append(node); }
/// Format the text between line0 and line1 (excluding line1); pos /// is the buffer position corresponding to the beginning of line0. /// Returns the buffer position corresponding to the beginning of /// line1 and an error, if any. /// private int Format(int pos0, int line0, int line1) { var pos = pos0; var column = widths.Length; for (var thisLine = line0; thisLine < line1; thisLine++) { var line = lines[thisLine]; if (column < line.Length - 1) { // cell exists in this column => this line // has more cells than the previous line // (the last cell per line is ignored because cells are // tab-terminated; the last cell per line describes the // text before the newline/formfeed and does not belong // to a column) // print unprinted lines until beginning of block pos = WriteLines(pos, line0, thisLine); line0 = thisLine; // column block begin var width = minwidth; // minimal column width var discardable = true; // true if all cells in this column are empty and "soft" for (; thisLine < line1; thisLine++) { line = lines[thisLine]; if (column < line.Length - 1) { // cell exists in this column var c = line[column]; // update width var w = c.width + padding; if (w > width) { width = w; } // update discardable if (c.width > 0 || c.htab) { discardable = false; } } else { break; } } // column block end // discard empty columns if necessary if (discardable && (flags & Formatting.DiscardEmptyColumns) != 0) { width = 0; } // format and print all columns to the right of this column // (we know the widths of this column and all columns to the left) widths = widths.Append(width); // push width pos = Format(pos, line0, thisLine); widths = widths.Slice(0, widths.Length - 1); // pop width line0 = thisLine; } } // print unprinted lines until end return(WriteLines(pos, line0, line1)); }
private slice <int> widths; // list of column widths in runes - re-used during formatting private void AddLine() { this.lines = lines.Append(new slice <Cell>()); }