private IComponentIndex ParseComponentIndex(IDeclarationSource nameSource, IParsingSourceStream sourceStream, List <ComponentInfo> infoList) { IComponentProperty IndexProperty = null; foreach (ComponentInfo Info in infoList) { if (Info.NameSource.Name == "index" && IndexProperty == null) { IndexProperty = new ComponentProperty(Info); } else if (Info.NameSource.Name != "index") { throw new ParsingException(27, sourceStream, $"Unknown token '{Info.NameSource.Name}'."); } else { throw new ParsingException(28, sourceStream, $"'{Info.NameSource.Name}' is repeated."); } } if (IndexProperty == null) { throw new ParsingException(64, sourceStream, "Index not specified."); } if (IndexProperty.FixedValueSource != null || IndexProperty.ObjectPropertyKey != null) { throw new ParsingException(65, sourceStream, "Index must be an integer, state or boolean property."); } return(new ComponentIndex(nameSource, ParserDomain.ToXamlName(nameSource.Source, nameSource.Name, "Index"), IndexProperty)); }
private IComponentHtml ParseComponentHtml(IDeclarationSource nameSource, IParsingSourceStream sourceStream, List <ComponentInfo> infoList) { IComponentProperty HtmlProperty = null; foreach (ComponentInfo Info in infoList) { if (Info.NameSource.Name == "html" && HtmlProperty == null) { HtmlProperty = new ComponentProperty(Info); } else if (Info.NameSource.Name != "html") { throw new ParsingException(27, sourceStream, $"Unknown token '{Info.NameSource.Name}'."); } else { throw new ParsingException(28, sourceStream, $"'{Info.NameSource.Name}' is repeated."); } } if (HtmlProperty == null) { throw new ParsingException(0, sourceStream, "Html not specified."); } return(new ComponentHtml(nameSource, ParserDomain.ToXamlName(nameSource.Source, nameSource.Name, "Html"), HtmlProperty)); }
private Dictionary <IDeclarationSource, string> ParseColors(IParsingSourceStream sourceStream) { Dictionary <IDeclarationSource, string> Colors = new Dictionary <IDeclarationSource, string>(); while (!sourceStream.EndOfStream) { sourceStream.ReadLine(); IDeclarationSource ColorSource; string ColorValue; ParserDomain.ParseStringPair(sourceStream, ':', out ColorSource, out ColorValue); foreach (KeyValuePair <IDeclarationSource, string> Entry in Colors) { if (Entry.Key.Name == ColorSource.Name) { throw new ParsingException(81, sourceStream, $"Color '{ColorSource.Name}' defined more than once."); } } Colors.Add(ColorSource, ColorValue); } return(Colors); }
private IComponentArea ParseComponentArea(IDeclarationSource nameSource, IParsingSourceStream sourceStream, List <ComponentInfo> infoList) { IComponentProperty AreaProperty = null; foreach (ComponentInfo Info in infoList) { if (Info.NameSource.Name == "name" && AreaProperty == null) { AreaProperty = new ComponentProperty(Info); } else if (Info.NameSource.Name != "name") { throw new ParsingException(27, sourceStream, $"Unknown token '{Info.NameSource.Name}'."); } else { throw new ParsingException(28, sourceStream, $"'{Info.NameSource.Name}' is repeated."); } } if (AreaProperty == null) { throw new ParsingException(29, sourceStream, "Area name not specified."); } if (AreaProperty.FixedValueSource == null) { throw new ParsingException(30, sourceStream, "Area can only be a static name."); } return(new ComponentArea(nameSource, ParserDomain.ToXamlName(nameSource.Source, nameSource.Name, "Area"), AreaProperty.FixedValueSource)); }
public override IUnitTest Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable) { IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable); try { using (SourceStream.Open()) { if (SourceStream.IsEmpty) { return(null); } return(Parse(fileName, SourceStream)); } } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException(231, SourceStream, e); } }
public override ILayout Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable) { IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable); try { XamlSchemaContext Context = GetContext(); using (SourceStream.OpenXamlFromFile(Context)) { if (SourceStream.IsEmpty) { return(null); } return(Parse(fileName, SourceStream)); } } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException(93, SourceStream, e); } }
public object LoadXaml() { CurrentSource = this; object Result; try { Result = System.Windows.Markup.XamlReader.Load(xr); } catch (ParsingException) { throw; } catch (Exception e) { if (e.InnerException is ParsingException AsParsingException) { throw AsParsingException; } else { throw new ParsingException(23, this, e); } } CurrentSource = null; return(Result); }
private void AddDictionaryContent(IParsingSourceStream sourceStream, ResourceDictionary wrapped, Windows.UI.Xaml.ResourceDictionary dictionary, List <string> FileNames) { foreach (object Key in dictionary.Keys) { if (!wrapped.Contains(Key)) { wrapped.Add(Key, dictionary[Key]); } else { throw new ParsingException(92, sourceStream, $"Key '{Key}' found multiple times."); } } foreach (Windows.UI.Xaml.ResourceDictionary Item in dictionary.MergedDictionaries) { if (Item.Source != null) { IParsingSourceStream NestedSourceStream = ParsingSourceStream.CreateFromFileName(Item.Source.AbsolutePath, sourceStream.ConditionalDefineTable); ResourceDictionary NestedContent; List <string> NestedFileNames; LoadResourceFile(NestedSourceStream, out NestedContent, out NestedFileNames); AddDictionaryContent(NestedSourceStream, wrapped, NestedContent); FileNames.AddRange(NestedFileNames); } } }
private XamlSchemaContext GetContext(IParsingSourceStream sourceStream) { List <Assembly> ReferencedAssemblies = new List <Assembly>(); try { AssemblyName[] ReferencedAssemblyNames = Assembly.GetExecutingAssembly().GetReferencedAssemblies(); for (int i = 0; i < ReferencedAssemblyNames.Length; i++) { AssemblyName ReferencedAssemblyName = ReferencedAssemblyNames[i]; if (ReferencedAssemblyName.Name == "mscorlib" || ReferencedAssemblyName.Name == "XmlnsTest") { ReferencedAssemblies.Add(Assembly.Load(ReferencedAssemblyName)); } } } catch (Exception e) { throw new ParsingException(91, sourceStream, e); } XamlSchemaContext Result = new XamlSchemaContext(ReferencedAssemblies); return(Result); }
private IObjectPropertyCollection ParseObjectProperties(IParsingSourceStream sourceStream, ref string line) { IObjectPropertyCollection ObjectPropertyList = new ObjectPropertyCollection(); string HeaderLine = sourceStream.Line; if (HeaderLine != "properties") { throw new ParsingException(95, sourceStream, "'properties' expected."); } while (!sourceStream.EndOfStream) { sourceStream.ReadLine(); if (string.IsNullOrEmpty(sourceStream.Line)) { break; } IObjectProperty NewProperty = ParseProperty(sourceStream); foreach (IObjectProperty ObjectProperty in ObjectPropertyList) { if (ObjectProperty.NameSource.Name == NewProperty.NameSource.Name) { throw new ParsingException(96, sourceStream, $"Object already contains a property called '{NewProperty.NameSource.Name}'."); } } ObjectPropertyList.Add(NewProperty); } return(ObjectPropertyList); }
private void LoadResourceFile(IParsingSourceStream sourceStream, out ResourceDictionary content, out List <string> fileNames) { try { string FolderName = Path.GetDirectoryName(sourceStream.FileName); FolderName = FolderName.Replace("\\", "/"); using (sourceStream.Open()) { string ContentString = sourceStream.ReadToEnd(); ContentString = ContentString.Replace("Source=\"/", $"Source=\"{FolderName}/"); XamlSchemaContext Context = GetContext(sourceStream); using (sourceStream.OpenXamlFromString(ContentString, Context)) { fileNames = new List <string>(); fileNames.Add(sourceStream.FileName); content = LoadResourceFile(sourceStream, fileNames); } } } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException(90, sourceStream, e); } }
public override IPage Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable) { string Name = Path.GetFileNameWithoutExtension(fileName); IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable); try { using (SourceStream.Open()) { if (SourceStream.IsEmpty) { return(null); } return(Parse(Name, SourceStream)); } } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException(108, SourceStream, e); } }
public static bool TryParseObjectProperty(IParsingSourceStream sourceStream, string text, out IDeclarationSource objectSource, out IDeclarationSource memberSource, out IDeclarationSource keySource) { if (!text.Contains(".")) { objectSource = null; memberSource = null; keySource = null; return(false); } else { string MemberName; ParseStringPair(sourceStream, text, '.', out objectSource, out MemberName); string Key; int StartIndex = MemberName.IndexOf("["); int EndIndex = MemberName.IndexOf("]"); if (StartIndex > 0 && EndIndex > StartIndex) { Key = MemberName.Substring(StartIndex + 1, EndIndex - StartIndex - 1); MemberName = MemberName.Substring(0, StartIndex); keySource = new DeclarationSource(Key, sourceStream); } else { keySource = null; } memberSource = new DeclarationSource(MemberName, sourceStream); return(true); } }
public static void ParseStringPair(IParsingSourceStream sourceStream, string line, char separator, out IDeclarationSource nameSource, out string value) { if (string.IsNullOrEmpty(line)) { throw new ParsingException(19, sourceStream, "Unexpected empty line."); } string[] Splitted = line.Split(separator); if (Splitted.Length < 2) { throw new ParsingException(20, sourceStream, $"<key>{separator}<value> expected."); } string Name = Splitted[0].Trim(); if (string.IsNullOrEmpty(Name)) { throw new ParsingException(21, sourceStream, $"<key>{separator}<value> expected, found empty key."); } string Value = Splitted[1]; for (int i = 2; i < Splitted.Length; i++) { Value = $"{Value}{separator}{Splitted[i]}"; } value = Value.Trim(); if (string.IsNullOrEmpty(value)) { throw new ParsingException(22, sourceStream, $"<key>{separator}<value> expected, found empty value."); } nameSource = new DeclarationSource(Name, sourceStream); }
public void Process(IDictionary <ConditionalDefine, bool> conditionalDefineTable) { PreprocessorDefineTable = new Dictionary <string, bool>(); IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(PreprocessorDefineFile, conditionalDefineTable); int LineNumber = 0; using (SourceStream.Open()) { while (!SourceStream.EndOfStream) { SourceStream.ReadLine(); string Line = SourceStream.Line; string[] Splitted = Line.Split('='); if (Splitted.Length != 2) { throw new ParsingException(0, SourceStream, $"Inconsistent format at line {LineNumber + 1}."); } else { string Define = Splitted[0].Trim(); if (!IsDefineValid(Define)) { throw new ParsingException(0, SourceStream, $"Invalid define '{Define}' at line {LineNumber + 1}."); } if (PreprocessorDefineTable.ContainsKey(Define)) { throw new ParsingException(0, SourceStream, $"'{Define}' at line {LineNumber + 1} already exist."); } string Value = Splitted[1].Trim(); int ValueAsInt; bool ValueAsBool; if (int.TryParse(Value, out ValueAsInt) && (ValueAsInt == 0 || ValueAsInt == 1)) { ValueAsBool = (ValueAsInt == 1); } else if (bool.TryParse(Value, out ValueAsBool)) { } else { throw new ParsingException(0, SourceStream, $"Invalid define value '{Value}' at line {LineNumber + 1}."); } PreprocessorDefineTable.Add(Define, ValueAsBool); } LineNumber++; } } }
private IPage Parse(string name, IParsingSourceStream sourceStream) { IComponentEvent QueryEvent = null; IDeclarationSource AreaSource = null; IParsingSource AllAreaLayoutsSource = null; Dictionary <IDeclarationSource, string> AreaLayoutsPairs = null; IDeclarationSource DesignSource = null; IDeclarationSource WidthSource = null; IDeclarationSource HeightSource = null; bool IsScrollable = false; IDeclarationSource BackgroundSource = null; IDeclarationSource BackgroundColorSource = null; string Tag = null; while (!sourceStream.EndOfStream) { sourceStream.ReadLine(); string Line = sourceStream.Line; if (!string.IsNullOrWhiteSpace(Line)) { ParseComponent(sourceStream, ref QueryEvent, ref AreaSource, ref AllAreaLayoutsSource, ref AreaLayoutsPairs, ref DesignSource, ref WidthSource, ref HeightSource, ref IsScrollable, ref BackgroundSource, ref BackgroundColorSource, ref Tag); } } if (AreaSource == null || string.IsNullOrEmpty(AreaSource.Name)) { throw new ParsingException(109, sourceStream, "Missing area name."); } if (AreaLayoutsPairs == null) { throw new ParsingException(110, sourceStream, "Missing default area layout."); } if (DesignSource == null || string.IsNullOrEmpty(DesignSource.Name)) { throw new ParsingException(111, sourceStream, "Missing design name."); } if (WidthSource == null || string.IsNullOrEmpty(WidthSource.Name)) { throw new ParsingException(112, sourceStream, "Missing width."); } if (HeightSource == null || string.IsNullOrEmpty(HeightSource.Name)) { throw new ParsingException(113, sourceStream, "Missing height."); } if (BackgroundColorSource == null || string.IsNullOrEmpty(BackgroundColorSource.Name)) { throw new ParsingException(114, sourceStream, "Missing background color."); } return(new Page(name, ParserDomain.ToCSharpName(sourceStream, name + "Page"), ParserDomain.ToXamlName(sourceStream, name, "Page"), QueryEvent, AreaSource, AllAreaLayoutsSource, AreaLayoutsPairs, DesignSource, WidthSource, HeightSource, IsScrollable, BackgroundSource, BackgroundColorSource, Tag)); }
public override IBackground Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable) { string Name = Path.GetFileNameWithoutExtension(fileName); IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable); List <string> Lines; LoadResourceFile(SourceStream, out Lines); return(new Background(Name, ParserDomain.ToXamlName(SourceStream, Name, "Background"), Lines)); }
private IObjectEvent ParseEvent(IParsingSourceStream sourceStream, string line) { string Name = line.Trim(); if (Name.Length <= 0) { throw new ParsingException(107, sourceStream, "Event name cannot be empty."); } IDeclarationSource NameSource = new DeclarationSource(Name, sourceStream); return(new ObjectEvent(NameSource, ParserDomain.ToCSharpName(sourceStream, Name))); }
public ParsingException(int code, IParsingSourceStream sourceStream, Exception innerException, [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string filePath = null, [CallerMemberName] string caller = null) : base(innerException.Message, innerException) { Code = code; Directory = null; ParsingSource = sourceStream.FreezedPosition(); LineNumber = lineNumber; FilePath = ShortFilePath(filePath); Caller = caller; }
public override IDesign Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable) { IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable); ResourceDictionary Content; List <string> FileNames; LoadResourceFile(SourceStream, out Content, out FileNames); if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.Button))) { throw new ParsingException(82, SourceStream, "Missing 'Button' style."); } if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.TextBox))) { throw new ParsingException(83, SourceStream, "Missing 'TextBox' style."); } if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.Image))) { throw new ParsingException(84, SourceStream, "Missing 'Image' style."); } if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.ListBox))) { throw new ParsingException(85, SourceStream, "Missing 'ListBox' style."); } if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.TextBlock))) { throw new ParsingException(86, SourceStream, "Missing 'TextBlock' style."); } if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.RadioButton))) { throw new ParsingException(87, SourceStream, "Missing 'RadioButton' style."); } if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.CheckBox))) { throw new ParsingException(88, SourceStream, "Missing 'CheckBox' style."); } if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.PasswordBox))) { throw new ParsingException(89, SourceStream, "Missing 'PasswordBox' style."); } if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.Primitives.ToggleButton))) { throw new ParsingException(206, SourceStream, "Missing 'ToggleButton' style."); } string MainFileName = FileNames[0]; string Name = Path.GetFileNameWithoutExtension(MainFileName); return(new Design(FileNames, ParserDomain.ToXamlName(SourceStream, Name, "Design"), Content)); }
private Dictionary <IDeclarationSource, string> ParseAreaLayoutsPairs(IParsingSourceStream sourceStream, string line) { Dictionary <IDeclarationSource, string> Result = new Dictionary <IDeclarationSource, string>(); string[] Splitted = line.Split(','); foreach (string Split in Splitted) { IDeclarationSource AreaSource; string LayoutName; ParserDomain.ParseStringPair(sourceStream, Split, '=', out AreaSource, out LayoutName); Result.Add(AreaSource, LayoutName); } return(Result); }
public override IResource Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable) { string Name = Path.GetFileNameWithoutExtension(fileName); IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable); try { using (SourceStream.Open()) { return(new Resource(Name, ParserDomain.ToXamlName(SourceStream, Name, "Resource"), fileName)); } } catch (Exception e) { throw new ParsingException(116, SourceStream, e); } }
private IComponentText ParseComponentText(IDeclarationSource nameSource, IParsingSourceStream sourceStream, List <ComponentInfo> infoList) { IComponentProperty TextProperty = null; IComponentProperty TextDecorationProperty = null; foreach (ComponentInfo Info in infoList) { if (Info.NameSource.Name == "text" && TextProperty == null) { TextProperty = new ComponentProperty(Info); } else if (Info.NameSource.Name == "decoration" && TextDecorationProperty == null) { TextDecorationProperty = new ComponentProperty(Info); } else if (Info.NameSource.Name != "text" && Info.NameSource.Name != "decoration") { throw new ParsingException(27, sourceStream, $"Unknown token '{Info.NameSource.Name}'."); } else { throw new ParsingException(28, sourceStream, $"'{Info.NameSource.Name}' is repeated."); } } if (TextProperty == null) { throw new ParsingException(38, sourceStream, "Text not specified."); } if (TextDecorationProperty != null && TextDecorationProperty.FixedValueSource == null) { throw new ParsingException(39, sourceStream, "Decoration can only be a constant."); } string TextDecoration = TextDecorationProperty != null ? TextDecorationProperty.FixedValueSource.Name : null; if (TextDecoration != null && TextDecoration != Windows.UI.Text.TextDecorations.OverLine.ToString() && TextDecoration != Windows.UI.Text.TextDecorations.Strikethrough.ToString() && TextDecoration != Windows.UI.Text.TextDecorations.Underline.ToString()) { throw new ParsingException(40, sourceStream, $"Invalid decoration for '{nameSource.Name}'."); } return(new ComponentText(nameSource, ParserDomain.ToXamlName(nameSource.Source, nameSource.Name, "Text"), TextProperty, TextDecoration)); }
public static ComponentInfo Parse(IParsingSourceStream sourceStream, string infoText) { IDeclarationSource NameSource; string MemberValue; ParserDomain.ParseStringPair(sourceStream, infoText, '=', out NameSource, out MemberValue); if (!MemberValue.Contains(".")) { return new ComponentInfo() { NameSource = NameSource, FixedValueSource = new DeclarationSource(MemberValue, sourceStream), ObjectSource = null, MemberSource = null, KeySource = null } } ; else { IDeclarationSource ObjectSource; string MemberName; ParserDomain.ParseStringPair(sourceStream, MemberValue, '.', out ObjectSource, out MemberName); string Key; int StartIndex = MemberName.IndexOf("["); int EndIndex = MemberName.IndexOf("]"); IDeclarationSource KeySource; if (StartIndex > 0 && EndIndex > StartIndex) { Key = MemberName.Substring(StartIndex + 1, EndIndex - StartIndex - 1); MemberName = MemberName.Substring(0, StartIndex); KeySource = new DeclarationSource(Key, sourceStream); } else { KeySource = null; } return(new ComponentInfo() { NameSource = NameSource, FixedValueSource = null, ObjectSource = ObjectSource, MemberSource = new DeclarationSource(MemberName, sourceStream), KeySource = KeySource }); } }
private IArea Parse(string name, IParsingSourceStream sourceStream) { IComponentCollection ComponentList; try { ComponentList = ParseComponents(sourceStream); } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException(24, sourceStream, e); } return(new Area(name, ParserDomain.ToXamlName(sourceStream, name, "Area"), ComponentList)); }
private void AddDictionaryContent(IParsingSourceStream sourceStream, ResourceDictionary wrapped, ResourceDictionary dictionary) { foreach (object Key in dictionary.Keys) { if (!wrapped.Contains(Key)) { wrapped.Add(Key, dictionary[Key]); } else { throw new ParsingException(92, sourceStream, $"Key '{Key}' found multiple times."); } } foreach (ResourceDictionary Item in dictionary.MergedDictionaries) { AddDictionaryContent(sourceStream, wrapped, Item); } }
private IColorTheme Parse(string name, IParsingSourceStream sourceStream) { Dictionary <IDeclarationSource, string> Colors; try { Colors = ParseColors(sourceStream); } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException(80, sourceStream, e); } return(new ColorTheme(name, Colors)); }
private void LoadResourceFile(IParsingSourceStream sourceStream, out List <string> Lines) { try { using (sourceStream.Open()) { Lines = new List <string>(); while (!sourceStream.EndOfStream) { sourceStream.ReadLine(); Lines.Add(sourceStream.Line); } } } catch (Exception e) { throw new ParsingException(79, sourceStream, e); } }
private IDynamic Parse(string name, IParsingSourceStream sourceStream) { IDynamicPropertyCollection Properties = new DynamicPropertyCollection(); sourceStream.ReadLine(); string Line = sourceStream.Line; int Indentation = -1; bool UseTab = false; while (Line != null) { IDynamicProperty Property = Parse(sourceStream, ref Line, ref Indentation, ref UseTab); Properties.Add(Property); } string FileName = ParserDomain.ToCSharpName(sourceStream, name + "PageDynamic"); string XamlPageName = ParserDomain.ToXamlName(sourceStream, name, "Page"); return(new Dynamic(name, FileName, XamlPageName, Properties)); }
private IObject Parse(string name, IParsingSourceStream sourceStream) { IObjectPropertyCollection ObjectPropertyList; List <IObjectEvent> ObjectEventList; sourceStream.ReadLine(); string Line = sourceStream.Line; bool IsGlobal; if (!string.IsNullOrEmpty(Line) && Line.Trim().ToLower() == "global") { IsGlobal = true; sourceStream.ReadLine(); } else { IsGlobal = false; } try { ObjectPropertyList = ParseObjectProperties(sourceStream, ref Line); ObjectEventList = ParseEvents(sourceStream, ref Line); } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException(94, sourceStream, e); } string CSharpname = ParserDomain.ToCSharpName(sourceStream, name); return(new Object(name, CSharpname, IsGlobal, ObjectPropertyList, ObjectEventList)); }