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 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); }
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)); }
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)); }
private List <IObjectEvent> ParseEvents(IParsingSourceStream sourceStream, ref string line) { List <IObjectEvent> ObjectEventList = new List <IObjectEvent>(); if (line != "events") { sourceStream.ReadLine(); string HeaderLine = sourceStream.Line; if (HeaderLine != "events") { throw new ParsingException(105, sourceStream, "'events' expected."); } } while (!sourceStream.EndOfStream) { sourceStream.ReadLine(); line = sourceStream.Line.Trim(); if (string.IsNullOrEmpty(line)) { break; } foreach (IObjectEvent ObjectEvent in ObjectEventList) { if (ObjectEvent.NameSource.Name == line) { throw new ParsingException(106, sourceStream, $"Event name '{line}' specified more than once."); } } IObjectEvent NewEvent = ParseEvent(sourceStream, line); ObjectEventList.Add(NewEvent); } return(ObjectEventList); }
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 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 IComponentCollection ParseComponents(IParsingSourceStream sourceStream) { IComponentCollection ComponentList = new ComponentCollection(); while (!sourceStream.EndOfStream) { sourceStream.ReadLine(); IComponent NewComponent = ParseComponent(sourceStream); foreach (IComponent Component in ComponentList) { if (Component.Source.Name == NewComponent.Source.Name) { throw new ParsingException(0, sourceStream, $"Component with name '{NewComponent.Source.Name}' found more than once."); } } ComponentList.Add(NewComponent); } return(ComponentList); }
private IDynamicProperty Parse(IParsingSourceStream sourceStream, ref string line, ref int indentation, ref bool useTab) { while (string.IsNullOrEmpty(line) && !sourceStream.EndOfStream) { sourceStream.ReadLine(); line = sourceStream.Line; } IDeclarationSource PropertySource; string ResultValue; ParserDomain.ParseStringPair(sourceStream, ':', out PropertySource, out ResultValue); if (string.IsNullOrEmpty(PropertySource.Name)) { throw new ParsingException(209, sourceStream, "Missing dynamic property name."); } string CSharpName = ParserDomain.ToCSharpName(PropertySource.Source, PropertySource.Name); DynamicOperationResults Result; if (ResultValue == "boolean") { Result = DynamicOperationResults.Boolean; } else { throw new ParsingException(210, sourceStream, $"Invalid dynamic property type '{ResultValue}'."); } Stack <IDynamicOperation> OperationStack = new Stack <IDynamicOperation>(); IDynamicOperation RootOperation = null; for (;;) { sourceStream.ReadLine(); line = sourceStream.Line; if (string.IsNullOrEmpty(line)) { break; } if (indentation < 0) { MeasureIndentation(sourceStream, ref indentation, ref useTab); } int Depth = GetIndentation(sourceStream, indentation, useTab); string Text = line.Trim(); if (Text == "NOT") { OperationStack.Push(new UnaryOperation(DynamicOperationTypes.NOT)); } else if (Text == "OR") { OperationStack.Push(new BinaryOperation(DynamicOperationTypes.OR)); } else if (Text == "AND") { OperationStack.Push(new BinaryOperation(DynamicOperationTypes.AND)); } else if (Text == "EQUALS") { OperationStack.Push(new BinaryOperation(DynamicOperationTypes.EQUALS)); } else if (Text == "GREATER THAN") { OperationStack.Push(new BinaryOperation(DynamicOperationTypes.GREATER_THAN)); } else if (Text == "IS EMPTY") { OperationStack.Push(new UnaryOperation(DynamicOperationTypes.IS_EMPTY)); } else { IDynamicOperation Operand; int IntegerConstantValue; if (int.TryParse(Text, out IntegerConstantValue)) { Operand = new IntegerConstantOperation(IntegerConstantValue); } else { IDeclarationSource ObjectSource; IDeclarationSource MemberSource; IDeclarationSource KeySource; if (!ParserDomain.TryParseObjectProperty(sourceStream, Text, out ObjectSource, out MemberSource, out KeySource)) { throw new ParsingException(211, sourceStream, $"Expected operator, integer constant or object property."); } ComponentInfo Info = new ComponentInfo(); Info.ObjectSource = ObjectSource; Info.MemberSource = MemberSource; Info.KeySource = KeySource; ComponentProperty ValueProperty = new ComponentProperty(Info); Operand = new PropertyValueOperation(ValueProperty); } while (OperationStack.Count > 0) { IDynamicOperation CurrentOperation = OperationStack.Peek(); if ((CurrentOperation is IUnaryOperation AsUnary) && (AsUnary.Operand == null)) { AsUnary.SetOperand(Operand); RootOperation = OperationStack.Pop(); Operand = RootOperation; }
private IUnitTest Parse(string fileName, IParsingSourceStream SourceStream) { List <ITestingOperation> Operations = new List <ITestingOperation>(); while (!SourceStream.EndOfStream) { SourceStream.ReadLine(); string Line = SourceStream.Line; if (string.IsNullOrEmpty(Line)) { break; } string[] Splitted = Line.Split(','); if (Splitted.Length < 4) { throw new ParsingException(232, SourceStream, "Invalid line in the unit testing file."); } IDeclarationSource PageName = new DeclarationSource(Splitted[0].Trim(), SourceStream); string Operation = Splitted[1].Trim(); IDeclarationSource AreaName = new DeclarationSource(Splitted[2].Trim(), SourceStream); string Parameters = Splitted[3]; for (int i = 4; i < Splitted.Length; i++) { Parameters += "," + Splitted[i]; } ITestingOperation NewOperation; if (Operation == "click") { IDeclarationSource ComponentName = new DeclarationSource(Parameters.Trim(), SourceStream); NewOperation = new ClickOperation(PageName, AreaName, ComponentName); } else if (Operation == "toggle") { IDeclarationSource ComponentName = new DeclarationSource(Parameters.Trim(), SourceStream); NewOperation = new ToggleOperation(PageName, AreaName, ComponentName); } else if (Operation == "fill") { string[] FillParameters = Parameters.Split('='); if (FillParameters.Length < 2) { throw new ParsingException(233, SourceStream, "Invalid line in the unit testing file."); } IDeclarationSource ComponentName = new DeclarationSource(FillParameters[0].Trim(), SourceStream); string Content = FillParameters[1].Trim(); NewOperation = new FillOperation(PageName, AreaName, ComponentName, Content); } else if (Operation == "select") { string[] FillParameters = Parameters.Split('='); if (FillParameters.Length < 2) { throw new ParsingException(234, SourceStream, "Invalid line in the unit testing file."); } IDeclarationSource ComponentName = new DeclarationSource(FillParameters[0].Trim(), SourceStream); int Index; if (!int.TryParse(FillParameters[1].Trim(), out Index)) { throw new ParsingException(235, SourceStream, "Invalid line in the unit testing file."); } NewOperation = new SelectOperation(PageName, AreaName, ComponentName, Index); } else { throw new ParsingException(236, SourceStream, $"Unknown unit testing operation '{Operation}'."); } Operations.Add(NewOperation); } return(new UnitTest(fileName, Operations)); }
public void Process(IDictionary <ConditionalDefine, bool> conditionalDefineTable) { TranslationTable = new Dictionary <string, IDictionary <string, string> >(); LanguageList = new List <string>(); KeyList = new List <string>(); UsedKeyList = new List <string>(); int LineNumber = 0; IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(TranslationFile, conditionalDefineTable); using (SourceStream.Open()) { while (!SourceStream.EndOfStream) { SourceStream.ReadLine(); string Line = SourceStream.Line; string[] Splitted = Line.Split(Separator); if (TranslationTable.Count == 0) { if (Splitted.Length < 2) { throw new ParsingException(178, SourceStream, "The translation file is expected to have a header."); } string KeyHeader = Splitted[0].Trim(); if (KeyHeader != "Key") { throw new ParsingException(179, SourceStream, "The translation file is expected to have a header starting with 'Key' for the first column."); } for (int i = 1; i < Splitted.Length; i++) { string Language = Splitted[i].Trim(); if (Language.Length == 0 || Language.Length >= 100) { throw new ParsingException(180, SourceStream, $"The translation file is expected to have the name of a language at the header of column #{i + 1}."); } if (TranslationTable.ContainsKey(Language)) { throw new ParsingException(181, SourceStream, $"Language '{Language}' found more than once in the header."); } LanguageList.Add(Language); TranslationTable.Add(Language, new Dictionary <string, string>()); } } else if (Splitted.Length != LanguageList.Count + 1) { throw new ParsingException(182, SourceStream, $"Inconsistent format at line {LineNumber + 1}."); } else { string Key = Splitted[0]; if (!IsKeyReserved(Key) && !IsKeyValid(Key)) { throw new ParsingException(183, SourceStream, $"Invalid key '{Key}' at line {LineNumber + 1}."); } for (int i = 1; i < Splitted.Length; i++) { string Language = LanguageList[i - 1]; IDictionary <string, string> LanguageTable = TranslationTable[Language]; if (i == 1 && LanguageTable.ContainsKey(Key)) { throw new ParsingException(184, SourceStream, $"Translation for key '{Key}' found at line {LineNumber + 1} but this key already has an entry."); } LanguageTable.Add(Key, Splitted[i].Trim()); } KeyList.Add(Key); } LineNumber++; } } }