Пример #1
0
        /// <summary>
        /// 获取指令补全
        /// </summary>
        /// <param name="currentInput">当前的指令输入</param>
        /// <returns></returns>
        public static InputAttribution GetInstructionCompletion(InputAttribution currentInput)
        {
            if (string.IsNullOrEmpty(currentInput.content))
            {
                return(currentInput);
            }
            string targetInstructionLeft, targetInstructionPart, targetInstructionRight;

            GetInstructionCompletionDepart(currentInput, out targetInstructionLeft, out targetInstructionPart, out targetInstructionRight);
            if (string.IsNullOrEmpty(targetInstructionPart))
            {
                return(currentInput);
            }
            InputAttribution retn = currentInput; retn.selectEmpty = true;
            string           cp   = "";

            switch (GetInstructionCompletionPartType(targetInstructionPart))
            {
            case InstructionType.STARTUP:
                cp = AInstruction_Startup.GetCompletion(targetInstructionPart);
                break;

            case InstructionType.MACRO:
                cp = AInstruction_Macro.GetCompletion(targetInstructionPart);
                break;

            case InstructionType.CONST:
                cp = AConstQuote.GetCompletion(targetInstructionPart);
                break;

            case InstructionType.BUILDIN:
                break;
            }

            if (!string.IsNullOrEmpty(cp))
            {
                retn.content     = targetInstructionLeft + cp + targetInstructionRight;
                retn.selectStart = retn.caretPosition = currentInput.caretPosition;
                retn.selectEnd   = retn.selectStart + cp.Length - targetInstructionPart.Length - 1;
                retn.selectEmpty = retn.selectEnd <= 0 || retn.selectEnd < retn.selectStart;
            }

            // Check const-instruction completion at last.
            if (retn.selectEmpty)
            {
                cp               = AConstInstruction.GetCompletion(targetInstructionPart);
                retn.content     = targetInstructionLeft + cp + targetInstructionRight;
                retn.selectStart = retn.caretPosition = currentInput.caretPosition;
                retn.selectEnd   = retn.selectStart + cp.Length - targetInstructionPart.Length - 1;
                retn.selectEmpty = retn.selectEnd <= 0 || retn.selectEnd < retn.selectStart;
            }

            return(retn);
        }
Пример #2
0
 /// <summary>
 /// 常指令参数解析
 /// </summary>
 /// <param name="constInstruction">常指令结构</param>
 /// <param name="instructionLine">常指令指令行</param>
 /// <param name="paramValueList">参数值列表</param>
 /// <exception cref="ConstInstructionParameterParseException"></exception>
 /// <returns></returns>
 public static string ConstInstructionParameterParse(ConstInstruction constInstruction, string instructionLine, List <string> paramValueList, bool constQuoteParse = true)
 {
     if (paramValueList.Count != constInstruction.parameterList.Count)
     {
         throw new ConstInstructionParameterParseException();
     }
     for (int i = 0; i < constInstruction.parameterList.Count; i++)
     {
         string value = paramValueList[i];
         if (constQuoteParse)
         {
             value = AConstQuote.ConstQuoteParse(value);
         }
         instructionLine = instructionLine.Replace(constInstruction.parameterList[i], value);
     }
     return(instructionLine);
 }