public void ParseBlockReadsToAfterOffKeywordIfOptionExplicitBlock()
 {
     ParseBlockTest("Option Explicit Off Foo Bar Baz",
                    new DirectiveBlock(
                        Factory.MetaCode("Option Explicit Off")
                        .With(SetVBOptionCodeGenerator.Explicit(false))));
 }
 public void ParseBlockReadsToAfterOnKeywordIfOptionStrictBlock()
 {
     ParseBlockTest("Option Strict On Foo Bar Baz",
                    new DirectiveBlock(
                        Factory.MetaCode("Option Strict On")
                        .With(SetVBOptionCodeGenerator.Strict(true))));
 }
Beispiel #3
0
 public void VB_Option_Explicit_Statement()
 {
     ParseBlockTest(@"@Option Explicit Off",
                    new DirectiveBlock(
                        Factory.CodeTransition(),
                        Factory.MetaCode("Option Explicit Off")
                        .With(SetVBOptionCodeGenerator.Explicit(false))));
 }
 public void ParseBlockThrowsErrorIfOptionStrictIsNotFollowedByOnOrOff()
 {
     ParseBlockTest("Option Strict Yes",
                    new DirectiveBlock(
                        Factory.MetaCode("Option Strict Yes")
                        .With(SetVBOptionCodeGenerator.Strict(true))),
                    new RazorError(
                        String.Format(
                            RazorResources.ParseError_InvalidOptionValue,
                            "Strict", "Yes"),
                        14, 0, 14));
 }
Beispiel #5
0
        protected virtual bool OptionStatement()
        {
            try
            {
                Context.CurrentBlock.Type = BlockType.Directive;

                Assert(VBKeyword.Option);
                AcceptAndMoveNext();
                AcceptWhile(VBSymbolType.WhiteSpace);
                if (!At(VBSymbolType.Identifier))
                {
                    if (CurrentSymbol != null)
                    {
                        Context.OnError(CurrentLocation, String.Format(CultureInfo.CurrentCulture,
                                                                       RazorResources.ParseError_Unexpected,
                                                                       CurrentSymbol.Content));
                    }
                    return(false);
                }
                SourceLocation optionLoc = CurrentLocation;
                string         option    = CurrentSymbol.Content;
                AcceptAndMoveNext();

                AcceptWhile(VBSymbolType.WhiteSpace);
                bool boolVal;
                if (At(VBKeyword.On))
                {
                    AcceptAndMoveNext();
                    boolVal = true;
                }
                else if (At(VBSymbolType.Identifier))
                {
                    if (String.Equals(CurrentSymbol.Content, SyntaxConstants.VB.OffKeyword, StringComparison.OrdinalIgnoreCase))
                    {
                        AcceptAndMoveNext();
                        boolVal = false;
                    }
                    else
                    {
                        Context.OnError(CurrentLocation, String.Format(CultureInfo.CurrentCulture,
                                                                       RazorResources.ParseError_InvalidOptionValue,
                                                                       option,
                                                                       CurrentSymbol.Content));
                        AcceptAndMoveNext();
                        return(false);
                    }
                }
                else
                {
                    if (!EndOfFile)
                    {
                        Context.OnError(CurrentLocation, String.Format(CultureInfo.CurrentCulture,
                                                                       RazorResources.ParseError_Unexpected,
                                                                       CurrentSymbol.Content));
                        AcceptAndMoveNext();
                    }
                    return(false);
                }

                if (String.Equals(option, SyntaxConstants.VB.StrictKeyword, StringComparison.OrdinalIgnoreCase))
                {
                    Span.CodeGenerator = SetVBOptionCodeGenerator.Strict(boolVal);
                }
                else if (String.Equals(option, SyntaxConstants.VB.ExplicitKeyword, StringComparison.OrdinalIgnoreCase))
                {
                    Span.CodeGenerator = SetVBOptionCodeGenerator.Explicit(boolVal);
                }
                else
                {
                    Span.CodeGenerator = new SetVBOptionCodeGenerator(option, boolVal);
                    Context.OnError(optionLoc, RazorResources.ParseError_UnknownOption, option);
                }
            }
            finally
            {
                if (Span.Symbols.Count > 0)
                {
                    Output(SpanKind.MetaCode);
                }
            }
            return(true);
        }