Example #1
0
        public static Project Build(string projectRoot, params string[] classPaths)
        {
            var myParser = new TypeLuaParser();

            myParser.Setup();

            var project = new Project(projectRoot);

            projectRoot = projectRoot + "\\";

            Types.Class        tlClass = null;
            List <Types.Class> classes = new List <Types.Class>();

            try
            {
                foreach (var classPath in classPaths)
                {
                    var path = classPath.Replace(projectRoot, "");
                    path = path.Replace("\\", "/");
                    var extension = Path.GetExtension(path);
                    if (extension == ".tl")
                    {
                        tlClass = new Types.Class(project, path.Substring(0, path.Length - 3));
                        var readAllText = File.ReadAllText(classPath);

                        myParser.Parse(new StringReader(readAllText), project, tlClass);
                        classes.Add(tlClass);
                    }
                    else if (extension == ".lua")
                    {
                        var luafile = new Luafile(project, path.Substring(0, path.Length - 4));
                        project.luafiles[luafile.FullName] = luafile;
                    }
                }

                var classParser = new ClassParser();

                for (int i = 0; i < classes.Count; i++)
                {
                    tlClass = classes[i];
                    tlClass.Packages.PackageList.BuildPackageContext(tlClass.Packages);
                }

                for (int i = 0; i < classes.Count; i++)
                {
                    tlClass = classes[i];
                    classParser.BuildGlobalContext(tlClass);
                }

                for (int i = 0; i < classes.Count; i++)
                {
                    tlClass = classes[i];
                    classParser.ClarifyType(tlClass);
                }

                for (int i = 0; i < classes.Count; i++)
                {
                    tlClass = classes[i];
                    classParser.TypeVerify(tlClass);
                }
            }
            catch (FileParseException e)
            {
                e.FileName = tlClass.ClassPath;
                Console.WriteLine(e.StackTrace);
                throw e;
            }

            return(project);
        }