コード例 #1
0
    public PythonScript(string filename, string content, PythonAst ast)
    {
        Filename  = filename;
        Namespace = "Scripts";
        ClassName = CreateClassName(Path.ChangeExtension(filename, null));
        Content   = content;
        AST       = ast;

        Type       = ScriptType.Module;
        ScriptId   = -1;
        OutputPath = ClassName + ".cs";

        // Check if the filename matches the pattern for "attached" scripts that will contain san_ events.
        var match = PythonScriptNamePattern.Match(filename);

        if (match.Success)
        {
            Type       = ScriptType.Object;
            ScriptId   = int.Parse(match.Groups[1].Value);
            ClassName  = CreateClassName(match.Groups[2].Value);
            OutputPath = ClassName + ".cs";
            Namespace  = "Scripts";
        }
        else
        {
            match = SpellNamePattern.Match(filename);
            if (match.Success)
            {
                Type       = ScriptType.Spell;
                SpellId    = int.Parse(match.Groups[1].Value);
                ClassName  = CreateClassName(match.Groups[2].Value);
                OutputPath = "Spells/" + ClassName + ".cs";
                Namespace  = "Scripts.Spells";
            }
        }

        // Find imported modules
        var importedWalker = new ImportedModulesWalker();

        ast.Walk(importedWalker);
        ImportedModules = importedWalker.ImportedModules;
        ImportedModules.Remove("toee");
        ImportedModules.Remove("__main__");
        ImportedModules.Remove("math");
        ImportedModules.Remove("sys");
        ImportedModules.Remove("array");
        ImportedModules.Remove("t"); // because it has a circular dependency
        ImportedModules.Remove("co8Util");
        ImportedModules.Remove("co8Util.Logger");
        ImportedModules.Remove("co8Util.PersistentData");
        ImportedModules.Remove("co8Util.TimedEvent");
        ImportedModules.Remove("co8Util.ObjHandling");
        ImportedModules.Remove("co8Util.Enum");
        ImportedModules.Remove("_include"); // Co8 hack
        if (ModuleName != "utilities")
        {
            ImportedModules.Add("utilities"); // Implicitly imported by C++ code into __main__
        }
    }
コード例 #2
0
        // basic checks (only for checking name conflicts)

        public void CheckCommonNamesConflicts(string name, int line, int column)
        {
            if (Classes.ContainsKey(name) || Routines.ContainsKey(name) || Fields.ContainsKey(name) || ImportedModules.Contains(name) || ModuleData.Name == name)
            {
                ThrowConflictNameException(ModuleData.File, line, column);
            }
        }
コード例 #3
0
 public void Remove(IEnumerable <ImportedModule> newImports)
 {
     this.ImportedModules = ImportedModules.Where(i => !newImports.Any(removed => removed.Equals(i))).ToList();
 }