コード例 #1
0
ファイル: RSSParser.cs プロジェクト: DrunkerScripter/RSS
        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);
            }
        }
コード例 #2
0
ファイル: Scope.cs プロジェクト: DrunkerScripter/RSS
 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;
 }
コード例 #3
0
ファイル: Scope.cs プロジェクト: DrunkerScripter/RSS
        private void CloseScope()
        {
            if (Scopes.Count == 0)
            {
                throw new ParserException("Attempted to end the global scope.");
            }

            Scope scope = Scopes.Pop();

            RSSParser.Finalise(scope);
        }
コード例 #4
0
ファイル: Scope.cs プロジェクト: DrunkerScripter/RSS
 public StackScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string ScopeType) : base(Parser, ID, Parent, ScopeType)
 {
     Scopes = new Stack <Scope>();
 }
コード例 #5
0
ファイル: Scope.cs プロジェクト: DrunkerScripter/RSS
 public ListScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string ScopeType = "Generic") : base(Parser, ID, Parent, ScopeType)
 {
 }
コード例 #6
0
ファイル: Scope.cs プロジェクト: DrunkerScripter/RSS
 public StyleIdScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string[] ClassNames) : base(Parser, ID, Parent, "StyleId")
 {
 }
コード例 #7
0
ファイル: Scope.cs プロジェクト: DrunkerScripter/RSS
 public StyleScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string Name) : base(Parser, ID, Parent, "Style")
 {
     StyleName = Name;
 }
コード例 #8
0
ファイル: Scope.cs プロジェクト: DrunkerScripter/RSS
 public StyleScope(RSSParser Parser, StatmentType[] ID, Scope Parent) : base(Parser, ID, Parent, "Style")
 {
 }
コード例 #9
0
ファイル: Scope.cs プロジェクト: DrunkerScripter/RSS
 public WidgetScope(RSSParser Parser, StatmentType[] ID, Scope Parent) : base(Parser, ID, Parent, "Widget")
 {
 }
コード例 #10
0
ファイル: PropertyParser.cs プロジェクト: DrunkerScripter/RSS
        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}");
            });
        }