Exemple #1
0
        public List <ClassExpression> parse(FunctionDescriptionSheet funcSheet, MyLog myLog)
        {
            // parseOneFile title row
            Excel.Range xlRange     = funcSheet.getSheet().UsedRange;
            int         rowCount    = xlRange.Rows.Count;
            int         columnCount = xlRange.Columns.Count;

            Excel.Range firstRow = funcSheet.getSheet().Rows[1];
            setColumnIndex(firstRow, myLog, ref columnCount);
            if (columnCount < 0)
            {
                return(null);
            }

            List <ClassExpression> classExpressions = new List <ClassExpression>();
            ClassExpression        classExpression  = new ClassExpression();

            for (int fi = 2; fi <= rowCount; fi++)
            {
                Excel.Range row      = funcSheet.getSheet().Rows[fi];
                string      funcName = getValueCell(row, FUNCTION_NAME_COLUMN_INDEX);
                // indicate end sheet
                if (funcName == null || funcName.Equals(""))
                {
                    break;
                }
                string workspace      = getValueCell(row, WORKSPACE_COLUMN_INDEX);
                string _class         = getValueCell(row, CLASS_COLUMN_INDEX);
                string accessibility  = getValueCell(row, ACCESSIBILITY_COLUMN_INDEX);
                string summary        = getValueCell(row, SUMMARY_COLUMN_INDEX);
                string parameters     = getValueCell(row, PARAMETERS_COLUMN_INDEX);
                string _returns       = getValueCell(row, RETURNS_COLUMN_INDEX);
                string implementation = getValueCell(row, IMPLEMENTATION_COLUMN_INDEX);

                string last_workspace = workspace == null || workspace.Equals("") ?
                                        classExpression.getWorkspace() : workspace;
                string last_class = _class == null || _class.Equals("") ?
                                    classExpression.getName() : _class;
                if (last_workspace == null || last_workspace.Equals(""))
                {
                    myLog.Warn("Not know workspace for row #" + (fi + 1) +
                               " in \"" + funcSheet.getSheet().Name + "\" sheet", logger);
                }
                if (last_class == null || last_workspace.Equals(""))
                {
                    myLog.Warn("Not know workspace for row #" + (fi + 1) +
                               " in \"" + funcSheet.getSheet().Name + "\" sheet", logger);
                }
                if (workspace != null && !workspace.Equals("") ||
                    (_class != null && !_class.Equals("")))
                {
                    classExpression = new ClassExpression(last_workspace, last_class);
                    classExpressions.Add(classExpression);
                }
                List <ParameterExpression> _params = parseParams(parameters, myLog);
                FunctionExpression         funcEpx = new FunctionExpression(
                    funcName, accessibility, summary, _params);
                funcEpx.setReturnDescription(_returns);
                funcEpx.setContent(implementation);

                if (classExpression.getListFunction() == null)
                {
                    classExpression.setListFunction(new List <FunctionExpression>());
                }
                classExpression.getListFunction().Add(funcEpx);
            }
            return(classExpressions);
        }
 public virtual ScriptsExpression HandleAndGenScripts(IScriptGenerationParams scriptGenerationParams, ScriptType scriptType = ScriptType.Normal)
 {
     if (scriptGenerationParams is UserCodeScriptGenerationParams ucParams)
     {
         Regex regex = new Regex("(?<class_group>.*?)\\.(?<func_group>.*)");
         Match match = regex.Match(expression);
         if (match.Success)
         {
             string   className   = match.Groups["class_group"].Value;
             string   funcName    = match.Groups["func_group"].Value;
             Regex    regex2      = new Regex("(?<func_group>.*)\\((?<params_group>.*)\\)$");
             Match    match2      = regex2.Match(funcName);
             int      paramsCount = 0;
             string[] _params     = null;
             if (match2.Success && match2.Groups["params_group"] != null &&
                 match2.Groups["params_group"].Value.Trim() != "")
             {
                 funcName    = match2.Groups["func_group"].Value;
                 _params     = match2.Groups["params_group"].Value.Split(',');
                 paramsCount = _params.Count();
             }
             bool voidReturn = true;
             if (Regex.IsMatch(ucParams.SpecNode.Expression, USER_CODE_WITH_VARIABLE_DECLARE))
             {
                 voidReturn = false;
             }
             else if (!Regex.IsMatch(ucParams.SpecNode.Expression, AbstractSpecUserAction.USER_CODE))
             {
                 logger.Error("Incorrect Expression: " + ucParams.SpecNode.Expression);
             }
             var re   = new UserCodeScriptsExpression();
             var pair = CheckFunctionExisted(ucParams.ClassExpressions, className, funcName, paramsCount, voidReturn);
             if (!pair.Item1)
             {
                 FunctionExpression func = new FunctionExpression(funcName);
                 if (_params != null)
                 {
                     foreach (string param in _params)
                     {
                         ParameterExpression parameterExpression = new ParameterExpression();
                         parameterExpression.setName(param);
                         if (func.getParams() == null)
                         {
                             func.setParams(new List <ParameterExpression>());
                         }
                         func.getParams().Add(parameterExpression);
                     }
                 }
                 func.setReturnDescription("no description");
                 ClassExpression classExpExisted = pair.Item2;
                 // if  class existed
                 if (classExpExisted != null)
                 {
                     Utils.MergeFunctions(classExpExisted.getListFunction(), func);
                 }
                 else
                 {
                     re.AppendNewAdditionFunc(className, func);
                 }
             }
             DoGenRawScripts(className, funcName, _params, voidReturn, ucParams, re, scriptType);
             return(re);
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     else
     {
         throw new NotImplementedException();
     }
 }