コード例 #1
0
ファイル: ParseHelper.cs プロジェクト: SimuPoLAS/Ofc
 /// <summary>
 ///     Parses the specified directory with the specified hook.
 /// </summary>
 /// <param name="target">Target source file.</param>
 /// <param name="hook">Target hook used by when parsing.</param>
 /// <param name="recursive">
 ///     If <c>true</c> all file in the directory will be compressed otherwise only top-level files will
 ///     be compressed.
 /// </param>
 internal static void ParseDirectory(string target, [CanBeNull] IParserHook <string> hook, bool recursive)
 {
     foreach (var file in Directory.EnumerateFiles(target, "*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
     {
         ParseFile(file, hook);
     }
 }
コード例 #2
0
ファイル: ParseHelper.cs プロジェクト: SimuPoLAS/Ofc
        /// <summary>
        ///     Parses the specified directory with the specified hook and returns if the amount of files that were successful.
        /// </summary>
        /// <param name="target">Target source file.</param>
        /// <param name="hook">Target hook used by when parsing.</param>
        /// <param name="recursive">
        ///     If <c>true</c> all file in the directory will be compressed otherwise only top-level files will
        ///     be compressed.
        /// </param>
        /// <returns>The amount of files that were successfully parsed.</returns>
        internal static int TryParseDirectory(string target, [CanBeNull] IParserHook <string> hook, bool recursive)
        {
            var a = 0;

            foreach (var file in Directory.EnumerateFiles(target, "*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
            {
                if (TryParseFile(file, hook))
                {
                    a++;
                }
            }
            return(a);
        }
コード例 #3
0
ファイル: ParseHelper.cs プロジェクト: SimuPoLAS/Ofc
 /// <summary>
 ///     Parses the specified file with the specified hook and returns if the parsing was successful.
 /// </summary>
 /// <param name="target">Target file.</param>
 /// <param name="hook">Target hook used when parsing.</param>
 /// <remarks>
 ///     If no hook is specified <see cref="EmptyHook{T}.Instance" /> will be use.
 /// </remarks>
 /// <returns>Returns <c>true</c> when the parsing was successful otherwise <c>false</c>.</returns>
 internal static bool TryParseFile(string target, [CanBeNull] IParserHook <string> hook)
 {
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target));
     }
     try
     {
         ParseFile(target, hook);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #4
0
ファイル: ParseHelper.cs プロジェクト: SimuPoLAS/Ofc
 /// <summary>
 ///     Parses the specified file with the specified hook.
 /// </summary>
 /// <param name="target">Target file.</param>
 /// <param name="hook">Target hook used when parsing.</param>
 /// <remarks>
 ///     If no hook is specified <see cref="EmptyHook{T}.Instance" /> will be use.
 /// </remarks>
 internal static void ParseFile(string target, [CanBeNull] IParserHook <string> hook)
 {
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target));
     }
     if (!File.Exists(target))
     {
         throw new FileNotFoundException("Could not find the specified file.", target);
     }
     using (var stream = new FileInputStream(target))
     {
         var lexer  = new OfcLexer(stream, true);
         var parser = new OfcParser(lexer, hook ?? EmptyHook <string> .Instance);
         parser.Parse();
     }
 }
コード例 #5
0
        public OfcParser([CanBeNull] IInputStream <OfcToken> input, [CanBeNull] IParserHook <string> hook, int bufferSize)
        {
            if (bufferSize < 64)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferSize));
            }

            /** set base members */
            _buffer   = new OfcToken[bufferSize];
            _eos      = input == null;
            _length   = 0;
            _position = 0;
            _size     = bufferSize;
            _source   = input;

            /** set parser members */
            _hook = hook ?? EmptyHook <string> .Instance;
        }
コード例 #6
0
 public OfcParser([CanBeNull] IInputStream <OfcToken> input, [CanBeNull] IParserHook <string> hook) : this(input, hook, 4096)
 {
 }