public GrapeCodeGeneratorConfiguration(GrapeAst ast, bool outputErrors, bool continueOnError, bool generateCode) {
     this.ast = ast;
     this.outputErrors = outputErrors;
     this.continueOnError = continueOnError;
     this.generateCode = generateCode;
     this.outputCode = "";
 }
Ejemplo n.º 2
0
 public static GrapeAst Merge(GrapeAst left, GrapeAst right) {
     List<GrapeEntity> mergedChildren = new List<GrapeEntity>();
     mergedChildren.AddRange(left.Children);
     mergedChildren.AddRange(right.Children);
     GrapeAst ast = new GrapeAst();
     ast.children = mergedChildren;
     return ast;
 }
Ejemplo n.º 3
0
        private void PopulatePackageFileNames(GrapeAst ast)
        {
            if (lastAst != ast) {
                packageFileNames.Clear();
                foreach (GrapePackageDeclaration packageDeclaration in GetEntitiesOfType(ast, typeof(GrapePackageDeclaration))) {
                    if (!packageFileNames.ContainsKey(packageDeclaration.PackageName)) {
                        List<string> list = new List<string>();
                        list.Add(packageDeclaration.FileName);
                        packageFileNames.Add(packageDeclaration.PackageName, list);
                    } else {
                        packageFileNames[packageDeclaration.PackageName].Add(packageDeclaration.FileName);
                    }
                }

                lastAst = ast;
            }
        }
Ejemplo n.º 4
0
        public GrapeClass GetClassWithNameFromImportedPackagesInFile(GrapeAst ast, string className, string fileName)
        {
            PopulatePackageFileNames(ast);
            List<string> importedPackageFiles = new List<string>();
            IEnumerable<GrapeEntity> importDeclarationsInFile = GetEntitiesOfTypeInFile(ast, fileName, typeof(GrapeImportDeclaration));
            foreach (GrapeImportDeclaration importDeclaration in importDeclarationsInFile) {
                foreach (KeyValuePair<string, List<string>> pair in packageFileNames) {
                    if (pair.Key == importDeclaration.PackageName) {
                        foreach (string packageFileName in pair.Value) {
                            importedPackageFiles.Add(packageFileName);
                        }
                    }
                }
            }

            IList<string> packagesInTypeName = GetSegmentsInQualifiedId(className, true);
            string actualTypeName = packagesInTypeName[packagesInTypeName.Count - 1];
            string actualPackageName = "";
            for (int i = 0; i < packagesInTypeName.Count - 1; i++) {
                actualPackageName += packagesInTypeName[i] + ".";
            }

            actualPackageName = actualPackageName.Trim('.');
            IEnumerable<GrapeEntity> packagesInFile = GetEntitiesOfTypeInFile(ast, fileName, typeof(GrapePackageDeclaration));
            foreach (GrapePackageDeclaration packageDeclaration in packagesInFile) {
                foreach (KeyValuePair<string, List<string>> pair in packageFileNames) {
                    if (pair.Key == packageDeclaration.PackageName) {
                        IEnumerable<string> otherPackagesInPackage = GetOtherPackagesInPackageName(packageDeclaration.PackageName);
                        foreach (string otherPackage in otherPackagesInPackage) {
                            foreach (KeyValuePair<string, List<string>> childPair in packageFileNames) {
                                if (childPair.Key == otherPackage) {
                                    importedPackageFiles.AddRange(childPair.Value);
                                }
                            }
                        }

                        importedPackageFiles.AddRange(pair.Value);
                    }
                }
            }

            foreach (string importedPackageFile in importedPackageFiles) {
                IEnumerable<GrapeEntity> classes = GetEntitiesOfTypeInFile(ast, importedPackageFile, typeof(GrapeClass));
                foreach (GrapeClass c in classes) {
                    if (c.Name == className) {
                        return c;
                    }
                }
            }

            IEnumerable<GrapeEntity> packages = GetEntitiesOfType(ast, typeof(GrapePackageDeclaration));
            IEnumerable<GrapeEntity> allClasses = GetEntitiesOfType(ast, typeof(GrapeClass));
            foreach (GrapePackageDeclaration packageDeclaration in packages) {
                if (packageDeclaration.PackageName == actualPackageName) {
                    foreach (GrapeClass c in allClasses) {
                        if (c.Name == actualTypeName) {
                            return c;
                        }
                    }
                }
            }

            return null;
        }
Ejemplo n.º 5
0
 public IEnumerable<GrapeEntity> GetEntitiesOfTypeInFile(GrapeAst ast, string fileName, Type type)
 {
     return GetChildrenRecursive(ast.Children, delegate(GrapeEntity e) {
         return e.GetType() == type && e.FileName == fileName;
     });
 }
Ejemplo n.º 6
0
 public IEnumerable<GrapeEntity> GetEntitiesOfType(GrapeAst ast, Type type)
 {
     return GetChildrenRecursive(ast.Children, delegate(GrapeEntity e) {
         return e.GetType() == type;
     });
 }