void ParseType(string elmName, UxlDocument doc) { SourceValue?typeName = null; SourceValue?cond = null; var elms = new List <UxlElement>(); var def = false; ParseAttributes( name => { switch (name) { case "Name": typeName = GetValue(); return(true); case "Condition": cond = GetValue(); return(true); case "IsDefault": def = GetBool(); return(true); default: elms.Add(new UxlElement(UxlElementType.Set, new SourceValue(GetSource(), name), GetValue(), null, false)); return(true); } }); var result = new UxlType(typeName ?? new SourceValue(), cond, def, elms); ParseElements( name => { switch (name) { case "Method": ParseMethod(name, result); return(true); case "TypeProperty": Log.Warning(GetSource(), ErrorCode.W0000, "<TypeProperty> is deprecated, replace with <Set>"); ParseSet(name, result.Elements); return(true); default: return(TryParseTypeEntity(name, result)); } }); if (typeName == null) { Log.Error(GetSource(), ErrorCode.E0000, "Expected 'Name' attribute on <" + elmName + "> element"); } else { doc.Types.Add(result); } }
void ParseUsing(UxlDocument doc) { var foundNamespace = false; ParseAttributes( name => { switch (name) { case "Namespace": doc.Usings.Add(GetValue()); return(foundNamespace = true); default: return(false); } }); if (!foundNamespace) { Log.Error(GetSource(), ErrorCode.E0000, "Expected 'Namespace' attribute on <Using>"); } ParseEmptyElement(); }
void ParseDeclare(UxlDocument doc) { Source src = null; UxlDeclareType type = 0; SourceValue? key = null; SourceValue? cond = null; SourceValue? targetDir = null; ParseAttributes( name => { switch (name) { case "Condition": cond = GetValue(); return(true); case "TargetDirectory": targetDir = GetValue(); return(true); default: UxlDeclareType et; if (Enum.TryParse(name, out et) && et != UxlDeclareType.Unknown) { if (type != 0) { Log.Error(GetSource(), ErrorCode.E0000, "A (ElementType)=\"(Key)\" attribute was already found on <Declare>"); } src = GetSource(); type = et; key = GetValue(); return(true); } return(false); } }); if (type == 0) { Log.Error(GetSource(), ErrorCode.E0000, "Expected a (ElementType)=\"(Key)\" attribute on <Declare>"); } else { doc.Declarations.Add(new UxlDeclare(src, type, key ?? new SourceValue(), cond)); } if (targetDir != null && key != null) { doc.Elements.Add(new UxlElement(UxlElementType.Set, new SourceValue(targetDir.Value.Source, key.Value.String + ".TargetDirectory"), targetDir.Value, null, false)); } ParseEmptyElement(); }
void ParseDeprecate(UxlDocument doc) { string oldName = null; string newName = null; ParseAttributes( name => { if (oldName == null && newName == null && name != "Condition") { oldName = name; newName = GetValue().String; return(true); } return(false); }); doc.Deprecations.Add(new UxlDeprecate(GetSource(), oldName, newName)); ParseEmptyElement(); }
void ParseDefine(UxlDocument doc) { string define = null; SourceValue?expression = null; ParseAttributes( name => { if (define == null && name != "Condition") { define = name; expression = GetValue(); // VALUE == NAME, when VALUE is omitted from XML if (expression.Value.String == define) { expression = new SourceValue(GetSource(), "1"); } return(true); } return(false); }); if (define == null || !expression.HasValue) { Log.Error(GetSource(), ErrorCode.E0000, "Expected a (Name)=\"(Expression)\" attribute on <Define>"); } else { doc.Defines.Add(new UxlDefine(define, expression.Value)); } ParseEmptyElement(); }
UxlDocument ParseDocument() { SourceValue?backend = null; SourceValue?cond = null; ParseAttributes( name => { switch (name) { case "Backend": backend = GetValue(); return(true); case "Condition": cond = GetValue(); return(true); default: return(false); } }); UxlBackendType backendType = 0; if (backend == null) { Log.Error(GetSource(), ErrorCode.E0000, "Expected 'Backend' attribute on <Extensions>"); } else if (!Enum.TryParse(backend.Value.String, out backendType) || backendType == UxlBackendType.Unknown) { Log.Error(backend.Value.Source, ErrorCode.E0000, "Unknown backend " + backend.Value.String.Quote()); } var result = new UxlDocument(File.Package, backendType, cond); ParseElements( name => { switch (name) { case "Using": ParseUsing(result); return(true); case "Define": ParseDefine(result); return(true); case "Declare": ParseDeclare(result); return(true); case "Deprecate": ParseDeprecate(result); return(true); case "Definition": Log.Warning(GetSource(), ErrorCode.W0000, "<Definition> is deprecated, replace with <Declare>"); ParseDeclare(result); return(true); case "Type": ParseType(name, result); return(true); case "Template": ParseTemplate(name, result.Templates); return(true); case "Library": Log.Warning(GetSource(), ErrorCode.W0000, "<Library> is deprecated, replace with <Template>"); ParseTemplate(name, result.Templates); return(true); case "Property": Log.Warning(GetSource(), ErrorCode.W0000, "<Property> is deprecated, replace with <Set>"); ParseSet(name, result.Elements); return(true); default: return(TryParseEntity(name, result)); } }); return(result); }