Example #1
0
		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);
			}
		}
Example #2
0
 public static SpanConstructor CodeTransition(
     this SpanFactory self,
     string content,
     CSharpSymbolType type
     )
 {
     return(self.Span(SpanKind.Transition, content, type).Accepts(AcceptedCharacters.None));
 }
Example #3
0
 public static SpanConstructor Comment(
     this SpanFactory self,
     string content,
     CSharpSymbolType type
     )
 {
     return(self.Span(SpanKind.Comment, content, type));
 }
Example #4
0
 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);
 }
Example #5
0
        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;
            }
        }
Example #6
0
        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);
            }
        }
Example #7
0
 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);
 }
Example #11
0
 internal void TestSingleToken(string text, CSharpSymbolType expectedSymbolType)
 {
     TestTokenizer(text, new CSharpSymbol(text, expectedSymbolType));
 }
Example #12
0
        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);
        }
Example #14
0
 public static SpanConstructor MetaCode(this SpanFactory self, string content, CSharpSymbolType type)
 {
     return(self.Span(SpanKindInternal.MetaCode, content, type));
 }
Example #15
0
 public static SpanConstructor CodeTransition(this SpanFactory self, CSharpSymbolType type)
 {
     return(self
            .Span(SpanKindInternal.Transition, SyntaxConstants.TransitionString, type)
            .Accepts(AcceptedCharactersInternal.None));
 }
Example #16
0
 public SpanConstructor Span(SpanKind kind, string content, CSharpSymbolType type)
 {
     return CreateSymbolSpan(kind, content, st => new CSharpSymbol(st, content, type));
 }
 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;
     }
 }
 public static SpanConstructor Comment(this SpanFactory self, string content, CSharpSymbolType type)
 {
     return self.Span(SpanKind.Comment, content, type);
 }