Example #1
0
        private string Evaluate(string text)
        {
            PreprocTokenizer preproc = new PreprocTokenizer(text);
            for (int index = 0; index < preproc.Count; ++index)
            {
                string token = preproc[index];
                if (Processor.PreProcMacros.ContainsKey(token))
                {
                    PreprocMacro macro = Processor.PreProcMacros[token];
                    if (macro.HasArguments)
                    {
                        // check to see if the arguments are found
                        Dictionary<string, string> ArgumentValues = new Dictionary<string, string>();
                        int nNextIndex = ExtractArguments(macro, preproc, index + 2, ArgumentValues);
                        if (nNextIndex > 0)
                        {
                            while (nNextIndex >= index)
                            {
                                preproc.RemoveAt(nNextIndex--);
                            }

                            // insert definition of macro, replacing the arguments as specified
                            macro.Expand(preproc, index, ArgumentValues);
                        }
                        else
                        {
                            Trace.TraceError("Warning: Unable to expand macro.\r\nText = '{0}'.\r\nFile = {1} [Line {2}]", text, Filename, Line);
                            return text;
                        }
                    }
                    else
                    {
                        preproc[index] = macro.Definition;
                    }
                }
            }
            return preproc.Join();
        }