From 3e6240d8957ec7abed6ab18688c6945f0a19082a Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 31 Mar 2014 00:10:39 -0400 Subject: [PATCH] Fix array editor disabled --- NBTExplorer.Installer/Product.wxs | 2 +- NBTExplorer/NBTExplorer.csproj | 5 +- NBTExplorer/Properties/AssemblyInfo.cs | 4 +- NBTModel/FilterExpressionParser.cs | 101 +++++++++++++++++++++++++ NBTModel/NBTModel.csproj | 5 +- NBTModel/NbtPath.cs | 2 +- 6 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 NBTModel/FilterExpressionParser.cs diff --git a/NBTExplorer.Installer/Product.wxs b/NBTExplorer.Installer/Product.wxs index 4702375..6fc2c09 100644 --- a/NBTExplorer.Installer/Product.wxs +++ b/NBTExplorer.Installer/Product.wxs @@ -3,7 +3,7 @@ diff --git a/NBTExplorer/NBTExplorer.csproj b/NBTExplorer/NBTExplorer.csproj index c6f53e2..f58521c 100644 --- a/NBTExplorer/NBTExplorer.csproj +++ b/NBTExplorer/NBTExplorer.csproj @@ -88,9 +88,8 @@ - - False - References\Substrate.dll + + ..\References\Substrate.dll diff --git a/NBTExplorer/Properties/AssemblyInfo.cs b/NBTExplorer/Properties/AssemblyInfo.cs index 07f2afb..9bbeb69 100644 --- a/NBTExplorer/Properties/AssemblyInfo.cs +++ b/NBTExplorer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.7.1.0")] -[assembly: AssemblyFileVersion("2.7.1.0")] +[assembly: AssemblyVersion("2.7.2.0")] +[assembly: AssemblyFileVersion("2.7.2.0")] diff --git a/NBTModel/FilterExpressionParser.cs b/NBTModel/FilterExpressionParser.cs new file mode 100644 index 0000000..32882c6 --- /dev/null +++ b/NBTModel/FilterExpressionParser.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NBTExplorer.Model +{ + class FilterExpressionParser + { + private Stack argStack = new Stack(); + + /*public bool Parse (DataNode targetNode, List tokens) + { + Queue tokenQueue = new Queue(FilterExpressionConverter.Convert(tokens)); + + while (tokenQueue.Count > 0) { + string token = tokenQueue.Dequeue(); + + switch (token) { + case "equal": + + } + } + }*/ + } + + static class FilterExpressionConverter + { + private static List> OperatorGroups = new List> { + new List { "equal", "greater", "less", "contains", "begins", "ends" }, + new List { "not" }, + new List { "and", "or" }, + }; + + public static List Convert (List tokens) + { + Queue tokenQueue = new Queue(tokens); + List output = new List(); + Stack opStack = new Stack(); + + while (tokenQueue.Count > 0) { + string token = tokenQueue.Dequeue(); + + if (IsGroupStart(token)) { + opStack.Push(token); + } + else if (IsGroupEnd(token)) { + while (opStack.Count > 0 && !IsGroupStart(opStack.Peek())) + output.Add(opStack.Pop()); + if (opStack.Count == 0) + throw new Exception("Mismatched grouping"); + opStack.Pop(); + } + else if (IsOperator(token)) { + while (opStack.Count > 0 && IsOperator(opStack.Peek())) { + if (Precedence(token) > Precedence(opStack.Peek())) + output.Add(opStack.Pop()); + } + opStack.Push(token); + } + else { + output.Add(token); + } + } + + while (opStack.Count > 0) { + if (IsGroupStart(opStack.Peek())) + throw new Exception("Mismatched grouping"); + output.Add(opStack.Pop()); + } + + return output; + } + + private static bool IsGroupStart (string token) + { + return token == "("; + } + + private static bool IsGroupEnd (string token) + { + return token == ")"; + } + + private static bool IsOperator (string token) + { + foreach (var group in OperatorGroups) { + if (group.Contains(token)) + return true; + } + return false; + } + + private static int Precedence (string op) { + for (int i = 0; i < OperatorGroups.Count; i++) { + if (OperatorGroups[i].Contains(op)) + return i; + } + return int.MaxValue; + } + } +} diff --git a/NBTModel/NBTModel.csproj b/NBTModel/NBTModel.csproj index 6901e4d..f1f6341 100644 --- a/NBTModel/NBTModel.csproj +++ b/NBTModel/NBTModel.csproj @@ -18,7 +18,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;WINDOWS prompt 4 @@ -26,7 +26,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;WINDOWS prompt 4 @@ -46,6 +46,7 @@ + diff --git a/NBTModel/NbtPath.cs b/NBTModel/NbtPath.cs index 2af4da6..f2affa3 100644 --- a/NBTModel/NbtPath.cs +++ b/NBTModel/NbtPath.cs @@ -51,7 +51,7 @@ private IEnumerable EnumerateNodes (DataNode containerNode, List remainingLevels = nextLevels.GetRange(1, nextLevels.Count - 1); - + if (part == "*") { foreach (DataNode childNode in containerNode.Nodes) { foreach (DataNode grandChildNode in EnumerateNodes(childNode, remainingLevels))