protected internal void Accept(TSymbol symbol) { if (symbol != null) { foreach (RazorError error in symbol.Errors) { Context.Errors.Add(error); } Span.Accept(symbol); } }
/// <summary> /// Accepts the specified symbol. /// </summary> /// <param name="symbol">The symbol.</param> protected internal void Accept(TSymbol symbol) { if (symbol != null) { foreach (var error in symbol.Errors) { Context.OnError(error); } Span.Accept(symbol); } }
protected virtual void SectionDirective() { bool nested = Context.IsWithin(BlockType.Section); bool errorReported = false; // Set the block and span type Context.CurrentBlock.Type = BlockType.Section; // Verify we're on "section" and accept AssertDirective(SyntaxConstants.CSharp.SectionKeyword); AcceptAndMoveNext(); if (nested) { Context.OnError(CurrentLocation, String.Format(CultureInfo.CurrentCulture, RazorResources.ParseError_Sections_Cannot_Be_Nested, RazorResources.SectionExample_CS)); errorReported = true; } IEnumerable <CSharpSymbol> ws = ReadWhile(IsSpacingToken(includeNewLines: true, includeComments: false)); // Get the section name string sectionName = String.Empty; if (!Required(CSharpSymbolType.Identifier, errorIfNotFound: true, errorBase: RazorResources.ParseError_Unexpected_Character_At_Section_Name_Start)) { if (!errorReported) { errorReported = true; } PutCurrentBack(); PutBack(ws); AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: false)); } else { Accept(ws); sectionName = CurrentSymbol.Content; AcceptAndMoveNext(); } Context.CurrentBlock.CodeGenerator = new SectionCodeGenerator(sectionName); SourceLocation errorLocation = CurrentLocation; ws = ReadWhile(IsSpacingToken(includeNewLines: true, includeComments: false)); // Get the starting brace bool sawStartingBrace = At(CSharpSymbolType.LeftBrace); if (!sawStartingBrace) { if (!errorReported) { errorReported = true; Context.OnError(errorLocation, RazorResources.ParseError_MissingOpenBraceAfterSection); } PutCurrentBack(); PutBack(ws); AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: false)); Optional(CSharpSymbolType.NewLine); Output(SpanKind.MetaCode); CompleteBlock(); return; } else { Accept(ws); } // Set up edit handler AutoCompleteEditHandler editHandler = new AutoCompleteEditHandler(Language.TokenizeString) { AutoCompleteAtEndOfSpan = true }; Span.EditHandler = editHandler; Span.Accept(CurrentSymbol); // Output Metacode then switch to section parser Output(SpanKind.MetaCode); SectionBlock("{", "}", caseSensitive: true); Span.CodeGenerator = SpanCodeGenerator.Null; // Check for the terminating "}" if (!Optional(CSharpSymbolType.RightBrace)) { editHandler.AutoCompleteString = "}"; Context.OnError(CurrentLocation, RazorResources.ParseError_Expected_X, Language.GetSample(CSharpSymbolType.RightBrace)); } else { Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; } CompleteBlock(insertMarkerIfNecessary: false, captureWhitespaceToEndOfLine: true); Output(SpanKind.MetaCode); return; }