コード例 #1
0
        protected bool TryRecover(RecoveryModes mode,
                                  Predicate <char> condition,
                                  bool allowTransition,
                                  SpanFactory previousSpanFactory)
        {
            bool anyNewLines = false;

            while (!EndOfFile && !condition(CurrentCharacter))
            {
                // Eat whitespace
                Context.AcceptWhiteSpace(false);

                if (mode.HasFlag(RecoveryModes.Markup))
                {
                    // If we see new lines before a '<' then assume it's markup.
                    // This isn't 100% correct but it is the 80/90% case when typing razor code
                    if (anyNewLines && Context.MarkupParser.IsStartTag())
                    {
                        return(true);
                    }

                    // End tags are mostly unambiguous
                    // REVIEW: Does this make sense?
                    if (Context.MarkupParser.IsEndTag())
                    {
                        return(true);
                    }
                }

                if (mode.HasFlag(RecoveryModes.Code))
                {
                    if (TryRecover(allowTransition, previousSpanFactory))
                    {
                        return(true);
                    }
                }

                if (mode.HasFlag(RecoveryModes.Transition))
                {
                    if (CurrentCharacter == RazorParser.TransitionCharacter)
                    {
                        return(true);
                    }
                }

                anyNewLines = ParserHelpers.IsNewLine(CurrentCharacter);

                Context.AcceptCurrent();
            }
            return(false);
        }
コード例 #2
0
        protected bool TryRecover(RecoveryModes mode,
                                  Predicate<char> condition,
                                  bool allowTransition,
                                  SpanFactory previousSpanFactory) {
            bool anyNewLines = false;
            while (!EndOfFile && !condition(CurrentCharacter)) {
                // Eat whitespace
                Context.AcceptWhiteSpace(false);

                if (mode.HasFlag(RecoveryModes.Markup)) {
                    // If we see new lines before a '<' then assume it's markup. 
                    // This isn't 100% correct but it is the 80/90% case when typing razor code
                    if (anyNewLines && Context.MarkupParser.IsStartTag()) {
                        return true;
                    }

                    // End tags are mostly unambiguous
                    // REVIEW: Does this make sense?
                    if (Context.MarkupParser.IsEndTag()) {
                        return true;
                    }
                }

                if (mode.HasFlag(RecoveryModes.Code)) {
                    if (TryRecover(allowTransition, previousSpanFactory)) {
                        return true;
                    }
                }

                if (mode.HasFlag(RecoveryModes.Transition)) {
                    if (CurrentCharacter == RazorParser.TransitionCharacter) {
                        return true;
                    }
                }

                anyNewLines = ParserHelpers.IsNewLine(CurrentCharacter);

                Context.AcceptCurrent();
            }
            return false;
        }
コード例 #3
0
 protected bool TryRecover(RecoveryModes mode) {
     return TryRecover(mode, ch => false, allowTransition: false, previousSpanFactory: null);
 }
コード例 #4
0
 protected bool TryRecover(RecoveryModes mode)
 {
     return(TryRecover(mode, ch => false, allowTransition: false, previousSpanFactory: null));
 }