Пример #1
0
 public void UnterminatedRazorCommentInImplicitExpressionMethodCall()
 {
     ParseDocumentTest("@foo(@*",
                       new MarkupBlock(
                           Factory.EmptyHtml(),
                           new ExpressionBlock(
                               Factory.CodeTransition(),
                               Factory.Code("foo(")
                               .AsImplicitExpression(CSharpCodeParser.DefaultKeywords),
                               new CommentBlock(
                                   Factory.CodeTransition(CSharpSymbolType.RazorCommentTransition)
                                   .Accepts(AcceptedCharactersInternal.None),
                                   Factory.MetaCode("*", CSharpSymbolType.RazorCommentStar)
                                   .Accepts(AcceptedCharactersInternal.None),
                                   Factory.Span(SpanKindInternal.Comment, new CSharpSymbol(
                                                    string.Empty,
                                                    CSharpSymbolType.Unknown))
                                   .Accepts(AcceptedCharactersInternal.Any)))),
                       new RazorError(
                           LegacyResources.ParseError_RazorComment_Not_Terminated,
                           new SourceLocation(5, 0, 5),
                           length: 2),
                       new RazorError(
                           LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"),
                           new SourceLocation(4, 0, 4),
                           length: 1));
 }
Пример #2
0
 public void ParseBlockStopsBalancingParenthesesAtEOF()
 {
     ImplicitExpressionTest(
         "foo(()", "foo(()",
         acceptedCharacters: AcceptedCharactersInternal.Any,
         errors: new RazorError(
             LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"),
             new SourceLocation(4, 0, 4),
             length: 1));
 }
Пример #3
0
 public void ParseBlockTerminatesUsingBlockAtEOLWhenRecoveringFromMissingCloseParen()
 {
     ParseBlockTest("using(foo bar" + Environment.NewLine
                    + "baz",
                    new StatementBlock(
                        Factory.Code("using(foo bar" + Environment.NewLine).AsStatement()
                        ),
                    new RazorError(
                        LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"),
                        new SourceLocation(5, 0, 5),
                        length: 1));
 }
Пример #4
0
 public void ParseBlockCorrectlyHandlesInCorrectTransitionsIfImplicitExpressionParensUnclosed()
 {
     ParseBlockTest("Href(" + Environment.NewLine
                    + "<h1>@Html.Foo(Bar);</h1>" + Environment.NewLine,
                    new ExpressionBlock(
                        Factory.Code("Href(" + Environment.NewLine)
                        .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                        ),
                    new RazorError(
                        LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"),
                        new SourceLocation(4, 0, 4),
                        length: 1));
 }
Пример #5
0
 // Test for fix to Dev10 884975 - Incorrect Error Messaging
 public void ParseBlockShouldReportErrorAndTerminateAtEOFIfBracketInImplicitExpressionUnclosed()
 {
     ParseBlockTest("Foo[Bar[Baz]" + Environment.NewLine
                    + "Biz" + Environment.NewLine
                    + "Boz",
                    new ExpressionBlock(
                        Factory.Code($"Foo[Bar[Baz]{Environment.NewLine}Biz{Environment.NewLine}Boz")
                        .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                        ),
                    new RazorError(
                        LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF("[", "]"),
                        new SourceLocation(3, 0, 3),
                        length: 1));
 }
Пример #6
0
 // Test for fix to Dev10 884975 - Incorrect Error Messaging
 public void ParseBlockShouldReportErrorAndTerminateAtMarkupIfParenInImplicitExpressionUnclosed()
 {
     ParseBlockTest("Foo(Bar(Baz)" + Environment.NewLine
                    + "Biz" + Environment.NewLine
                    + "<html>" + Environment.NewLine
                    + "Boz" + Environment.NewLine
                    + "</html>",
                    new ExpressionBlock(
                        Factory.Code($"Foo(Bar(Baz){Environment.NewLine}Biz{Environment.NewLine}")
                        .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                        ),
                    new RazorError(
                        LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"),
                        new SourceLocation(3, 0, 3),
                        length: 1));
 }
Пример #7
0
 public void ParseBlockResumesIfStatementAfterOpenParen()
 {
     ParseBlockTest("if(" + Environment.NewLine
                    + "else { <p>Foo</p> }",
                    new StatementBlock(
                        Factory.Code($"if({Environment.NewLine}else {{").AsStatement(),
                        new MarkupBlock(
                            Factory.Markup(" "),
                            BlockFactory.MarkupTagBlock("<p>", AcceptedCharactersInternal.None),
                            Factory.Markup("Foo"),
                            BlockFactory.MarkupTagBlock("</p>", AcceptedCharactersInternal.None),
                            Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None)),
                        Factory.Code("}").AsStatement().Accepts(AcceptedCharactersInternal.None)
                        ),
                    new RazorError(
                        LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"),
                        new SourceLocation(2, 0, 2),
                        length: 1));
 }
        protected internal bool Balance(BalancingModes mode)
        {
            var left  = CurrentSymbol.Type;
            var right = Language.FlipBracket(left);
            var start = CurrentStart;

            AcceptAndMoveNext();
            if (EndOfFile && ((mode & BalancingModes.NoErrorOnFailure) != BalancingModes.NoErrorOnFailure))
            {
                Context.ErrorSink.OnError(
                    start,
                    LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF(
                        Language.GetSample(left),
                        Language.GetSample(right)),
                    length: 1 /* { OR } */);
            }

            return(Balance(mode, left, right, start));
        }
Пример #9
0
 public void ParseBlockCorrectlyRecoversFromMissingCloseParenInExpressionWithinCode()
 {
     ParseBlockTest(@"{string.Format(<html></html>}",
                    new StatementBlock(
                        Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                        Factory.Code("string.Format(")
                        .AsStatement()
                        .AutoCompleteWith(autoCompleteString: null),
                        new MarkupBlock(
                            BlockFactory.MarkupTagBlock("<html>", AcceptedCharactersInternal.None),
                            BlockFactory.MarkupTagBlock("</html>", AcceptedCharactersInternal.None)),
                        Factory.EmptyCSharp().AsStatement(),
                        Factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
                    expectedErrors: new[]
     {
         new RazorError(
             LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"),
             new SourceLocation(14, 0, 14),
             length: 1)
     });
 }
        protected internal bool Balance(BalancingModes mode, TSymbolType left, TSymbolType right, SourceLocation start)
        {
            var startPosition = CurrentStart.AbsoluteIndex;
            var nesting       = 1;

            if (!EndOfFile)
            {
                var syms = new List <TSymbol>();
                do
                {
                    if (IsAtEmbeddedTransition(
                            (mode & BalancingModes.AllowCommentsAndTemplates) == BalancingModes.AllowCommentsAndTemplates,
                            (mode & BalancingModes.AllowEmbeddedTransitions) == BalancingModes.AllowEmbeddedTransitions))
                    {
                        Accept(syms);
                        syms.Clear();
                        HandleEmbeddedTransition();

                        // Reset backtracking since we've already outputted some spans.
                        startPosition = CurrentStart.AbsoluteIndex;
                    }
                    if (At(left))
                    {
                        nesting++;
                    }
                    else if (At(right))
                    {
                        nesting--;
                    }
                    if (nesting > 0)
                    {
                        syms.Add(CurrentSymbol);
                    }
                }while (nesting > 0 && NextToken());

                if (nesting > 0)
                {
                    if ((mode & BalancingModes.NoErrorOnFailure) != BalancingModes.NoErrorOnFailure)
                    {
                        Context.ErrorSink.OnError(
                            start,
                            LegacyResources.FormatParseError_Expected_CloseBracket_Before_EOF(
                                Language.GetSample(left),
                                Language.GetSample(right)),
                            length: 1 /* { OR } */);
                    }
                    if ((mode & BalancingModes.BacktrackOnFailure) == BalancingModes.BacktrackOnFailure)
                    {
                        Context.Source.Position = startPosition;
                        NextToken();
                    }
                    else
                    {
                        Accept(syms);
                    }
                }
                else
                {
                    // Accept all the symbols we saw
                    Accept(syms);
                }
            }
            return(nesting == 0);
        }