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); } }
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; }
private void CloseScope() { if (Scopes.Count == 0) { throw new ParserException("Attempted to end the global scope."); } Scope scope = Scopes.Pop(); RSSParser.Finalise(scope); }
public StackScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string ScopeType) : base(Parser, ID, Parent, ScopeType) { Scopes = new Stack <Scope>(); }
public ListScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string ScopeType = "Generic") : base(Parser, ID, Parent, ScopeType) { }
public StyleIdScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string[] ClassNames) : base(Parser, ID, Parent, "StyleId") { }
public StyleScope(RSSParser Parser, StatmentType[] ID, Scope Parent, string Name) : base(Parser, ID, Parent, "Style") { StyleName = Name; }
public StyleScope(RSSParser Parser, StatmentType[] ID, Scope Parent) : base(Parser, ID, Parent, "Style") { }
public WidgetScope(RSSParser Parser, StatmentType[] ID, Scope Parent) : base(Parser, ID, Parent, "Widget") { }
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}"); }); }