private bool ParseSingleLineBlock() { Context.UpdateSeenValidEmailPrefix(); // Output the ":" as a transition token Context.AcceptCurrent(); End(MetaCodeSpan.Create); while (!EndOfFile) { if (!TryStartCodeParser(isSingleLineMarkup: true)) { if (ParserHelpers.IsNewLine(CurrentCharacter)) { Context.AcceptNewLine(); return(false); } else { Context.UpdateSeenValidEmailPrefix(); Context.AcceptCurrent(); } } } return(true); }
protected bool RequireSingleWhiteSpace() { if (Char.IsWhiteSpace(CurrentCharacter)) { if (ParserHelpers.IsNewLine(CurrentCharacter)) { Context.AcceptNewLine(); } else { Context.AcceptCurrent(); } return(true); } return(false); }
/// <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 ParseTagBlock(bool inDocument) { // For tracking end tags Stack <TagInfo> tags = new Stack <TagInfo>(); bool startedByPseudoTag = false; bool?canGrow = null; do { // Append until the next tag, processing code as we find it AppendUntilAndParseCode(c => c == '<'); // Read the tag name in lookahead since we might not actually want to accept it TagInfo tag = ParseStartOfTag(); // Special case for "<text>" tag as the first tag we've seen if (IsPsuedoTagValidHere(inDocument, tags, startedByPseudoTag, tag)) { if (!tag.IsEndTag) { startedByPseudoTag = true; // Set a flag to indicate that a </text> is a valid end tag if (ParseStartPsuedoTag(tags, tag)) { // Can't just do "canGrow = !ParseStartPsuedoTag(...)" because we can't canGrow to // stay null if we get false from ParseStartPsuedoTag canGrow = false; } } else { ParseEndPsuedoTag(tags, tag, inDocument); canGrow = false; } } // It wasn't a "<text>" OR it was but it was within a block, so we don't do anything special else { // We're at the '<' Context.AcceptCurrent(); // "<" if (tag.IsEndTag) { Context.AcceptCurrent(); // "/" } Context.AcceptCharacters(tag.Name.Length); // tag name // Invalid tag name? Not a real tag if (!String.IsNullOrEmpty(tag.Name)) { // What kind of tag is it bool?unterminated = null; switch (tag.Name[0]) { case '!': unterminated = ParseBangTag(tag.Name); break; case '?': unterminated = ParseProcessingInstruction(); break; default: if (tag.IsEndTag) { unterminated = ParseEndTag(tags, tag, inDocument); } else { unterminated = ParseStartTag(tags, tag); } break; } if (tags.Count == 0 && unterminated != null) { canGrow = unterminated.Value; } } else { canGrow = true; if (tags.Count == 0) { OnError(CurrentLocation, RazorResources.ParseError_OuterTagMissingName); } } } } while (!EndOfFile && tags.Count > 0); if (canGrow == null) { canGrow = tags.Count > 0; } if (tags.Count > 0) { // Ended because of EOF, not matching close tag. Throw error for last tag while (tags.Count > 1) { tags.Pop(); } TagInfo tag = tags.Pop(); OnError(tag.Start, RazorResources.ParseError_MissingEndTag, tag.Name); } // Add the remaining whitespace (up to and including the next newline) to the token if run-time mode if (!DesignTimeMode) { // Dev10 Bug 884969 - Emit space between markup and code Context.AcceptWhiteSpace(includeNewLines: false); if (Char.IsWhiteSpace(CurrentCharacter)) { Context.AcceptLine(includeNewLineSequence: true); } } else if (canGrow.Value) { Context.AcceptWhiteSpace(includeNewLines: false); if (ParserHelpers.IsNewLine(CurrentCharacter)) { Context.AcceptNewLine(); } } return(canGrow.Value); }