Example #1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }

            string rootPath = args[0];
            string format   = args[1];

            // Log.ApplyDefaultsForConsoleApplication();

            try
            {
                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    FileSpecification specification = new FileSpecification
                                                      (
                        IrbisPath.MasterFile,
                        provider.Database,
                        format
                                                      );
                    string source = provider.ReadFile(specification);
                    if (string.IsNullOrEmpty(source))
                    {
                        Console.WriteLine("No file: {0}", format);
                    }
                    else
                    {
                        PftContext context = new PftContext(null);
                        context.SetProvider(provider);
                        PftFormatter formatter = new PftFormatter(context);
                        formatter.ParseProgram(source);

                        PftProgram       program = formatter.Program;
                        AbstractOutput   console = new ConsoleOutput();
                        PftPrettyPrinter printer = new PftPrettyPrinter();
                        console.WriteLine(string.Empty);
                        console.WriteLine(new string('=', 60));
                        console.WriteLine(string.Empty);
                        console.WriteLine(string.Empty);
                        program.PrettyPrint(printer);
                        console.WriteLine(printer.ToString());
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Example #2
0
        private void ParseHtml()
        {
            string       recordText = _recordBox.Text;
            StringReader reader     = new StringReader(recordText);

            _record = PlainText.ReadRecord(reader);
            _recordGrid.SetRecord(_record);

            PftHtmlFormatter formatter = new PftHtmlFormatter();

            formatter.ParseProgram(_pftBox.Text);
            _program = formatter.Program;
            _pftTreeView.SetNodes(_program);
        }
Example #3
0
        private static PftFormatter _GetFormatter
        (
            [NotNull] PftProgram program
        )
        {
            PftFormatter result = new PftFormatter
            {
                Program = program
            };
            LocalProvider provider = (LocalProvider)result.Context.Provider;

            provider.FallForwardPath = ".";

            return(result);
        }
Example #4
0
        private static string _GetTitle
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_titleProgram, null))
            {
                string source = File.ReadAllText("title.pft", IrbisEncoding.Ansi);
                _titleProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_titleProgram);
            string       result    = formatter.FormatRecord(record);

            return(result.Limit(250));
        }
Example #5
0
        public FstItem
        (
            ManagedClient64 client,
            string format
        )
            : this()
        {
            Format = format;
            PftFormatter formatter = new PftFormatter
            {
                Context = { Client = client }
            };

            formatter.ParseInput(format);
            Program = formatter.Program;
        }
Example #6
0
        private void Parse()
        {
            string       recordText = _recordBox.Text;
            StringReader reader     = new StringReader(recordText);

            _record = PlainText.ReadRecord(reader);
            if (!ReferenceEquals(_record, null))
            {
                _record.Mfn = 1; // TODO some other value?
            }
            _recordGrid.SetRecord(_record);

            PftLexer lexer = new PftLexer();

            _tokenList = lexer.Tokenize(_pftBox.Text);

            _tokenGrid.SetTokens(_tokenList);

            PftParser parser = new PftParser(_tokenList);

            _program = parser.Parse();
            _pftTreeView.SetNodes(_program);
        }
Example #7
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                return;
            }

            string rootPath = args[0];
            string fileName = args[1];
            string format   = args[2];

            Log.ApplyDefaultsForConsoleApplication();

            try
            {
                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    FileSpecification specification = new FileSpecification
                                                      (
                        IrbisPath.MasterFile,
                        provider.Database,
                        format
                                                      );
                    string source = provider.ReadFile(specification);
                    if (string.IsNullOrEmpty(source))
                    {
                        Console.WriteLine("No file: {0}", format);
                    }
                    else
                    {
                        PftContext context = new PftContext(null);
                        context.SetProvider(provider);
                        PftFormatter formatter = new PftFormatter(context);
                        formatter.ParseProgram(source);

                        PftSerializer.Save(formatter.Program, fileName);

                        PftProgram program
                            = (PftProgram)PftSerializer.Read(fileName);

                        PftSerializationUtility.VerifyDeserializedProgram
                        (
                            formatter.Program,
                            program
                        );

                        PftNodeInfo nodeInfo = program.GetNodeInfo();

                        AbstractOutput console = new ConsoleOutput();
                        PftNodeInfo.Dump(console, nodeInfo, 0);

                        byte[] bytes
                            = PftSerializer.ToMemory(formatter.Program);

                        for (int i = 0; i < 10000; i++)
                        {
                            PftProgram restoredProgram
                                = (PftProgram)PftSerializer.FromMemory(bytes);
                            console.WriteLine("{0}", i + 1);
                            //console.WriteLine(restoredProgram.ToString());
                        }

                        PftPrettyPrinter printer = new PftPrettyPrinter();
                        program.PrettyPrint(printer);
                        console.WriteLine(printer.ToString());
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }

            string rootPath   = args[0];
            string formatName = args[1];

            try
            {
                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    FileSpecification specification = new FileSpecification
                                                      (
                        IrbisPath.MasterFile,
                        provider.Database,
                        formatName
                                                      );
                    string source = provider.ReadFile(specification);
                    if (string.IsNullOrEmpty(source))
                    {
                        Console.WriteLine("No file: {0}", formatName);
                    }
                    else
                    {
                        PftContext context = new PftContext(null);
                        context.SetProvider(provider);
                        PftFormatter formatter = new PftFormatter(context);
                        formatter.ParseProgram(source);

                        PftProgram program
                            = (PftProgram)formatter.Program.Clone();
                        program.Optimize();

                        //Console.WriteLine(program.DumpToText());
                        //Console.WriteLine();

                        if (!Directory.Exists("Out"))
                        {
                            Directory.CreateDirectory("Out");
                        }

                        PftCompiler compiler = new PftCompiler
                        {
                            Debug      = true,
                            KeepSource = true,
                            //OutputPath = "Out"
                            OutputPath = "."
                        };
                        compiler.SetProvider(provider);
                        string className = compiler.CompileProgram
                                           (
                            program
                                           );

                        //string sourceCode = compiler.GetSourceCode();
                        //Console.WriteLine(sourceCode);

                        AbstractOutput output       = AbstractOutput.Console;
                        string         assemblyPath = compiler.CompileToDll
                                                      (
                            output,
                            className
                                                      );
                        if (!ReferenceEquals(assemblyPath, null))
                        {
                            Console.WriteLine
                            (
                                "Compiled to {0}",
                                assemblyPath
                            );

                            MarcRecord record = provider.ReadRecord(1);

                            //if (!ReferenceEquals(record, null))
                            //{
                            //    Assembly assembly
                            //        = Assembly.LoadFile(assemblyPath);
                            //    Func<PftContext, PftPacket> creator
                            //        = CompilerUtility.GetEntryPoint(assembly);
                            //    PftPacket packet = creator(context);
                            //    string formatted = packet.Execute(record);
                            //    Console.WriteLine(formatted);

                            //    Stopwatch stopwatch = new Stopwatch();
                            //    stopwatch.Start();
                            //    for (int i = 0; i < 100000; i++)
                            //    {
                            //        if (i % 1000 == 0)
                            //        {
                            //            Console.WriteLine(i);
                            //        }
                            //        packet.Execute(record);
                            //    }
                            //    stopwatch.Stop();
                            //    Console.WriteLine(stopwatch.Elapsed);
                            //}

                            if (!ReferenceEquals(record, null))
                            {
                                using (RemoteFormatter remote
                                           = new RemoteFormatter(assemblyPath))
                                {
                                    PftPacket packet = remote.GetFormatter(context);
                                    Console.WriteLine(RemotingServices.IsTransparentProxy(packet));
                                    string formatted = packet.Execute(record);
                                    Console.WriteLine(formatted);

                                    Stopwatch stopwatch = new Stopwatch();
                                    stopwatch.Start();
                                    for (int i = 0; i < 100; i++)
                                    {
                                        if (i % 10 == 0)
                                        {
                                            Console.WriteLine(i);
                                        }
                                        packet.Execute(record);
                                    }
                                    stopwatch.Stop();
                                    Console.WriteLine(stopwatch.Elapsed);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Example #9
0
        private void CompileAndRun()
        {
            DatabaseInfo database = _databaseBox.SelectedItem
                                    as DatabaseInfo;

            if (!ReferenceEquals(database, null))
            {
                _provider.Database = database.Name
                                     .ThrowIfNull("database.Name");
            }

            PftContext context = new PftContext(null);

            context.SetProvider(_provider);
            PftProgram program = (PftProgram)_program.Clone();

            program.Optimize();

            if (!Directory.Exists("Out"))
            {
                Directory.CreateDirectory("Out");
            }

            PftCompiler compiler = new PftCompiler
            {
                Debug      = true,
                KeepSource = true,
                OutputPath = "Out"
            };

            compiler.SetProvider(_provider);
            string         className    = compiler.CompileProgram(program);
            AbstractOutput output       = new TextOutput();
            string         assemblyPath = compiler.CompileToDll
                                          (
                output,
                className
                                          );
            string result = output.ToString();

            if (!ReferenceEquals(assemblyPath, null))
            {
                Assembly assembly
                    = Assembly.LoadFile(assemblyPath);
                Func <PftContext, PftPacket> creator
                    = CompilerUtility.GetEntryPoint(assembly);
                PftPacket packet = creator(context);
                result = packet.Execute(_record);
            }

            _resutlBox.Text = result;
            try
            {
                _rtfBox.Rtf = result;
            }
            catch
            {
                _rtfBox.Text = result;
            }

            if (ReferenceEquals(_htmlBox.Document, null))
            {
                _htmlBox.Navigate("about:blank");
                while (_htmlBox.IsBusy)
                {
                    Application.DoEvents();
                }
            }
            if (!ReferenceEquals(_htmlBox.Document, null))
            {
                _htmlBox.Document.Write(result);
            }
            try
            {
                _htmlBox.DocumentText =
                    "<html>"
                    + result
                    + "</html>";
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // Nothing to do
            }

            _recordGrid.SetRecord(_record);
        }