Beispiel #1
0
        public static void DumpSyntaxResult(String InputDirectory, String OutputDirectory)
        {
            var Files = new Dictionary <String, FileParserResult>();

            foreach (var FilePath in Directory.EnumerateFiles(InputDirectory, "*.tree", SearchOption.AllDirectories))
            {
                var AbsolutePath = FileNameHandling.GetAbsolutePath(FilePath, System.Environment.CurrentDirectory);
                var FileContent  = Txt.ReadFile(FilePath);
                var Text         = TokenParser.BuildText(FileContent, AbsolutePath);
                var Result       = FileParser.ParseFile(Text);
                Files.Add(AbsolutePath, Result);
            }

            //var arr = AmbiguousRemover.Reduce(Files, new List<String> { }, new TypeProvider());
            //if (arr.UnresolvableAmbiguousOrErrors.Count > 0)
            //{
            //    var l = new List<String> { };
            //    foreach (var p in arr.UnresolvableAmbiguousOrErrors)
            //    {
            //        var ErrorMessage = p.Key;
            //        var ErrorRange = p.Value;
            //        l.Add(p.Key + ": " + ErrorRange.Text.Path + (ErrorRange.Range.OnSome ? ": " + ErrorRange.Range.Value.ToString() : ""));
            //    }
            //    var OutputPath = FileNameHandling.GetPath(OutputDirectory, "Error.txt");
            //    var OutputDir = FileNameHandling.GetFileDirectory(OutputPath);
            //    if (!Directory.Exists(OutputDir)) { Directory.CreateDirectory(OutputDir); }
            //    Txt.WriteFile(OutputPath, String.Join("\r\n", l) + "\r\n");
            //    return;
            //}
            //Files = arr.Files;

            foreach (var p in Files)
            {
                var RelativePath = FileNameHandling.GetRelativePath(p.Key, FileNameHandling.GetAbsolutePath(InputDirectory, System.Environment.CurrentDirectory));
                var FileName     = FileNameHandling.GetFileName(p.Key);
                var fd           = new FileDumper();
                var Comment
                    = "==========================================================================" + "\r\n"
                      + "\r\n"
                      + "  SourceFile:  " + FileName + "\r\n"
                      + "\r\n"
                      + "==========================================================================";
                var f          = fd.Dump(p.Value, Comment);
                var OutputPath = FileNameHandling.GetPath(FileNameHandling.GetPath(OutputDirectory, FileNameHandling.GetFileDirectory(RelativePath)), FileNameHandling.GetMainFileName(FileName) + ".syn.tree");
                var OutputDir  = FileNameHandling.GetFileDirectory(OutputPath);
                if (!Directory.Exists(OutputDir))
                {
                    Directory.CreateDirectory(OutputDir);
                }
                TreeFile.WriteRaw(OutputPath, f);
            }
        }
Beispiel #2
0
        public static void ExportCollection(String ConnectionString, String DataDir, List <String> ExportEntityNames)
        {
            var bs = Niveum.ObjectSchema.BinarySerializerWithString.Create();

            var Pair     = LoadData(ConnectionString, bs);
            var s        = Pair.Key;
            var Value    = Pair.Value;
            var Entities = s.Types.Where(t => t.OnEntity).Select(t => t.Entity).ToList();

            HashSet <String> ExportEntityNameSet = null;

            if (ExportEntityNames.Count != 0)
            {
                ExportEntityNameSet = new HashSet <String>(ExportEntityNames.Distinct(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
            }

            var Dir = FileNameHandling.GetAbsolutePath(DataDir, Environment.CurrentDirectory);

            if (Dir != "" && !Directory.Exists(Dir))
            {
                Directory.CreateDirectory(Dir);
            }

            var rvts = new RelationValueTreeSerializer(s);

            foreach (var p in Entities.ZipStrict(Value.Tables, (a, b) => new KeyValuePair <EntityDef, TableVal>(a, b)))
            {
                var e  = p.Key;
                var tv = p.Value;
                if ((ExportEntityNameSet == null) || (ExportEntityNameSet.Contains(e.Name)))
                {
                    var l = rvts.WriteTable(e, tv);
                    var t = RelationValueSyntaxTreeBuilder.BuildTable(e, l);

                    var TreeFilePath = FileNameHandling.GetPath(DataDir, e.Name + ".tree");
                    TreeFile.WriteRaw(TreeFilePath, new Syntax.Forest {
                        MultiNodesList = new List <Syntax.MultiNodes> {
                            t
                        }
                    });
                }
            }
        }
Beispiel #3
0
        public static void Write(StreamWriter sw, EntityMappingDiff d)
        {
            var Lines = new List <Syntax.TextLine>();
            Action <List <String> > AddLine = Tokens =>
            {
                var Text = String.Join(" ", Tokens.Select(t => t == null ? "$Empty" : TreeFormatLiteralWriter.GetLiteral(t, true, false).SingleLine));
                Lines.Add(new Syntax.TextLine {
                    Text = Text, Range = new Syntax.TextRange {
                        Start = new Syntax.TextPosition {
                            Row = 1, Column = 1, CharIndex = 0
                        }, End = new Syntax.TextPosition {
                            Row = 1, Column = 1 + Text.Length, CharIndex = Text.Length
                        }
                    }
                });
            };
            Action <List <String> > AddCommentLine = Tokens =>
            {
                var Text = "//" + String.Join(" ", Tokens.Select(t => t == null ? "$Empty" : TreeFormatLiteralWriter.GetLiteral(t, true, false).SingleLine));
                Lines.Add(new Syntax.TextLine {
                    Text = Text, Range = new Syntax.TextRange {
                        Start = new Syntax.TextPosition {
                            Row = 1, Column = 1, CharIndex = 0
                        }, End = new Syntax.TextPosition {
                            Row = 1, Column = 1 + Text.Length, CharIndex = Text.Length
                        }
                    }
                });
            };

            foreach (var m in d.Mappings)
            {
                if (m.Method.OnNew)
                {
                    AddLine(new List <String> {
                        "Entity", m.EntityName, "New"
                    });
                }
                else if (m.Method.OnCopy)
                {
                    AddLine(new List <String> {
                        "Entity", m.EntityName, "From", m.Method.Copy
                    });
                }
                else if (m.Method.OnField)
                {
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            foreach (var m in d.Mappings)
            {
                if (m.Method.OnNew)
                {
                }
                else if (m.Method.OnCopy)
                {
                }
                else if (m.Method.OnField)
                {
                    var f = m.Method.Field;
                    if (f.Method.OnNew)
                    {
                        AddLine(new List <String> {
                            "Entity", m.EntityName, "Field", f.FieldName, "New", GetPrimitiveValString(f.Method.New)
                        });
                    }
                    else if (f.Method.OnCopy)
                    {
                        AddLine(new List <String> {
                            "Entity", m.EntityName, "Field", f.FieldName, "From", f.Method.Copy
                        });
                    }
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            foreach (var de in d.DeletedEntities)
            {
                AddCommentLine(new List <String> {
                    "Entity", de, "Delete"
                });
            }
            foreach (var de in d.DeletedFields)
            {
                foreach (var df in de.Value)
                {
                    AddCommentLine(new List <String> {
                        "Entity", de.Key, "Field", df, "Delete"
                    });
                }
            }

            var AlterNode = Syntax.MultiNodes.CreateFunctionNodes(new Syntax.FunctionNodes {
                FunctionDirective = new Syntax.FunctionDirective {
                    Text = "Map"
                }, Parameters = new List <Syntax.Token> {
                }, Content = new Syntax.FunctionContent {
                    IndentLevel = 0, Lines = Lines
                }
            });

            TreeFile.WriteRaw(sw, new Syntax.Forest {
                MultiNodesList = new List <Syntax.MultiNodes> {
                    AlterNode
                }
            });
        }