コード例 #1
0
ファイル: InterPreter.cs プロジェクト: JasperH/CSConsole
 /// <summary> 
 /// Filter the not name like, and also if parameters are added, the not methods.
 /// </summary>
 /// <param name="nextNode">The next node.</param>
 /// <param name="initialMembers">The initial members.</param>
 /// <param name="parameters">The parameters.</param>
 /// <returns></returns>
 private List<MemberInfo> getPossibleMembers(ExecutionNode nextNode, MemberInfo[] initialMembers, List<object> parameters)
 {
     var possibleMembers = initialMembers.Where(possibleMember => possibleMember.Name.ToLower() == nextNode.executionText.ToLower()).ToList();
     if (parameters.Count > 0)
     {
         List<MemberInfo> replaceList = new List<MemberInfo>();
         foreach (var memberInfo in possibleMembers)
         {
             if (memberInfo.MemberType == MemberTypes.Method)
                 replaceList.Add(memberInfo);
         }
         possibleMembers = replaceList;
     }
     return possibleMembers;
 }
コード例 #2
0
ファイル: InterPreter.cs プロジェクト: JasperH/CSConsole
        /// <summary>
        /// Seperates the specified text, by walking the tree.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static ExecutionNode seperate(string text)
        {
            String usingText = text.Trim();
            usingText = removeUselesWhite(usingText);
            ExecutionNode rootNode = new ExecutionNode(null);
            try
            {
                ExecutionNode currentNode = rootNode;
                int currentCharacter = 0;
                for (int i = 0; i < usingText.Length; i++)
                {
                    Char c = usingText[i];

                    switch (c)
                    {
                        case '(':
                            currentNode.executionText = usingText.Substring(currentCharacter, i - currentCharacter).Trim();
                            currentCharacter = i + 1;
                            ExecutionNode nextNode = new ExecutionNode(currentNode);
                            currentNode = nextNode;
                            break;
                        case ')':
                            if (currentNode.executionText.Equals(""))
                                currentNode.executionText = usingText.Substring(currentCharacter, i - currentCharacter).Trim();
                            if (currentNode.executionText.Equals(""))
                            {
                                ExecutionNode papa = currentNode.parentNode;
                                currentNode.parentNode.removeParameterNode(currentNode);
                                currentNode = papa;
                                currentCharacter = i + 1;
                                break;
                            }
                            currentNode = currentNode.parentNode;
                            currentCharacter = i + 1;
                            break;
                        case ' ':
                            if (currentNode.executionText.Equals(""))
                            {
                                if (!usingText.Substring(currentCharacter, i - currentCharacter).Trim().Equals(""))
                                    currentNode.executionText = usingText.Substring(currentCharacter, i - currentCharacter).Trim();
                            }
                            currentCharacter = i + 1;
                            currentNode.PostParallelNode = new ExecutionNode(currentNode.parentNode);
                            currentNode.PostParallelNode.anteParallelNode = currentNode;
                            currentNode = currentNode.PostParallelNode;
                            break;
                        case '.':
                            if (currentNode.executionText.Equals(""))
                                currentNode.executionText = usingText.Substring(currentCharacter, i - currentCharacter).Trim();
                            currentCharacter = i + 1;
                            currentNode.postDotNode = new ExecutionNode(currentNode.parentNode);
                            currentNode.postDotNode.anteDotNode = currentNode;
                            currentNode = currentNode.postDotNode;
                            break;
                        case ',':
                            if (currentNode.executionText.Equals(""))
                                currentNode.executionText = usingText.Substring(currentCharacter, i - currentCharacter).Trim();
                            currentCharacter = i + 1;
                            ExecutionNode myNextNode = new ExecutionNode(currentNode.parentNode);
                            currentNode = myNextNode;
                            break;

                        case ';':
                            if (currentNode.executionText.Equals(""))
                                currentNode.executionText = usingText.Substring(currentCharacter, i - currentCharacter).Trim();
                            break;
                    }
                }
            }
            catch (NullReferenceException nRE)
            { throw new ArgumentException("ILLEGAL AMOUNT OF BRACKETS!"); }

            return rootNode;
        }
コード例 #3
0
ファイル: InterPreter.cs プロジェクト: JasperH/CSConsole
 private List<Object> getParameterObjects(ExecutionNode myNode)
 {
     var retList = new List<object>();
     foreach (var parameterNode in
         myNode.getParameterNodes().Where(parameterNode => parameterNode.getAnteDotNode() == null))
     {
         printMessageToLogger("Parameter passing: " + parameterNode.executionText, 1);
         retList.Add(executeBaseNode(parameterNode));
     }
     return retList;
 }
コード例 #4
0
ファイル: InterPreter.cs プロジェクト: JasperH/CSConsole
 public ExecutionNode(ExecutionNode parentNode)
 {
     this.parentNode = parentNode;
     if (parentNode != null)
         parentNode.parameterNodes.Add(this);
 }
コード例 #5
0
ファイル: InterPreter.cs プロジェクト: JasperH/CSConsole
        /// <summary>
        /// Executes the dot attached node and all afterdot nodes.
        /// </summary>
        /// <param name="nextNode">The next node.</param>
        /// <param name="onWhich">The on which.</param>
        /// <returns></returns>
        private object executeDotAttachedNode(ExecutionNode nextNode, object onWhich)
        {
            Type onWichType = onWhich.GetType();
            printMessageToLogger("Start processing dotNode: " + nextNode.executionText, 1);
            var parameters = getParameterObjects(nextNode);
            //NameFilter
            var possibleMembers = getPossibleMembers(nextNode, onWichType.GetMembers(), parameters);
            if (possibleMembers.Count == 0)
            {
                printMessageToLogger("No possible members for: " + nextNode.executionText, 50);
                throw new DotItemNotFoundException();
            }
            //overloadFilter
            possibleMembers = getPossibleMembersFilteringOverloadMethods(parameters, possibleMembers);
            if (!enableFirstTake && possibleMembers.Count > 1)
            {
                printMessageToLogger("To many possibilities found and firstTake not enabled: " + nextNode.executionText, 50);
                throw new ToManyDotItemsFoundException();
            }
            var chosen = possibleMembers[0];
            object result;
            switch (chosen.MemberType)
            {
                case MemberTypes.Property:

                    result = onWichType.GetProperty(chosen.Name).GetValue(chosen, new object[0]);
                    break;

                case MemberTypes.Field:
                    result = onWichType.GetField(chosen.Name).GetValue(onWhich);
                    break;
                case MemberTypes.Method:
                    //VIA methodbase
                    result = ((MethodBase)chosen).Invoke(onWhich, parameters.ToArray());
                    break;
                case MemberTypes.Constructor:
                case MemberTypes.NestedType:
                case MemberTypes.Event:
                default:
                    throw new NotImplementedException();
                    break;
            }

            if (nextNode.hasPostDotNode())
            {
                printMessageToLogger(nextNode.executionText + " finished & given through to: " + nextNode.getPostDotNode().executionText, 1);
                return executeDotAttachedNode(nextNode.getPostDotNode(), result);
            }

            printMessageToLogger(nextNode.executionText + " finished", 1);
            return result;
        }
コード例 #6
0
ファイル: InterPreter.cs プロジェクト: JasperH/CSConsole
        /// <summary>
        /// Executes the base node and all afterdot nodes. Basenodes are no methods and have no parameters.
        /// </summary>
        /// <param name="firstNode">The first node.</param>
        /// <returns></returns>
        private object executeBaseNode(ExecutionNode firstNode)
        {
            var executionText = firstNode.executionText;
            printMessageToLogger("Start processing baseNode: " + firstNode.executionText, 1);
            List<Object> possibilities = theConsole.myAutoCompleter.getAllFirstBasesObjects(AutoCompleter.getFirstPartOfName((firstNode.executionText)));
            #region preInterpreterReplacement
            //DIRECT PREINTERPRETE REPLACEMENT

            if (myPreInterpreter.getReplacementStringDictionary().Keys.Count > 0 && myPreInterpreter.getReplacementStringDictionary().ContainsKey(firstNode.executionText))
            {
                object preResult;
                myPreInterpreter.getReplacementStringDictionary().TryGetValue(firstNode.executionText, out preResult);

                possibilities = new List<object>(1) { preResult };
            }
            #endregion

            //END DIRECT PREINTERPRETE REPLACEMENT
            if (possibilities.Count == 0)
            {
                printMessageToLogger("No possible base object for: " + executionText, 50);
                throw new BaseItemNotFoundException();
            }
            if (!enableFirstTake && possibilities.Count > 1)
            {
                printMessageToLogger("To many possibilities found and firstTake not enabled: " + executionText, 50);
                throw new ToManyBaseFoundException();
            }
            if (firstNode.hasPostDotNode())
            {
                printMessageToLogger(executionText + " finished & given through to: " + firstNode.getPostDotNode().executionText, 1);
                return executeDotAttachedNode(firstNode.getPostDotNode(), possibilities[0]);
            }
            printMessageToLogger(executionText + " finished", 1);
            return possibilities[0];
        }
コード例 #7
0
ファイル: InterPreter.cs プロジェクト: JasperH/CSConsole
 public void removeParameterNode(ExecutionNode executionNode)
 {
     if (executionNode == null)
         return;
     if (parameterNodes.Contains(executionNode))
     {
         parameterNodes.Remove(executionNode);
         if (executionNode.parentNode == this)
         {
             executionNode.parentNode = null;
         }
     }
 }