Ejemplo n.º 1
0
        XmlParserState SwitchToDirective(IXmlParserContext context, ref string rollback)
        {
            string key  = context.KeywordBuilder.ToString();
            string name = key.Trim();
            var    dir  = new RazorDirective(context.LocationMinus(key.Length + 2))
            {
                Name = name,
                IsSimpleDirective = RazorSymbols.IsSimpleDirective(name)
            };

            context.Nodes.Push(dir);
            rollback = String.Empty;
            return(EnsureSetAndAdopted <RazorDirectiveState> (ref directiveState));
        }
Ejemplo n.º 2
0
 public override XmlParserState ParseClosingBracket <T> (char c, IXmlParserContext context, XmlParserState stateToReturn)
 {
     if (base.ParseClosingBracket <T> (c, context, stateToReturn) != null)
     {
         if (RazorSymbols.CanBeContinued(CorrespondingBlock.Name))
         {
             keys             = RazorSymbols.PossibleKeywordsAfter(CorrespondingBlock.Name);
             context.StateTag = POSSIBLE_CONTINUATION;
         }
         else
         {
             return(stateToReturn);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
        public override XmlParserState PushChar(char c, IXmlParserContext context, ref string rollback)
        {
            string key;

            switch (context.StateTag)
            {
            case UNKNOWN:
                context.KeywordBuilder.Append(c);
                key = context.KeywordBuilder.ToString();
                if (!RazorSymbols.CanBeStatementOrDirective(key))
                {
                    context.Nodes.Push(new RazorImplicitExpression(context.LocationMinus(key.Length + 1)));
                    rollback = String.Empty;
                    return(EnsureSetAndAdopted <RazorExpressionState> (ref expressionState));
                }
                if (key == "using")
                {
                    context.StateTag = USING;
                }
                else if (RazorSymbols.IsDirective(key))
                {
                    context.StateTag = POSSIBLE_DIRECTIVE;
                }
                else if (RazorSymbols.IsStatement(key))
                {
                    context.StateTag = POSSIBLE_STATEMENT;
                }

                break;

            // Using can be either statement: @using (resource) {}, or directive: @using System.IO
            case USING:
                if (c == '(' || c == '\n')
                {
                    return(SwitchToStatement(context, ref rollback));
                }
                else if (Char.IsLetterOrDigit(c))
                {
                    return(SwitchToDirective(context, ref rollback));
                }

                context.KeywordBuilder.Append(c);
                break;

            case POSSIBLE_STATEMENT:
                if (Char.IsWhiteSpace(c) || c == '{' || c == '(')
                {
                    return(SwitchToStatement(context, ref rollback));
                }

                context.KeywordBuilder.Append(c);
                context.StateTag = UNKNOWN;
                break;

            case POSSIBLE_DIRECTIVE:
                if (Char.IsWhiteSpace(c) || c == '{')
                {
                    return(SwitchToDirective(context, ref rollback));
                }

                context.KeywordBuilder.Append(c);
                context.StateTag = UNKNOWN;
                break;
            }

            return(null);
        }