private string AcceptTagName() { // Comments start as soon as the "!--" is read, so parsing until the first whitespace character (or the end of the tag) won't identify them properly. if (Context.Peek("!--", caseSensitive: true)) { Context.Expect("!--"); return("!--"); } // Didn't return from above, so it's not a comment return(Context.AcceptUntil(c => Char.IsWhiteSpace(c) || c == '/' || c == '>' || c == RazorParser.TransitionCharacter)); }
/// <summary> /// Parses the modeltype statement. /// </summary> /// <param name="block">The code block.</param> public bool ParseModelTypeStatement(CodeBlockInfo block) { Contract.Requires(block != null); using (StartBlock(BlockType.Directive)) { block.ResumeSpans(Context); SourceLocation location = CurrentLocation; bool readWhitespace = RequireSingleWhiteSpace(); End(MetaCodeSpan.Create(Context, false, readWhitespace ? AcceptedCharacters.None : AcceptedCharacters.Any)); if (_modelOrInheritsStatementFound) { OnError(location, "The modeltype or inherits keywords can only appear once."); } _modelOrInheritsStatementFound = true; // Accept Whitespace up to the new line or non-whitespace character Context.AcceptWhiteSpace(false); string typeName = null; if (ParserHelpers.IsIdentifierStart(CurrentCharacter)) { using (Context.StartTemporaryBuffer()) { Context.AcceptUntil(ParserHelpers.IsNewLine); typeName = Context.ContentBuffer.ToString(); Context.AcceptTemporaryBuffer(); } Context.AcceptNewLine(); } else { OnError(location, "Expected model identifier."); } End(new ModelSpan(Context, typeName)); } return(false); }
private bool ParseModelStatement(CodeBlockInfo block) { using (StartBlock(BlockType.Directive)) { block.ResumeSpans(Context); SourceLocation endModelLocation = CurrentLocation; bool readWhitespace = RequireSingleWhiteSpace(); End(MetaCodeSpan.Create(Context, hidden: false, acceptedCharacters: readWhitespace ? AcceptedCharacters.None : AcceptedCharacters.Any)); if (_modelStatementFound) { OnError(endModelLocation, String.Format(CultureInfo.CurrentCulture, MvcResources.MvcRazorCodeParser_OnlyOneModelStatementIsAllowed, ModelTypeKeyword)); } _modelStatementFound = true; // Accept Whitespace up to the new line or non-whitespace character Context.AcceptWhiteSpace(includeNewLines: false); string typeName = null; if (ParserHelpers.IsIdentifierStart(CurrentCharacter)) { using (Context.StartTemporaryBuffer()) { Context.AcceptUntil(c => ParserHelpers.IsNewLine(c)); typeName = Context.ContentBuffer.ToString(); Context.AcceptTemporaryBuffer(); } Context.AcceptNewLine(); } else { OnError(endModelLocation, String.Format(CultureInfo.CurrentCulture, MvcResources.MvcRazorCodeParser_ModelKeywordMustBeFollowedByTypeName, ModelTypeKeyword)); } CheckForInheritsAndModelStatements(); End(new ModelSpan(Context, typeName)); } return(false); }
protected void ParseComment() { using (StartBlock(BlockType.Comment)) { SourceLocation startLocation = CurrentLocation; Context.Expect(RazorParser.StartCommentSequence[0]); End(TransitionSpan.Create(Context, hidden: false, acceptedCharacters: AcceptedCharacters.None)); Context.Expect(RazorParser.StartCommentSequence[1]); End(MetaCodeSpan.Create(Context, hidden: false, acceptedCharacters: AcceptedCharacters.None)); bool inComment = true; while (inComment && !EndOfFile) { Context.AcceptUntil(RazorParser.EndCommentSequence[0]); if (Context.Peek(RazorParser.EndCommentSequence, caseSensitive: true)) { inComment = false; } else { Context.AcceptCurrent(); } } End(CommentSpan.Create); if (EndOfFile) { OnError(startLocation, RazorResources.ParseError_RazorComment_Not_Terminated); } else { Context.Expect(RazorParser.EndCommentSequence[0]); End(MetaCodeSpan.Create(Context, hidden: false, acceptedCharacters: AcceptedCharacters.None)); Context.Expect(RazorParser.EndCommentSequence[1]); End(TransitionSpan.Create(Context, hidden: false, acceptedCharacters: AcceptedCharacters.None)); } } }
/// <summary> /// Parses the model statement. /// </summary> /// <param name="block">The code block.</param> private bool ParseModelStatement(CodeBlockInfo block) { var location = CurrentLocation; bool readWhiteSpace = RequireSingleWhiteSpace(); End(MetaCodeSpan.Create(Context, false, readWhiteSpace ? AcceptedCharacters.None : AcceptedCharacters.Any)); if (_modelOrInheritsStatementFound) { OnError(location, "The model or inherits keywords can only appear once."); } _modelOrInheritsStatementFound = true; Context.AcceptWhiteSpace(false); string typeName = null; if (ParserHelpers.IsIdentifierStart(CurrentCharacter)) { using (Context.StartTemporaryBuffer()) { Context.AcceptUntil(ParserHelpers.IsNewLine); typeName = Context.ContentBuffer.ToString(); Context.AcceptTemporaryBuffer(); } Context.AcceptNewLine(); } else { OnError(location, "Expected model identifier."); } End(new ModelSpan(Context, typeName)); return(false); }