Exemple #1
0
        public static void ProcessError(string source, out string detail, out ParserError error)
        {
            if (errors.TryGetValue(source, out error))
            {
                detail = ParserErrors.ResourceManager.GetString(error.ToString());
            }
            else
            {
                var twoParts = source.Split(new char[] { '\u0020' }, StringSplitOptions.RemoveEmptyEntries);

                if (twoParts.Length != 2)
                {
                    error  = Undefined;
                    detail = ParserErrors.Undefined;
                    return;
                }

                var token = twoParts[0].Trim('\"');

                if (tokens.TryGetValue(token, out var nt))
                {
                    token = nt;
                }
                else if (token == "invalid")
                {
                    error  = InvalidSyntax;
                    detail = string.Format(ParserErrors.InvalidSyntax, source);
                    return;
                }

                if (!token.All(c => char.IsLetter(c)))
                {
                    token = "\"" + token + "\"";
                }

                error  = TokenExpected;
                detail = string.Format(ParserErrors.TokenExpected, token);
            }
        }