private IReadOnlyList<CSharpSymbol> ReadArgument(IReadOnlyList<ISymbol> symbols, ref int index, CSharpSymbolType closeSymbolType) { var result = new List<CSharpSymbol>(); var depth = 0; while (true) { var symbol = ReadSymbol(symbols, ref index); if (symbol == null) return null; if (depth == 0 && (symbol.Type == CSharpSymbolType.Comma || symbol.Type == closeSymbolType)) { index--; return result; } if (symbol.Type == CSharpSymbolType.LeftBrace || symbol.Type == CSharpSymbolType.LeftBracket || symbol.Type == CSharpSymbolType.LeftParenthesis) depth++; else if (symbol.Type == CSharpSymbolType.RightBrace || symbol.Type == CSharpSymbolType.RightBracket || symbol.Type == CSharpSymbolType.RightParenthesis) depth--; result.Add(symbol); } }
public static SpanConstructor CodeTransition( this SpanFactory self, string content, CSharpSymbolType type ) { return(self.Span(SpanKind.Transition, content, type).Accepts(AcceptedCharacters.None)); }
public static SpanConstructor Comment( this SpanFactory self, string content, CSharpSymbolType type ) { return(self.Span(SpanKind.Comment, content, type)); }
private bool IsValidTokenType(CSharpSymbolType type) { return(type != CSharpSymbolType.WhiteSpace && type != CSharpSymbolType.NewLine && type != CSharpSymbolType.Comment && type != CSharpSymbolType.RazorComment && type != CSharpSymbolType.RazorCommentStar && type != CSharpSymbolType.RazorCommentTransition && type != CSharpSymbolType.Transition); }
private void HandleStatement(Block block, CSharpSymbolType type) { switch (type) { case CSharpSymbolType.RazorCommentTransition: Output(SpanKind.Code); RazorComment(); Statement(block); break; case CSharpSymbolType.LeftBrace: // Verbatim Block block = block ?? new Block(RazorResources.BlockName_Code, CurrentLocation); AcceptAndMoveNext(); CodeBlock(block); break; case CSharpSymbolType.Keyword: // Keyword block HandleKeyword(false, StandardStatement); break; case CSharpSymbolType.Transition: // Embedded Expression block EmbeddedExpression(); break; case CSharpSymbolType.RightBrace: // Possible end of Code Block, just run the continuation break; case CSharpSymbolType.Comment: AcceptAndMoveNext(); break; default: // Other statement StandardStatement(); break; } }
private void Statement(Block block) { Span.EditHandler.AcceptedCharacters = AcceptedCharacters.Any; // Accept whitespace but always keep the last whitespace node so we can put it back if necessary CSharpSymbol lastWs = AcceptWhiteSpaceInLines(); Debug.Assert( lastWs == null || ( lastWs.Start.AbsoluteIndex + lastWs.Content.Length == CurrentLocation.AbsoluteIndex ) ); if (EndOfFile) { if (lastWs != null) { Accept(lastWs); } return; } CSharpSymbolType type = CurrentSymbol.Type; SourceLocation loc = CurrentLocation; bool isSingleLineMarkup = type == CSharpSymbolType.Transition && NextIs(CSharpSymbolType.Colon); bool isMarkup = isSingleLineMarkup || type == CSharpSymbolType.LessThan || (type == CSharpSymbolType.Transition && NextIs(CSharpSymbolType.LessThan)); if (Context.DesignTimeMode || !isMarkup) { // CODE owns whitespace, MARKUP owns it ONLY in DesignTimeMode. if (lastWs != null) { Accept(lastWs); } } else { // MARKUP owns whitespace EXCEPT in DesignTimeMode. PutCurrentBack(); PutBack(lastWs); } if (isMarkup) { if (type == CSharpSymbolType.Transition && !isSingleLineMarkup) { Context.OnError( loc, RazorResources.ParseError_AtInCode_Must_Be_Followed_By_Colon_Paren_Or_Identifier_Start ); } // Markup block Output(SpanKind.Code); if ( Context.DesignTimeMode && CurrentSymbol != null && ( CurrentSymbol.Type == CSharpSymbolType.LessThan || CurrentSymbol.Type == CSharpSymbolType.Transition ) ) { PutCurrentBack(); } OtherParserBlock(); } else { // What kind of statement is this? HandleStatement(block, type); } }
public SpanConstructor Span(SpanKind kind, string content, CSharpSymbolType type) { return(CreateSymbolSpan(kind, content, st => new CSharpSymbol(st, content, type))); }
public static SpanConstructor MetaCode(this SpanFactory self, string content, CSharpSymbolType type) { return self.Span(SpanKind.MetaCode, content, type); }
public static SpanConstructor CodeTransition(this SpanFactory self, string content, CSharpSymbolType type) { return self.Span(SpanKind.Transition, content, type).Accepts(AcceptedCharacters.None); }
public static SpanConstructor CodeTransition(this SpanFactory self, CSharpSymbolType type) { return self.Span(SpanKind.Transition, SyntaxConstants.TransitionString, type).Accepts(AcceptedCharacters.None); }
internal void TestSingleToken(string text, CSharpSymbolType expectedSymbolType) { TestTokenizer(text, new CSharpSymbol(text, expectedSymbolType)); }
private IReadOnlyList <CSharpSymbol> ReadArgument(IReadOnlyList <ISymbol> symbols, ref int index, CSharpSymbolType closeSymbolType) { var result = new List <CSharpSymbol>(); var depth = 0; while (true) { var symbol = ReadSymbol(symbols, ref index); if (symbol == null) { return(null); } if (depth == 0 && (symbol.Type == CSharpSymbolType.Comma || symbol.Type == closeSymbolType)) { index--; return(result); } if (symbol.Type == CSharpSymbolType.LeftBrace || symbol.Type == CSharpSymbolType.LeftBracket || symbol.Type == CSharpSymbolType.LeftParenthesis) { depth++; } else if (symbol.Type == CSharpSymbolType.RightBrace || symbol.Type == CSharpSymbolType.RightBracket || symbol.Type == CSharpSymbolType.RightParenthesis) { depth--; } result.Add(symbol); } }
/// <summary> /// This method is called to create a C# Symbol as a token /// </summary> /// <param name="start">Start position in the source document of the Token</param> /// <param name="content">the lexeme of the token</param> /// <param name="type">The Token's type</param> /// <param name="errors">Any encountered error</param> /// <returns>The Token's symbol</returns> protected override CSharpSymbol CreateSymbol(SourceLocation start, string content, CSharpSymbolType type, IEnumerable <RazorError> errors) { CSharpSymbol symbol = base.CreateSymbol(start, content, type, errors); return(symbol); }
public static SpanConstructor MetaCode(this SpanFactory self, string content, CSharpSymbolType type) { return(self.Span(SpanKindInternal.MetaCode, content, type)); }
public static SpanConstructor CodeTransition(this SpanFactory self, CSharpSymbolType type) { return(self .Span(SpanKindInternal.Transition, SyntaxConstants.TransitionString, type) .Accepts(AcceptedCharactersInternal.None)); }
public SpanConstructor Span(SpanKind kind, string content, CSharpSymbolType type) { return CreateSymbolSpan(kind, content, st => new CSharpSymbol(st, content, type)); }
public static SpanConstructor Comment(this SpanFactory self, string content, CSharpSymbolType type) { return self.Span(SpanKind.Comment, content, type); }