private bool ParseModelStatement(CodeBlockInfo block) { var currentLocation = this.CurrentLocation; var acceptedCharacters = this.RequireSingleWhiteSpace() ? AcceptedCharacters.None : AcceptedCharacters.Any; this.End(MetaCodeSpan.Create(this.Context, false, acceptedCharacters)); if (this.modelStatementFound) { this.OnError(currentLocation, string.Format(CultureInfo.CurrentCulture, "Only one @model statement is allowed.")); } this.modelStatementFound = true; this.Context.AcceptWhiteSpace(false); string modelTypeName = null; if (ParserHelpers.IsIdentifierStart(this.CurrentCharacter)) { using (this.Context.StartTemporaryBuffer()) { this.Context.AcceptUntil(c => ParserHelpers.IsNewLine(c)); modelTypeName = this.Context.ContentBuffer.ToString(); this.Context.AcceptTemporaryBuffer(); } this.Context.AcceptNewLine(); } else { this.OnError(currentLocation, string.Format(CultureInfo.CurrentCulture, "@model must be followed by a type name.")); } this.CheckForInheritsAndModelStatements(); this.End(new ModelSpan(this.Context, modelTypeName)); return(false); }
private bool IsIdentifierStart() { if (CurrentCharacter == '_') { // VB Spec §2.2: // If an identifier begins with an underscore, it must contain at least one other valid identifier character to disambiguate it from a line continuation. return(ParserHelpers.IsIdentifierPart(Peek())); } if (CurrentCharacter == '[') { return(ParserHelpers.IsIdentifierPart(Peek())); } return(ParserHelpers.IsIdentifierStart(CurrentCharacter)); }
/// <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); }
/// <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); }
private bool ParseResourceStatement(CodeBlockInfo block) { End(MetaCodeSpan.Create); SourceLocation endModelLocation = CurrentLocation; if (_modelStatementFound) { OnError(endModelLocation, String.Format(CultureInfo.CurrentCulture, "Only one '{0}' statement is allowed in a file.", ResourceKeyword)); } _modelStatementFound = 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()) { // Accept a dotted-identifier, but allow <> AcceptTypeName(); typeName = Context.ContentBuffer.ToString(); Context.AcceptTemporaryBuffer(); } } else { OnError(endModelLocation, String.Format(CultureInfo.CurrentCulture, "The '{0}' keyword must be followed by a type name on the same line.", ResourceKeyword)); } CheckForInheritsAndResourceStatements(); End(ResourceSpan.Create(Context, typeName)); return(false); }