protected ForEach(Parser parser, CodeObject parent) : base(parser, parent) { parser.NextToken(); // Move past 'foreach' ParseExpectedToken(parser, Expression.ParseTokenStartGroup); // Move past '(' SetField(ref _iteration, LocalDecl.Parse(parser, this, false, false), false); ParseExpectedToken(parser, ParseTokenIn); SetField(ref _collection, Expression.Parse(parser, this, true, Expression.ParseTokenEndGroup), false); ParseExpectedToken(parser, Expression.ParseTokenEndGroup); // Move past ')' new Block(out _body, parser, this, false); // Parse the body }
protected For(Parser parser, CodeObject parent) : base(parser, parent) { parser.NextToken(); // Move past 'for' ParseExpectedToken(parser, Expression.ParseTokenStartGroup); // Parse either LocalDecl or Expression List if (LocalDecl.PeekLocalDecl(parser)) { _initializations = LocalDecl.Parse(parser, this, false, true); } else { _initializations = Expression.ParseList(parser, this, Expression.ParseTokenEndGroup); } if (_initializations == null) { MoveAllComments(parser.LastToken, false, false, AnnotationFlags.IsInfix1); } ParseExpectedToken(parser, Terminator); // Move past ';' SetField(ref _conditional, Expression.Parse(parser, this, true, Terminator + Expression.ParseTokenEndGroup), false); if (_conditional == null) { MoveAllComments(parser.LastToken, false, false, AnnotationFlags.IsInfix2); } ParseExpectedToken(parser, Terminator); // Move past ';' _iterations = Expression.ParseList(parser, this, Expression.ParseTokenEndGroup); if (_iterations == null) { MoveAllComments(parser.LastToken, false, false, AnnotationFlags.IsInfix3); } ParseExpectedToken(parser, Expression.ParseTokenEndGroup); if (parser.TokenText == Terminator && !parser.Token.IsFirstOnLine) { ParseTerminator(parser); // Handle same-line ';' (null body) } else { new Block(out _body, parser, this, false); // Parse the body } }
protected Using(Parser parser, CodeObject parent) : base(parser, parent) { parser.NextToken(); // Move past 'using' ParseExpectedToken(parser, Expression.ParseTokenStartGroup); // Move past '(' // Parse either LocalDecl or Expression (object) if (LocalDecl.PeekLocalDecl(parser)) { SetField(ref _target, LocalDecl.Parse(parser, this, false, true), false); } else { SetField(ref _target, Expression.Parse(parser, this, true, Expression.ParseTokenEndGroup), false); } ParseExpectedToken(parser, Expression.ParseTokenEndGroup); // Move past ')' new Block(out _body, parser, this, false); // Parse the body }
protected Catch(Parser parser, CodeObject parent) : base(parser, parent) { MoveComments(parser.LastToken); // Get any comments before 'catch' parser.NextToken(); // Move past 'catch' // Check for compiler directives, storing them as infix annotations on the parent Block.ParseCompilerDirectives(parser, this, AnnotationFlags.IsInfix1); // Check if 'catch' has parens if (parser.TokenText == Expression.ParseTokenStartGroup) { parser.NextToken(); // Move past '(' // Parse either LocalDecl or Expression (TypeRef) if (LocalDecl.PeekLocalDecl(parser)) { SetField(ref _target, LocalDecl.Parse(parser, this, false, false), false); } else { SetField(ref _target, Expression.Parse(parser, this, true, Expression.ParseTokenEndGroup), false); } ParseExpectedToken(parser, Expression.ParseTokenEndGroup); // Move past ')' } new Block(out _body, parser, this, true); // Parse the body ParseUnusedAnnotations(parser, this, true); // Parse any annotations from the Unused list // Remove any preceeding blank lines if auto-cleanup is on if (AutomaticFormattingCleanup && NewLines > 1) { NewLines = 1; } }