Example #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());
        }
Example #2
0
        public static bool Expect(this ParserContext context, string expected, bool outputError, string errorMessage, bool caseSensitive, SourceLocation?errorLocation)
        {
            SourceLocation?errLoc;
            char?          errorChar;

            if (!Accept(context, expected, caseSensitive, out errLoc, out errorChar))
            {
                if (outputError)
                {
                    context.OnError(errorLocation ?? errLoc ?? context.CurrentLocation, errorMessage ?? RazorResources.ParseError_Expected_X, expected);
                }
                return(false);
            }
            return(true);
        }