示例#1
0
        static void ParseVars(Dictionary <int, List <Token> > line2Tokens, int startLine, int endLine,
                              ref List <FCodeLuaFunction> functions, ref FCodeLogic logic)
        {
            FCodeWindow w = EditorWindow.GetWindow <FCodeWindow>();
            Dictionary <string, string> fcodeSignature = w.fcodeSignature;
            var isVarsStarted = false;

            for (int currentLine = startLine + 1; currentLine < endLine; currentLine++)
            {
                if (line2Tokens.TryGetValue(currentLine, out List <Token> lineContent))
                {
                    // ** 从签名开始处
                    if (!isVarsStarted)
                    {
                        isVarsStarted = ValidSignature(lineContent, fcodeSignature, "VarsStart");
                        continue;
                    }
                    else if (ValidSignature(lineContent, fcodeSignature, "VarsStart"))
                    {
                        Error("重复的FCodeSignature:Vars:Start签名??");
                    }
                    // ** 把签名中的所有函数都加到vars中
                    var f = functions?.Find(luaFunc => luaFunc.fileStartLine == currentLine);
                    if (f != null)
                    {
                        logic.vars.Add(f);
                    }

                    // ** 到签名结束
                    if (ValidSignature(lineContent, fcodeSignature, "VarsEnd"))
                    {
                        isVarsStarted = false;
                    }
                }
            }
        }
示例#2
0
        static void ParseSingleLogic(Dictionary <int, List <Token> > line2Tokens, int startLine, int endLine, ref List <FCodeLuaFunction> functions, ref FCodeLogic logic)
        {
            FCodeWindow w = EditorWindow.GetWindow <FCodeWindow>();
            Dictionary <string, string> fcodeSignature = w.fcodeSignature;
            var              isSingleLogicStarted      = false;
            FCodeTiming      timing = 0;
            FCodeLuaFunction command = null, condition = null;

            for (int currentLine = startLine + 1; currentLine < endLine; currentLine++)
            {
                if (line2Tokens.TryGetValue(currentLine, out List <Token> lineContent))
                {
                    // ** 从签名开始处
                    if (!isSingleLogicStarted)
                    {
                        isSingleLogicStarted = ValidSignature(lineContent, fcodeSignature, "SingleLogicStart");
                        continue;
                    }
                    else if (ValidSignature(lineContent, fcodeSignature, "SingleLogicStart"))
                    {
                        Error("重复的FCodeSignature:SingleLogic:Start签名??");
                    }

                    // ** 从签名开始的下一行 直到签名结束的行内容都会在此处解析
                    var s = lineContent[0].Original();
                    switch (s)
                    {
                    case "timing":
                        var end = lineContent.Find(item => item.Original() == "FCodeTiming");
                        if (end != null)
                        {
                            var index = lineContent.IndexOf(end);
                            if (!Enum.TryParse(lineContent[index + 2].Original(), out timing))
                            {
                                Error($"解析FCodeTiming字符串出错 未定义的 {lineContent[index + 2].Original()}??");
                            }
                        }
                        else
                        {
                            Error("timing 字段中 未找到FCodeTiming关键字??");
                        }
                        break;

                    case "command":
                        command = functions?.Find(luaFunc => luaFunc.fileStartLine == currentLine);
                        break;

                    case "condition":
                        condition = functions?.Find(luaFunc => luaFunc.fileStartLine == currentLine);
                        break;
                    }

                    // ** 到签名结束
                    if (ValidSignature(lineContent, fcodeSignature, "SingleLogicEnd"))
                    {
                        isSingleLogicStarted = false;
                        var singleLogic = new FCodeLogic.SingleLogic(timing, command ?? GenFunction("command"), condition ?? GenFunction("condition"));
                        command   = null;
                        condition = null;
                        logic.logicList.Add(singleLogic);
                    }
                }
            }
        }