diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/SoftwareDeveloper/Associations/BinaryGrammar/SynalysisBinaryGrammarDataFormat.uexml b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/SoftwareDeveloper/Associations/BinaryGrammar/SynalysisBinaryGrammarDataFormat.uexml new file mode 100644 index 00000000..6398b418 --- /dev/null +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/SoftwareDeveloper/Associations/BinaryGrammar/SynalysisBinaryGrammarDataFormat.uexml @@ -0,0 +1,20 @@ + + + + + + + + *.grammar + + + + + + + + + + + + diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 8830e324..05926bf8 100644 --- a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -704,6 +704,7 @@ + diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/DataFormats/XMLBinaryGrammar/XMLBinaryGrammarDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/DataFormats/XMLBinaryGrammar/XMLBinaryGrammarDataFormat.cs new file mode 100644 index 00000000..a64c4fd8 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/DataFormats/XMLBinaryGrammar/XMLBinaryGrammarDataFormat.cs @@ -0,0 +1,170 @@ +// +// XMLBinaryGrammarDataFormat.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Collections.Generic; +using UniversalEditor.DataFormats.Markup.XML; +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.BinaryGrammar; +using UniversalEditor.ObjectModels.BinaryGrammar.GrammarItems; +using UniversalEditor.ObjectModels.Markup; + +namespace UniversalEditor.Plugins.Synalysis.DataFormats.XMLBinaryGrammar +{ + public class XMLBinaryGrammarDataFormat : XMLDataFormat + { + private static DataFormatReference _dfr = null; + protected override DataFormatReference MakeReferenceInternal() + { + if (_dfr == null) + { + _dfr = base.MakeReferenceInternal(); + _dfr.Capabilities.Add(typeof(BinaryGrammarObjectModel), DataFormatCapabilities.All); + } + return _dfr; + } + + protected override void BeforeLoadInternal(Stack objectModels) + { + base.BeforeLoadInternal(objectModels); + objectModels.Push(new MarkupObjectModel()); + } + protected override void AfterLoadInternal(Stack objectModels) + { + base.AfterLoadInternal(objectModels); + + MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel); + BinaryGrammarObjectModel grammar = (objectModels.Pop() as BinaryGrammarObjectModel); + + MarkupTagElement tagUFWB = (mom.Elements["ufwb"] as MarkupTagElement); + if (tagUFWB == null) + throw new InvalidDataFormatException("xml file does not contain top-level 'ufwb' tag"); + + MarkupTagElement tagGrammar = (tagUFWB.Elements["grammar"] as MarkupTagElement); + if (tagGrammar == null) + throw new InvalidDataFormatException("'ufwb' tag does not contain child-level 'grammar' tag"); + + MarkupAttribute attStart = tagGrammar.Attributes["start"]; + if (attStart == null) + throw new InvalidDataFormatException("'grammar' tag does not contain 'start' attribute (entry point)"); + + grammar.Name = tagGrammar.Attributes["name"]?.Value; + grammar.Author = tagGrammar.Attributes["author"]?.Value; + grammar.FileExtension = tagGrammar.Attributes["fileextension"]?.Value; + grammar.UniversalTypeIdentifier = tagGrammar.Attributes["uti"]?.Value; + grammar.IsComplete = (tagGrammar.Attributes["complete"]?.Value.Equals("yes")).GetValueOrDefault(); + + grammar.Description = (tagGrammar.Elements["description"] as MarkupTagElement)?.Value; + + for (int i = 0; i < tagGrammar.Elements.Count; i++) + { + MarkupTagElement tag = (tagGrammar.Elements[i] as MarkupTagElement); + if (tag == null) continue; + + if (tag.FullName == "structure") + { + GrammarItemStructure s = LoadStructure(tag); + if (attStart.Value.Equals(String.Format("id:{0}", s.ID)) || attStart.Value.Equals(s.Name)) + { + grammar.InitialStructure = s; + } + grammar.Structures.Add(s); + } + } + } + + private GrammarItemStructure LoadStructure(MarkupTagElement tag) + { + GrammarItemStructure s = new GrammarItemStructure(); + s.ID = tag.Attributes["id"]?.Value; + s.Name = tag.Attributes["name"]?.Value; + s.Length = tag.Attributes["length"]?.Value; + s.Encoding = tag.Attributes["encoding"]?.Value; + s.Endianness = "big".Equals(tag.Attributes["endian"]?.Value) ? Endianness.BigEndian : Endianness.LittleEndian; + s.Signed = !"no".Equals(tag.Attributes["signed"]?.Value); + s.Extends = tag.Attributes["extends"]?.Value; + foreach (MarkupElement el in tag.Elements) + { + MarkupTagElement tag1 = (el as MarkupTagElement); + if (tag1 == null) continue; + + GrammarItem item = null; + + string fieldName = tag1.Attributes["name"]?.Value; + string fieldID = tag1.Attributes["id"]?.Value; + string fieldLength = tag1.Attributes["length"]?.Value; + string repeatMax = tag1.Attributes["repeatmax"]?.Value; + + switch (tag1.FullName.ToLower()) + { + case "structref": + { + item = new GrammarItemStructureReference(); + (item as GrammarItemStructureReference).Structure = tag1.Attributes["structure"]?.Value; + break; + } + case "number": + { + item = new GrammarItemNumber(); + break; + } + case "string": + { + item = new GrammarItemString(); + break; + } + } + + if (item != null) + { + item.Name = fieldName; + item.ID = fieldID; + item.Length = fieldLength; + + MarkupTagElement tagFixedValues = (tag1.Elements["fixedvalues"] as MarkupTagElement); + if (tagFixedValues != null) + { + foreach (MarkupElement elFixedValue in tagFixedValues.Elements) + { + MarkupTagElement tagFixedValue = (elFixedValue as MarkupTagElement); + if (tagFixedValue == null) continue; + + FixedValue val = new FixedValue(); + val.Name = tagFixedValue.Attributes["name"]?.Value; + val.Value = tagFixedValue.Attributes["value"]?.Value; + s.FixedValues.Add(val); + } + } + + s.Items.Add(item); + } + } + return s; + } + + protected override void BeforeSaveInternal(Stack objectModels) + { + base.BeforeSaveInternal(objectModels); + + BinaryGrammarObjectModel grammar = (objectModels.Pop() as BinaryGrammarObjectModel); + MarkupObjectModel mom = new MarkupObjectModel(); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/Properties/AssemblyInfo.cs b/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..f0fa77bc --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/Properties/AssemblyInfo.cs @@ -0,0 +1,46 @@ +// +// AssemblyInfo.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("UniversalEditor.Plugins.Synalysis")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Mike Becker")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/UniversalEditor.Plugins.Synalysis.csproj b/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/UniversalEditor.Plugins.Synalysis.csproj new file mode 100644 index 00000000..06e353fe --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Synalysis/UniversalEditor.Plugins.Synalysis.csproj @@ -0,0 +1,51 @@ + + + + Debug + AnyCPU + {0EEC3646-9749-48AF-848E-0F699247E76F} + Library + UniversalEditor.Plugins.Synalysis + UniversalEditor.Plugins.Synalysis + v4.7 + + + true + full + false + ..\..\Output\Debug\Plugins + DEBUG; + prompt + 4 + false + + + true + ..\..\Output\Release\Plugins + prompt + 4 + false + + + + + + + + + + + + + + + {2D4737E6-6D95-408A-90DB-8DFF38147E85} + UniversalEditor.Core + + + {30467E5C-05BC-4856-AADC-13906EF4CADD} + UniversalEditor.Essential + + + + \ No newline at end of file diff --git a/CSharp/UniversalEditor.sln b/CSharp/UniversalEditor.sln index e3696fdf..3cba551e 100644 --- a/CSharp/UniversalEditor.sln +++ b/CSharp/UniversalEditor.sln @@ -145,6 +145,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MBS.Framework", "..\..\MBS. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.CRI", "Plugins\UniversalEditor.Plugins.CRI\UniversalEditor.Plugins.CRI.csproj", "{BB080ED6-A8D2-43B0-BC9F-323D3D587F91}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Synalysis", "Plugins\UniversalEditor.Plugins.Synalysis\UniversalEditor.Plugins.Synalysis.csproj", "{0EEC3646-9749-48AF-848E-0F699247E76F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -417,6 +419,10 @@ Global {BB080ED6-A8D2-43B0-BC9F-323D3D587F91}.Debug|Any CPU.Build.0 = Debug|Any CPU {BB080ED6-A8D2-43B0-BC9F-323D3D587F91}.Release|Any CPU.ActiveCfg = Release|Any CPU {BB080ED6-A8D2-43B0-BC9F-323D3D587F91}.Release|Any CPU.Build.0 = Release|Any CPU + {0EEC3646-9749-48AF-848E-0F699247E76F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0EEC3646-9749-48AF-848E-0F699247E76F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0EEC3646-9749-48AF-848E-0F699247E76F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0EEC3646-9749-48AF-848E-0F699247E76F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {6F0AB1AF-E1A1-4D19-B19C-05BBB15C94B2} = {05D15661-E684-4EC9-8FBD-C014BA433CC5} @@ -484,6 +490,7 @@ Global {EA724755-2670-4520-86AA-657C8A124DB7} = {2ED32D16-6C06-4450-909A-40D32DA67FB4} {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} = {20F315E0-52AE-479F-AF43-3402482C1FC8} {BB080ED6-A8D2-43B0-BC9F-323D3D587F91} = {2ED32D16-6C06-4450-909A-40D32DA67FB4} + {0EEC3646-9749-48AF-848E-0F699247E76F} = {2ED32D16-6C06-4450-909A-40D32DA67FB4} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0