Exemple #1
0
        public static IFluidTemplate Parse(this FluidParser parser, string template)
        {
            var context = new FluidParseContext(template);

            var success = parser.Grammar.TryParse(context, out var statements, out var parlotError);

            if (parlotError != null)
            {
                // Extract line with error
                var start = parlotError.Position.Offset - 1;
                var end   = parlotError.Position.Offset;
                while (start > 0 && template[start] != '\n' && template[start] != '\r')
                {
                    start--;
                }
                while (end < template.Length && template[end] != '\n')
                {
                    end++;
                }
                var source = template.Substring(start, end - start).Trim('\n', '\r');

                throw new ParseException($"{parlotError.Message} at {parlotError.Position}\nSource:\n{source}");
            }

            if (!success)
            {
                return(null);
            }

            return(new FluidTemplate(statements));
        }
Exemple #2
0
        public static IFluidTemplate Parse(this FluidParser parser, string template)
        {
            var context = new FluidParseContext(template);

            var success = parser.Grammar.TryParse(context, out var statements, out var parlotError);

            if (parlotError != null)
            {
                throw new ParseException($"{parlotError.Message} at {parlotError.Position}");
            }

            if (!success)
            {
                return(null);
            }

            return(new FluidTemplate(statements));
        }
Exemple #3
0
        /// <summary>
        /// Creates a new game connection
        /// </summary>
        /// <param name="auth">The authentication</param>
        public FluidClient(IAuth auth)
        {
            m_Log = new FluidLog();

            if (auth == null)
            {
                auth = new GuestAuth();
                m_Log.Add(FluidLogCategory.Suggestion, "Auto-Logged in as guest, for clarity specify your authentication instead of passing in null.");
            }

            Auth            = auth;
            ConnectionValue = new ConnectionValue();

            m_Config   = new Config();
            m_Parser   = new FluidParser();
            m_Toolbelt = new FluidToolbelt();
            m_ShopInfo = new FluidShopInfo();
        }
Exemple #4
0
 public static bool TryParse(this FluidParser parser, string template, out IFluidTemplate result, out string error)
 {
     try
     {
         error  = null;
         result = parser.Parse(template);
         return(true);
     }
     catch (ParseException e)
     {
         error  = e.Message;
         result = null;
         return(false);
     }
     catch (Exception e)
     {
         error  = e.Message;
         result = null;
         return(false);
     }
 }
Exemple #5
0
 public static bool TryParse(this FluidParser parser, string template, out IFluidTemplate result)
 {
     return(parser.TryParse(template, out result, out _));
 }