AGS.CScript.Compiler.Preprocessor.PreProcessDirective C# (CSharp) Method

PreProcessDirective() private method

private PreProcessDirective ( string line ) : string
line string
return string
        private string PreProcessDirective(string line)
        {
            line = line.Substring(1);
            string directive = GetNextWord(ref line);

            if ((directive == "ifdef") || (directive == "ifndef") ||
                (directive == "ifver") || (directive == "ifnver"))
            {
                ProcessConditionalDirective(directive, line, _results);
            }
            else if (directive == "endif")
            {
                if (_conditionalStatements.Count > 0)
                {
                    _conditionalStatements.Pop();
                }
                else
                {
                    RecordError(ErrorCode.EndIfWithoutIf, "#endif has no matching #if");
                }
            }
            else if (DeletingCurrentLine())
            {
                // allow the line to be deleted, we are inside a failed #ifdef
            }
            else if (directive == "define")
            {
                string macroName = GetNextWord(ref line);
                if (macroName.Length == 0)
                {
                    RecordError(ErrorCode.MacroNameMissing, "Macro name expected");
                    return string.Empty;
                }
                else if (Char.IsDigit(macroName[0]))
                {
                    RecordError(ErrorCode.MacroNameInvalid, "Macro name '" + macroName + "' cannot start with a digit");
                }
                else if (_state.Macros.Contains(macroName))
                {
                    RecordError(ErrorCode.MacroAlreadyExists, "Macro '" + macroName + "' is already defined");
                }
                else
                {
                    _state.Macros.Add(new Macro(macroName, line));
                }
            }
            else if (directive == "undef")
            {
                string macroName = GetNextWord(ref line);
                if (macroName.Length == 0)
                {
                    RecordError(ErrorCode.MacroNameMissing, "Macro name expected");
                }
                else if (!_state.Macros.Contains(macroName))
                {
                    RecordError(ErrorCode.MacroDoesNotExist, "Macro '" + macroName + "' is not defined");
                }
                else
                {
                    _state.Macros.Remove(macroName);
                }
            }
            else if (directive == "error")
            {
                RecordError(ErrorCode.UserDefinedError, "User error: " + line);
            }
            else if ((directive == "sectionstart") || (directive == "sectionend"))
            {
                // do nothing -- 2.72 put these as markers in the script
            }
            else if ((directive == "region") || (directive == "endregion"))
            {
                // do nothing -- scintilla can fold it, so it can be used to organize the code
            }
            else
            {
                RecordError(ErrorCode.UnknownPreprocessorDirective, "Unknown preprocessor directive '" + directive + "'");
            }

            return string.Empty;  // replace the directive with a blank line
        }