CSI.MacroSubstitutor.ProcessLine C# (CSharp) Method

ProcessLine() public method

public ProcessLine ( string line ) : string
line string
return string
        public string ProcessLine(string line)
        {
            Match m = define.Match(line);
            if (m.Success)
            {
                string[] parms = null;
                string sym = m.Groups[1].ToString();
                string subst = m.Groups[3].ToString();
                string arg = m.Groups[2].ToString();
                if (arg != "")
                {
                    arg = arg.ToString();
                    if (arg[0] == '(')
                    {
                        arg = arg.TrimEnd(null);
                        arg = arg.Substring(1, arg.Length - 2);
                        parms = arg.Split(new char[] { ',' });
                    }
                }
                AddMacro(sym, subst, parms);
                return "";
            }
            else
                return Substitute(line);
        }

Usage Example

        void ExecuteLine(string codeStr)
        {
            // at this point we either have a line to be immediately compiled and evaluated,
            // or a function definition.
            CHash  type = CHash.Expression;
            string className = null, assemblyName = null, funName = null;
            Match  funMatch = funDef.Match(codeStr);

            if (funMatch.Success)
            {
                type = CHash.Function;
            }
            if (type == CHash.Function)
            {
                funName = funMatch.Groups[1].ToString();
                macro.RemoveMacro(funName);
                className    = "Csi" + nextAssembly++;
                assemblyName = className + ".dll";
                codeStr      = codeStr.Insert(funMatch.Groups[1].Index, "_");
            }
            codeStr = macro.ProcessLine(codeStr);
            if (codeStr == "")  // may have been a prepro statement!
            {
                return;
            }
            bool wasAssignment;

            codeStr = MassageInput(codeStr, out wasAssignment);
            if (wasAssignment)
            {
                type = CHash.Assignment;
            }
            CompilerResults cr = CompileLine(codeStr.TrimStart(), type, assemblyName, className);

            if (cr != null)
            {
                Assembly ass = cr.CompiledAssembly;
                if (type != CHash.Function)
                {
                    CodeChunk.Instantiate(ass, this);
                }
                else
                {
                    CsiFunctionContext.Instantiate(ass, varTable, className, funName);
                    string prefix = mustDeclare ? "" : "$";
                    macro.AddMacro(funName, prefix + className + "._" + funName, null);
                    AddReference(Path.GetFullPath(assemblyName));
                }
            }
        }