コード例 #1
0
        void tokenize_file(SourceFile sourceFile, ModuleContainer module, ParserSession session)
        {
            Stream input = null;
            SeekableStreamReader reader = null;

            try {
                if (sourceFile.GetInputStream != null)
                {
                    reader = sourceFile.GetInputStream(sourceFile);
                    if (reader == null)
                    {
                        throw new FileNotFoundException("Delegate returned null", sourceFile.Name);
                    }
                }
                else
                {
                    input = File.OpenRead(sourceFile.Name);
                }
            } catch {
                Report.Error(2001, "Source file `" + sourceFile.Name + "' could not be found");
                return;
            }

            if (reader == null)
            {
                using (input) {
                    reader = new SeekableStreamReader(input, ctx.Settings.Encoding);
                    DoTokenize(sourceFile, module, session, reader);
                }
            }
            else
            {
                DoTokenize(sourceFile, module, session, reader);
            }
        }
コード例 #2
0
        public void Parse(SourceFile file, ModuleContainer module, ParserSession session, Report report)
        {
            Stream input = null;
            SeekableStreamReader reader = null;

            try {
                if (file.GetInputStream != null)
                {
                    reader = file.GetInputStream(file);
                    if (reader == null)
                    {
                        throw new FileNotFoundException("Delegate returned null", file.Name);
                    }
                }
                else
                {
                    input = File.OpenRead(file.Name);
                }
            } catch {
                report.Error(2001, "Source file `{0}' could not be found", file.Name);
                return;
            }

            if (reader == null)
            {
                using (input) {
                    // Check 'MZ' header
                    if (input.ReadByte() == 77 && input.ReadByte() == 90)
                    {
                        report.Error(2015, "Source file `{0}' is a binary file and not a text file", file.Name);
                        return;
                    }

                    input.Position = 0;
                    reader         = new SeekableStreamReader(input, ctx.Settings.Encoding, session.StreamReaderBuffer);

                    DoParse(file, module, session, report, reader);
                }
            }
            else
            {
                DoParse(file, module, session, report, reader);
            }
        }