Esempio n. 1
0
        public static void Parse(string[] Options)
        {
            try
            {
                string fileDir = GetFileDir(Options);

                Console.WriteLine("Parsing file to " + fileDir);

                bool Success;

                using (StreamReader S = new StreamReader(File.Open(Options[0], FileMode.Open)))
                {
                    CurrentParser = new RSSParser(S);
                    Success       = CurrentParser.Parse();
                }

                if (Success)
                {
                    CurrentParser.WriteToJSON(fileDir);
                    Console.WriteLine("Parsing Operation Finished Successfully.");
                }
            }
            catch (FileNotFoundException)
            {
                throw new ParserException($"Failed to find the file {Options[0]}");
            }
            catch (ArgumentException e)
            {
                throw new ParserException(e.Message);
            }
        }
Esempio n. 2
0
 public Scope(RSSParser Parser, StatmentType[] Accepted, Scope Parent, string Scope = "Generic")
 {
     this.Parser    = Parser;
     AcceptedValues = Accepted;
     Variables      = new Dictionary <string, string>();
     ID             = Scope;
     this.Parent    = Parent;
 }
Esempio n. 3
0
        private void CloseScope()
        {
            if (Scopes.Count == 0)
            {
                throw new ParserException("Attempted to end the global scope.");
            }

            Scope scope = Scopes.Pop();

            RSSParser.Finalise(scope);
        }
Esempio n. 4
0
 public StackScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string ScopeType) : base(Parser, ID, Parent, ScopeType)
 {
     Scopes = new Stack <Scope>();
 }
Esempio n. 5
0
 public ListScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string ScopeType = "Generic") : base(Parser, ID, Parent, ScopeType)
 {
 }
Esempio n. 6
0
 public StyleIdScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string[] ClassNames) : base(Parser, ID, Parent, "StyleId")
 {
 }
Esempio n. 7
0
 public StyleScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string Name) : base(Parser, ID, Parent, "Style")
 {
     StyleName = Name;
 }
Esempio n. 8
0
 public StyleScope(RSSParser Parser, StatmentType[] ID, Scope Parent) : base(Parser, ID, Parent, "Style")
 {
 }
Esempio n. 9
0
 public WidgetScope(RSSParser Parser, StatmentType[] ID, Scope Parent) : base(Parser, ID, Parent, "Widget")
 {
 }
Esempio n. 10
0
        private static void AddCallbacks()
        {
            PropertyCallbacks = new Dictionary <string, PropertyProcessCallback>();

            PropertyProcessCallback NumericalCallback = (str, scope) => {
                if (!IsNumeric(str))
                {
                    throw new ParserException("Property value must be numerical");
                }

                return(new string[] { str });
            };

            PropertyCallbacks.Add("int", NumericalCallback);
            PropertyCallbacks.Add("double", NumericalCallback);
            PropertyCallbacks.Add("float", NumericalCallback);

            PropertyCallbacks.Add("string", (str, scope) => {
                bool isString = (str.StartsWith("\"") && str.EndsWith("\""));

                if (!isString)
                {
                    throw new ParserException("Property value must be a string");
                }

                return(new string[] { str });
            });

            PropertyCallbacks.Add("bool", (str, scope) =>
            {
                bool isBool = (str == "true" || str == "false");

                if (!isBool)
                {
                    throw new ParserException("Property value must be a bool");
                }

                return(new string[] { str });
            });

            PropertyCallbacks.Add("UDim2", (str, scope) => {
                string[] vals = str.Split(',');

                ValidateStringArray(ref vals, scope, 4);

                return(vals);
            });

            PropertyCallbacks.Add("Color3", (str, scope) => {
                if (str.StartsWith("#"))
                {
                    try
                    {
                        Color col = ColorTranslator.FromHtml(str);

                        return(new string[] { col.R.ToString(), col.G.ToString(), col.B.ToString() });
                    }
                    catch (Exception)
                    {
                        throw new ParserException("Failed to convert to Color3");
                    }
                }
                else if (str.Contains("-"))
                {
                    if (!RobloxEnum.Enums["Color"].HasEnumItem(str))
                    {
                        throw new ParserException($"No inbuilt color {str}");
                    }

                    return(new string[] { JSONWriter.Quotify($"inbuilt-Color:{str}") });
                }
                else
                {
                    var vals = str.Split(',');

                    ValidateStringArray(ref vals, scope, 3);

                    return(vals);
                }
            });

            PropertyCallbacks.Add("Proportion", (str, scope) => {
                if (!(str.EndsWith("%") || str.EndsWith("px")))
                {
                    throw new ParserException("Failed to convert to proportion, must end in either a '%' sign or 'px'");
                }

                return(new string[] { JSONWriter.Quotify(str) });
            });

            PropertyCallbacks.Add("Style", (str, scope) => {
                RSSParser Current = RSSParser.CurrentParser;

                if (Current.Styles == null)
                {
                    throw new ParserException($"No Style called {str}");
                }

                foreach (var style in Current.Styles)
                {
                    if (style.styleName == str)
                    {
                        return new string[] { JSONWriter.Quotify(str) }
                    }
                }
                ;

                throw new ParserException($"No Style called {str}");
            });
        }