예제 #1
0
        public static string ExpectIdentifier(this ParserContext context, string unexpectedErrorMessageFormat, bool allowPrecedingWhiteSpace, SourceLocation?errorLocation)
        {
            using (context.StartTemporaryBuffer()) {
                if (allowPrecedingWhiteSpace)
                {
                    context.AcceptWhiteSpace(includeNewLines: true);
                }
                if (!ParserHelpers.IsIdentifierStart(context.CurrentCharacter))
                {
                    if (context.EndOfFile)
                    {
                        context.OnError(errorLocation ?? context.CurrentLocation, unexpectedErrorMessageFormat, RazorResources.ErrorComponent_EndOfFile);
                    }
                    else if (Char.IsWhiteSpace(context.CurrentCharacter))
                    {
                        context.OnError(errorLocation ?? context.CurrentLocation, unexpectedErrorMessageFormat, RazorResources.ErrorComponent_Whitespace);
                    }
                    else
                    {
                        context.OnError(errorLocation ?? context.CurrentLocation,
                                        unexpectedErrorMessageFormat,
                                        String.Format(CultureInfo.CurrentCulture,
                                                      RazorResources.ErrorComponent_Character,
                                                      context.CurrentCharacter));
                    }
                    return(null);
                }
                else
                {
                    context.AcceptTemporaryBuffer();
                }
            }

            return(context.AcceptIdentifier());
        }
예제 #2
0
 public static bool Accept(this ParserContext context, string expected, bool caseSensitive, out SourceLocation?errorLocation, out char?errorChar)
 {
     errorLocation = null;
     errorChar     = null;
     using (context.StartTemporaryBuffer()) {
         for (int i = 0; i < expected.Length; i++)
         {
             if (CharsEqual(expected[i], context.CurrentCharacter, caseSensitive))
             {
                 context.AcceptCurrent();
             }
             else
             {
                 errorLocation = context.CurrentLocation;
                 errorChar     = context.CurrentCharacter;
                 context.RejectTemporaryBuffer();
                 return(false);
             }
         }
         context.AcceptTemporaryBuffer();
     }
     return(true);
 }