/// <summary> /// Deep-clone the code object. /// </summary> public override CodeObject Clone() { MultiLocalDecl clone = (MultiLocalDecl)base.Clone(); clone._localDecls = ChildListHelpers.Clone(_localDecls, clone); return(clone); }
/// <summary> /// Parse a <see cref="LocalDecl"/>. /// </summary> public static LocalDecl Parse(Parser parser, CodeObject parent, bool standAlone, bool allowInitAndMulti) { // Parse the first LocalDecl LocalDecl localDecl = new LocalDecl(parser, parent, standAlone, allowInitAndMulti, true, false); // Handle additional LocalDecls after any commas if (!localDecl.HasTerminator && allowInitAndMulti && parser.TokenText == Expression.ParseTokenSeparator) { // If it's a multi, create one, and transfer the IsFirstOnLine setting MultiLocalDecl multiLocalDecl = new MultiLocalDecl(localDecl) { NewLines = localDecl.NewLines, HasTerminator = false }; multiLocalDecl.SetLineCol(localDecl); localDecl.NewLines = 0; do { Token commaToken = parser.Token; parser.NextToken(); // Move past ',' // Associate any EOL comment on the ',' to the last LocalDecl localDecl.MoveEOLComment(commaToken, false, false); localDecl = new LocalDecl(parser, null, false, true, false, true); // Force the expression to first-on-line if the last comma was (handles special-case // formatting where the commas preceed the list items instead of following them). if (commaToken.IsFirstOnLine) { localDecl.IsFirstOnLine = true; } // Move any comments after the ',' to the current LocalDecl localDecl.MoveComments(commaToken); multiLocalDecl.Add(localDecl); }while (parser.TokenText == Expression.ParseTokenSeparator); localDecl = multiLocalDecl; if (standAlone) { multiLocalDecl.ParseTerminator(parser); } } return(localDecl); }