コード例 #1
0
 /// <summary>
 /// Constructs a instance of the uglification options
 /// </summary>
 public UglificationOptions()
 {
     ParsingOptions = new ParsingOptions();
     CompressionOptions = new CompressionOptions();
     ManglingOptions = new ManglingOptions();
     CodeGenerationOptions = new CodeGenerationOptions();
     ScrewIe8 = false;
     KeepFunctionNames = false;
     Severity = 0;
 }
コード例 #2
0
        /// <inheritdoc />
        public Task <Possible <ISourceFile> > TryParseAsync(AbsolutePath pathToParse, AbsolutePath moduleOrConfigPathPromptingParse, ParsingOptions parsingOption = null)
        {
            Contract.Assume(m_descriptorsBySpecPath != null, "Init must have been called");

            var pathToParseAsString = pathToParse.ToString(m_context.PathTable);

            if (!m_descriptorsBySpecPath.TryGetValue(pathToParse, out var descriptor))
            {
                return(Task.FromResult <Possible <ISourceFile> >(new SpecNotOwnedByResolverFailure(pathToParseAsString)));
            }

            if (!Downloads.TryGetValue(descriptor.Name, out var downloadData))
            {
                Contract.Assert(false, "Inconsistent internal state of NugetWorkspaceResolver");
                return(Task.FromResult <Possible <ISourceFile> >(new SpecNotOwnedByResolverFailure(pathToParseAsString)));
            }

            var sourceFile = SourceFile.Create(pathToParseAsString);

            var downloadDeclaration = new VariableDeclaration("download", Identifier.CreateUndefined(), new TypeReferenceNode("File"));

            downloadDeclaration.Flags |= NodeFlags.Export | NodeFlags.Public | NodeFlags.ScriptPublic;
            downloadDeclaration.Pos    = 1;
            downloadDeclaration.End    = 2;

            var extractedDeclaration = new VariableDeclaration("extracted", Identifier.CreateUndefined(), new TypeReferenceNode("StaticDirectory"));

            extractedDeclaration.Flags |= NodeFlags.Export | NodeFlags.Public | NodeFlags.ScriptPublic;
            extractedDeclaration.Pos    = 3;
            extractedDeclaration.End    = 4;

            sourceFile.Statements.Add(
                new VariableStatement()
            {
                DeclarationList = new VariableDeclarationList(
                    NodeFlags.Const,
                    downloadDeclaration,
                    extractedDeclaration)
            }
                );

            // Needed for the binder to recurse.
            sourceFile.ExternalModuleIndicator = sourceFile;
            sourceFile.SetLineMap(new [] { 0, 2 });

            return(Task.FromResult <Possible <ISourceFile> >(sourceFile));
        }
コード例 #3
0
        internal static PdfDocument Open(Stream stream, ParsingOptions options)
        {
            var streamInput = new StreamInputBytes(stream, false);

            return(Open(streamInput, options));
        }
コード例 #4
0
        /// <nodoc/>
        public async Task <Possible <ISourceFile> > TryParseAsync(AbsolutePath pathToParse, AbsolutePath moduleOrConfigPathPromptingParse, ParsingOptions parsingOptions = null)
        {
            Contract.Requires(pathToParse.IsValid);

            // Check if the file exists and that it is not a directory
            if (!m_fileSystem.Exists(pathToParse))
            {
                return(new CannotReadSpecFailure(pathToParse.ToString(m_fileSystem.GetPathTable()), CannotReadSpecFailure.CannotReadSpecReason.SpecDoesNotExist));
            }

            if (m_fileSystem.IsDirectory(pathToParse))
            {
                return(new CannotReadSpecFailure(pathToParse.ToString(m_fileSystem.GetPathTable()), CannotReadSpecFailure.CannotReadSpecReason.PathIsADirectory));
            }

            // Parses the spec
            ISourceFile parsedFile;

            using (var reader = m_fileSystem.OpenText(pathToParse))
            {
                var content = await reader.ReadToEndAsync();

                var parser = new Parser();

                parsedFile = parser.ParseSourceFileContent(m_fileSystem.GetBaseName(pathToParse), content, parsingOptions);
            }

            return(new Possible <ISourceFile>(parsedFile));
        }
コード例 #5
0
 /// <inheritdoc cref="ParsePageAsync(WikiSite,string,string,ParsingOptions,CancellationToken)"/>
 public static Task <ParsedContentInfo> ParsePageAsync(this WikiSite site, string title, ParsingOptions options, CancellationToken cancellationToken)
 {
     return(ParsePageAsync(site, title, null, options, CancellationToken.None));
 }
コード例 #6
0
 /// <inheritdoc cref="ParseContentAsync(WikiSite,string,string,string,string,string,ParsingOptions,CancellationToken)"/>
 public static Task <ParsedContentInfo> ParseContentAsync(this WikiSite site, string content, string summary, string title,
                                                          string contentModel, ParsingOptions options, CancellationToken cancellationToken)
 {
     return(ParseContentAsync(site, content, summary, title, contentModel, null, options, CancellationToken.None));
 }
コード例 #7
0
 /// <inheritdoc cref="ParseRevisionAsync(WikiSite,int,string,ParsingOptions,CancellationToken)"/>
 public static Task <ParsedContentInfo> ParseRevisionAsync(this WikiSite site, int revId, ParsingOptions options, CancellationToken cancellationToken)
 {
     return(ParseRevisionAsync(site, revId, null, options, CancellationToken.None));
 }
コード例 #8
0
 /// <inheritdoc cref="ParsePageAsync(WikiSite,string,string,ParsingOptions,CancellationToken)"/>
 public static Task <ParsedContentInfo> ParsePageAsync(this WikiSite site, int id, ParsingOptions options)
 {
     return(ParsePageAsync(site, id, null, options, CancellationToken.None));
 }
コード例 #9
0
        /// <inheritdoc />
        public Task <Possible <ISourceFile> > TryParseAsync(AbsolutePath pathToParse, AbsolutePath moduleOrConfigPathPromptingParse, ParsingOptions parsingOption = null)
        {
            Contract.Assume(m_descriptorsBySpecPath != null, "Init must have been called");

            var pathToParseAsString = pathToParse.ToString(m_context.PathTable);

            if (!m_descriptorsBySpecPath.TryGetValue(pathToParse, out var descriptor))
            {
                return(Task.FromResult <Possible <ISourceFile> >(new SpecNotOwnedByResolverFailure(pathToParseAsString)));
            }

            if (!Downloads.TryGetValue(descriptor.Name, out var downloadData))
            {
                Contract.Assert(false, "Inconsistent internal state of DownloadResolver");
                return(Task.FromResult <Possible <ISourceFile> >(new SpecNotOwnedByResolverFailure(pathToParseAsString)));
            }

            string exeExtension = OperatingSystemHelper.IsWindowsOS ? ".exe" : string.Empty;

            // CODESYNC: keep in sync with Public\Src\Tools\FileDownloader\Tool.FileDownloader.dsc deployment
            AbsolutePath toolRootPath     = m_host.Configuration.Layout.NormalizedBuildEngineDirectory.IsValid ? m_host.Configuration.Layout.NormalizedBuildEngineDirectory : m_host.Configuration.Layout.BuildEngineDirectory;
            var          pathToDownloader = toolRootPath.Combine(m_context.PathTable, RelativePath.Create(m_context.StringTable, "/tools/FileDownloader/Downloader" + exeExtension));
            var          pathToExtractor  = toolRootPath.Combine(m_context.PathTable, RelativePath.Create(m_context.StringTable, "/tools/FileDownloader/Extractor" + exeExtension));

            // Create a spec file that schedules two pips: a download one followed by an extract one. The latter only if extraction is specified
            // CODESYNC: tools arguments and behavior defined in Public\Src\Tools\FileDownloader\Downloader.cs and \Public\Src\Tools\FileDownloader\Extractor.cs
            var spec = $@"
                export declare const qualifier: {{}};
            
                const downloadTool  = {CreateToolDefinition(pathToDownloader, dependsOnAppDataDirectory: true)}
                const downloadResult = {CreateDownloadPip(downloadData)}
                @@public export const {downloadData.DownloadedValueName} : File = downloadResult.getOutputFile(p`{downloadData.DownloadedFilePath.ToString(m_context.PathTable)}`);";

            // The extract pip (and its corresponding public value) are only available if extraction needs to happen
            if (downloadData.ShouldExtractBits)
            {
                spec += $@"
                    const extractTool  = {CreateToolDefinition(pathToExtractor)}
                    const extractResult = {CreateExtractPip(downloadData)}
                    @@public export const {downloadData.ExtractedValueName} : OpaqueDirectory = extractResult.getOutputDirectory(d`{downloadData.ContentsFolder.Path.ToString(m_context.PathTable)}`);
                    ";
            }

            // No need to check for errors here since they are embedded in the source file and downstream consumers check for those
            FrontEndUtilities.TryParseSourceFile(m_context, pathToParse, spec, out var sourceFile);

            return(Task.FromResult <Possible <ISourceFile> >(sourceFile));
        }
コード例 #10
0
        /// <summary>
        /// Parses specified expression statement <paramref name="code"/> and returns the contained expression.
        /// </summary>
        /// <remarks>
        /// If <paramref name="roundTripTesting"/> is true, <see cref="ParseSourceFileWithRoundTrip"/> would be called to get
        /// source file from the string representation.
        /// </remarks>
        public static TNode ParseExpressionStatement <TNode>(string code, bool roundTripTesting = true, ParsingOptions parsingOptions = null) where TNode : class, INode
        {
            Contract.Requires(code != null);
            Contract.Ensures(Contract.Result <TNode>() != null);

            return(((IExpressionStatement)ParseStatementsFrom(code, roundTripTesting, parsingOptions).First()).Expression.Cast <TNode>());
        }
コード例 #11
0
        /// <summary>
        /// Parses specified <paramref name="code"/> and returns the second statement form the <see cref="ISourceFile"/>.
        /// </summary>
        /// <remarks>
        /// If <paramref name="roundTripTesting"/> is true, <see cref="ParseSourceFileWithRoundTrip"/> would be called to get
        /// source file from the string representation.
        /// </remarks>
        public static TNode ParseSecondStatementFrom <TNode>(string code, bool roundTripTesting = true, ParsingOptions parsingOptions = null) where TNode : INode
        {
            Contract.Requires(code != null);
            Contract.Ensures(Contract.Result <TNode>() != null);

            return((TNode)ParseStatementsFrom(code, roundTripTesting, parsingOptions).Skip(1).First());
        }
コード例 #12
0
        /// <summary>
        /// Parses specified <paramref name="code"/> and returns the all statements from the <see cref="ISourceFile"/>.
        /// </summary>
        /// <remarks>
        /// If <paramref name="roundTripTesting"/> is true, <see cref="ParseSourceFileWithRoundTrip"/> would be called to get
        /// source file from the string representation.
        /// </remarks>
        public static List <IStatement> ParseStatementsFrom(string code, bool roundTripTesting = true, ParsingOptions parsingOptions = null)
        {
            Contract.Requires(code != null);
            Contract.Ensures(Contract.Result <List <IStatement> >() != null);

            var sourceFile = roundTripTesting
                ? ParseSourceFileWithRoundTrip(code, parsingOptions)
                : ParseSourceFile(code, parsingOptions: parsingOptions);

            return(sourceFile.Statements.ToList());
        }
コード例 #13
0
        /// <summary>
        /// Parses specified <paramref name="code"/> into <see cref="ISourceFile"/>.
        /// This function will not throw if parsing or binding will fail.
        /// </summary>
        public static ISourceFile ParsePotentiallyBrokenSourceFile(string code, string fileName = "fakeFileName.ts", ParsingOptions parsingOptions = null)
        {
            Contract.Requires(code != null);
            Contract.Ensures(Contract.Result <ISourceFile>() != null);

            var parser = new Parser();

            parsingOptions = parsingOptions?.WithFailOnMissingSemicolons(false);
            ISourceFile node = parser.ParseSourceFile(fileName, code, ScriptTarget.Es2015, syntaxCursor: null, setParentNodes: true, parsingOptions: parsingOptions);

            // Source file should not be null
            Assert.NotNull(node);

            var binder = new Binder();

            binder.BindSourceFile(node, new CompilerOptions());

            return(node);
        }
コード例 #14
0
        /// <summary>
        /// Parses specified <paramref name="code"/> into <see cref="ISourceFile"/>.
        /// </summary>
        public static ISourceFile ParseSourceFile(string code, string fileName = "fakeFileName.dsc", ParsingOptions parsingOptions = null, Parser parser = null)
        {
            Contract.Requires(code != null);
            Contract.Ensures(Contract.Result <ISourceFile>() != null);

            parser = parser ?? new Parser();

            ISourceFile node = parser.ParseSourceFile(fileName, code, ScriptTarget.Es2015, syntaxCursor: null,
                                                      setParentNodes: true, parsingOptions: parsingOptions);

            // Source file should not be null
            Assert.NotNull(node);

            if (parser.ParseDiagnostics.Count != 0)
            {
                var message = string.Join("\r\n", parser.ParseDiagnostics.Select(d => d.MessageText));
                throw new Exception($"Parsing failed. Diagnostics:\r\n{message}");
            }

            var binder = new Binder();

            binder.BindSourceFile(node, new CompilerOptions());

            if (node.BindDiagnostics.Count != 0)
            {
                var message = string.Join("\r\n", node.BindDiagnostics.Select(d => d.MessageText));
                throw new Exception($"Binding failed. Diagnostics:\r\n{message}");
            }

            return(node);
        }
コード例 #15
0
        /// <summary>
        /// Constructs a instance of Uglify JS minifier
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param>
        /// <param name="uglifyConfig">Configuration settings of Uglify Minifier</param>
        public UglifyJsMinifier(Func <IJsEngine> createJsEngineInstance, UglifySettings uglifyConfig)
        {
            JsMinifierSettings     jsMinifierConfig     = uglifyConfig.Js;
            ParsingSettings        parsingConfig        = jsMinifierConfig.Parsing;
            CompressionSettings    compressionConfig    = jsMinifierConfig.Compression;
            ManglingSettings       manglingConfig       = jsMinifierConfig.Mangling;
            CodeGenerationSettings codeGenerationConfig = jsMinifierConfig.CodeGeneration;

            ParsingOptions = new ParsingOptions
            {
                BareReturns = parsingConfig.BareReturns,
                Strict      = parsingConfig.Strict
            };

            CompressionOptions = new CompressionOptions
            {
                Angular               = compressionConfig.Angular,
                Booleans              = compressionConfig.Booleans,
                Cascade               = compressionConfig.Cascade,
                CollapseVars          = compressionConfig.CollapseVars,
                Comparisons           = compressionConfig.Comparisons,
                Compress              = compressionConfig.Compress,
                Conditionals          = compressionConfig.Conditionals,
                DeadCode              = compressionConfig.DeadCode,
                DropConsole           = compressionConfig.DropConsole,
                DropDebugger          = compressionConfig.DropDebugger,
                Evaluate              = compressionConfig.Evaluate,
                GlobalDefinitions     = compressionConfig.GlobalDefinitions,
                HoistFunctions        = compressionConfig.HoistFunctions,
                HoistVars             = compressionConfig.HoistVars,
                IfReturn              = compressionConfig.IfReturn,
                JoinVars              = compressionConfig.JoinVars,
                KeepFunctionArgs      = compressionConfig.KeepFunctionArgs,
                KeepInfinity          = compressionConfig.KeepInfinity,
                Loops                 = compressionConfig.Loops,
                NegateIife            = compressionConfig.NegateIife,
                Passes                = compressionConfig.Passes,
                PropertiesDotNotation = compressionConfig.PropertiesDotNotation,
                PureGetters           = compressionConfig.PureGetters,
                PureFunctions         = compressionConfig.PureFunctions,
                ReduceVars            = compressionConfig.ReduceVars,
                Sequences             = compressionConfig.Sequences,
                TopLevel              = compressionConfig.TopLevel,
                TopRetain             = compressionConfig.TopRetain,
                Unsafe                = compressionConfig.Unsafe,
                UnsafeMath            = compressionConfig.UnsafeMath,
                UnsafeProto           = compressionConfig.UnsafeProto,
                UnsafeRegExp          = compressionConfig.UnsafeRegExp,
                Unused                = compressionConfig.Unused
            };

            ManglingOptions = new ManglingOptions
            {
                Eval     = manglingConfig.Eval,
                Except   = manglingConfig.Except,
                Mangle   = manglingConfig.Mangle,
                TopLevel = manglingConfig.TopLevel,
            };

            CodeGenerationOptions = new CodeGenerationOptions
            {
                AsciiOnly            = codeGenerationConfig.AsciiOnly,
                Beautify             = codeGenerationConfig.Beautify,
                Bracketize           = codeGenerationConfig.Bracketize,
                Comments             = codeGenerationConfig.Comments,
                IndentLevel          = codeGenerationConfig.IndentLevel,
                IndentStart          = codeGenerationConfig.IndentStart,
                InlineScript         = codeGenerationConfig.InlineScript,
                KeepQuotedProperties = codeGenerationConfig.KeepQuotedProperties,
                MaxLineLength        = codeGenerationConfig.MaxLineLength,
                PreserveLine         = codeGenerationConfig.PreserveLine,
                QuoteKeys            = codeGenerationConfig.QuoteKeys,
                QuoteStyle           = codeGenerationConfig.QuoteStyle,
                Semicolons           = codeGenerationConfig.Semicolons,
                SpaceColon           = codeGenerationConfig.SpaceColon,
                UnescapeRegexps      = codeGenerationConfig.UnescapeRegexps,
                Width    = codeGenerationConfig.Width,
                WrapIife = codeGenerationConfig.WrapIife
            };

            KeepFunctionNames = jsMinifierConfig.KeepFunctionNames;
            ScrewIe8          = jsMinifierConfig.ScrewIe8;
            Severity          = jsMinifierConfig.Severity;

            if (createJsEngineInstance == null)
            {
                string jsEngineName = uglifyConfig.JsEngine.Name;
                if (string.IsNullOrWhiteSpace(jsEngineName))
                {
                    throw new ConfigurationErrorsException(
                              string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
                                            "uglify",
                                            @"
  * JavaScriptEngineSwitcher.Msie
  * JavaScriptEngineSwitcher.V8
  * JavaScriptEngineSwitcher.ChakraCore",
                                            "MsieJsEngine")
                              );
                }

                createJsEngineInstance = () => JsEngineSwitcher.Instance.CreateEngine(jsEngineName);
            }
            _createJsEngineInstance = createJsEngineInstance;
        }
コード例 #16
0
ファイル: ParsingHelper.cs プロジェクト: microsoft/BuildXL
        /// <summary>
        /// Parses specified <paramref name="code"/> and returns the first statement from the <see cref="ISourceFile"/>.
        /// </summary>
        /// <remarks>
        /// If <paramref name="roundTripTesting"/> is true, <see cref="ParseSourceFileWithRoundTrip"/> would be called to get
        /// source file from the string representation.
        /// </remarks>
        public static TNode ParseFirstStatementFrom <TNode>(string code, bool roundTripTesting = true, ParsingOptions parsingOptions = null) where TNode : INode
        {
            Contract.Requires(code != null);

            var result = (TNode)ParseStatementsFrom(code, roundTripTesting, parsingOptions).First();

            return(result);
        }
コード例 #17
0
        public static List <Diagnostic> GetSemanticDiagnostics(bool useCachedVersion = false, ParsingOptions parsingOptions = null, params string[] codes)
        {
            var testFiles = GenerateTestFileNames("ts", codes);

            return(GetSemanticDiagnostics(
                       useCachedVersion: useCachedVersion,
                       parsingOptions: parsingOptions,
                       tsInputFiles: testFiles));
        }
コード例 #18
0
ファイル: UriParser.cs プロジェクト: paul-ion/HTTP-BlackOps
        /// <summary>
        /// Executes the parsing operation
        /// </summary>
        /// <param name="pathOfFileToImport"></param>
        /// <param name="currentFile"></param>
        /// <param name="options"></param>
        public void Parse(string pathOfFileToImport, ITrafficDataAccessor currentFile, ParsingOptions options)
        {
            _options = options;
            _status  = TrafficParserStatus.Running;

            string text = File.ReadAllText(pathOfFileToImport);

            MatchCollection matches = Regex.Matches(text, URI_REGEX);

            Dictionary <string, List <Uri> > uniqueRequests = new Dictionary <string, List <Uri> >();

            foreach (Match m in matches)
            {
                try
                {
                    Uri    uri = new Uri(m.Value);
                    string key = String.Format("{0}://{1}:{2}/{3}", uri.Scheme, uri.Host, uri.Port, uri.AbsolutePath);
                    if (!uniqueRequests.ContainsKey(key))
                    {
                        uniqueRequests.Add(key, new List <Uri>());
                    }
                    uniqueRequests[key].Add(uri);
                }
                catch (Exception ex)
                {
                    SdkSettings.Instance.Logger.Log(TraceLevel.Error, "URI Parser - Invalid uri: {0}", ex.Message);
                }
            }


            foreach (string key in uniqueRequests.Keys)
            {
                try
                {
                    List <Uri> uriList = uniqueRequests[key];
                    //construct querystring
                    StringBuilder queryStringBuilder = new StringBuilder();
                    foreach (Uri uri in uriList)
                    {
                        string query = uri.Query.Trim('?');
                        if (!String.IsNullOrWhiteSpace(query))
                        {
                            queryStringBuilder.Append(query);
                            queryStringBuilder.Append('&');
                        }
                    }
                    //now get the full query
                    string fullQuery = queryStringBuilder.ToString().Trim('&');
                    Uri    firstUri  = uriList[0];

                    AddRequest(currentFile, firstUri, fullQuery, Resources.UriParserGetRequest);
                    AddRequest(currentFile, firstUri, fullQuery, Resources.UriParserPostRequest);
                }
                catch (Exception ex)
                {
                    SdkSettings.Instance.Logger.Log(TraceLevel.Error, "URI Parser - Failed to add request: {0}", ex.Message);
                }
            }

            _status = TrafficParserStatus.Stopped;
        }
コード例 #19
0
        private static IDictionary <string, object> BuildParsingParams(WikiSite site, ParsingOptions options)
        {
            var p = new Dictionary <string, object>
            {
                { "action", "parse" },
                { "prop", "text|langlinks|categories|sections|revid|displaytitle|properties" },
                { "disabletoc", (options & ParsingOptions.DisableToc) == ParsingOptions.DisableToc },
                { "disableeditsection", (options & ParsingOptions.DisableEditSection) == ParsingOptions.DisableEditSection },
                { "disabletidy", (options & ParsingOptions.DisableTidy) == ParsingOptions.DisableTidy },
                { "preview", (options & ParsingOptions.Preview) == ParsingOptions.Preview },
                { "sectionpreview", (options & ParsingOptions.SectionPreview) == ParsingOptions.SectionPreview },
                { "redirects", (options & ParsingOptions.ResolveRedirects) == ParsingOptions.ResolveRedirects },
                { "mobileformat", (options & ParsingOptions.MobileFormat) == ParsingOptions.MobileFormat },
                { "noimages", (options & ParsingOptions.NoImages) == ParsingOptions.NoImages },
                { "effectivelanglinks", (options & ParsingOptions.EffectiveLanguageLinks) == ParsingOptions.EffectiveLanguageLinks },
            };

            if ((options & ParsingOptions.TranscludedPages) == ParsingOptions.TranscludedPages)
            {
                p["prop"] += "|templates";
            }
            if ((options & ParsingOptions.LimitReport) == ParsingOptions.LimitReport)
            {
                p["prop"] += "|limitreportdata";
            }
            if ((options & ParsingOptions.DisableLimitReport) == ParsingOptions.DisableLimitReport)
            {
                if (site.SiteInfo.Version >= new Version("1.26"))
                {
                    p["disablelimitreport"] = true;
                }
                else
                {
                    p["disablepp"] = true;
                }
            }
            return(p);
        }
コード例 #20
0
        private static List <string[]> ParseTables(GenericScore score, HtmlNodeCollection tables, ParsingOptions poptions)
        {
            // get list of indexes if defined
            List <int> indexes = null;

            if (score.Element.Length > 0)
            {
                string[] elts = score.Element.Split(';');
                indexes = new List <int>(elts.Length);
                for (int i = 0; i < elts.Length; i++)
                {
                    int index;
                    if (int.TryParse(elts[i], out index))
                    {
                        indexes.Add(index);
                    }
                }
            }

            // build the score
            List <string[]> ll = new List <string[]>();

            bool first = true;

            if (tables != null && tables.Count > 0)
            {
                bool allowNewLine = Tools.CheckParsingOption(poptions, ParsingOptions.NewLine);
                bool useTheader   = Tools.CheckParsingOption(poptions, ParsingOptions.UseTheader);
                bool useCaption   = Tools.CheckParsingOption(poptions, ParsingOptions.Caption);
                bool parseImgAlt  = Tools.CheckParsingOption(poptions, ParsingOptions.ImgAlt);

                int skip = score.Skip;
                int max  = score.MaxLines;
                if (max > 0)
                {
                    max += skip;
                }

                int itable = -1;
                foreach (HtmlNode table in tables)
                {
                    itable++;
                    if (indexes != null && !indexes.Contains(itable))
                    {
                        continue;
                    }

                    string[][] rr = ParseTable(table, score.XPathRow, score.XPathCol, skip, max, allowNewLine, useTheader, useCaption, parseImgAlt);
                    if (rr != null)
                    {
                        if (first)
                        {
                            AddHeaders(score, ll);
                            first = false;
                        }
                        else
                        {
                            switch (score.BetweenElts)
                            {
                            case BetweenElements.EmptyLine:
                                ll.Add(new string[] { ScoreCenterPlugin.C_HEADER });
                                break;

                            case BetweenElements.RepeatHeader:
                                AddHeaders(score, ll);
                                break;
                            }
                        }
                        ll.AddRange(rr);
                    }
                }
            }
            return(ll);
        }
コード例 #21
0
        /// <summary>
        /// Parsing the specific page revision, gets HTML and more information. (MediaWiki 1.12)
        /// </summary>
        /// <param name="site">The MediaWiki site to execute the request on.</param>
        /// <param name="revId">Id of the revision to be parsed.</param>
        /// <param name="lang">The language (variant) used to render the content. E.g. <c>"zh-cn"</c>, <c>"zh-tw"</c>. specify <c>content</c> to use this wiki's content language.</param>
        /// <param name="options">Options for parsing.</param>
        /// <param name="cancellationToken">The cancellation token that will be checked prior to completing the returned task.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="revId"/> is zero or negative.</exception>
        public static async Task <ParsedContentInfo> ParseRevisionAsync(this WikiSite site, int revId, string lang, ParsingOptions options, CancellationToken cancellationToken)
        {
            if (site == null)
            {
                throw new ArgumentNullException(nameof(site));
            }
            if (revId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(revId));
            }
            var p = BuildParsingParams(site, options);

            p["oldid"] = revId;
            var jobj = await site.InvokeMediaWikiApiAsync(new MediaWikiFormRequestMessage(p), cancellationToken);

            var parsed = ((JObject)jobj["parse"]).ToObject <ParsedContentInfo>(Utility.WikiJsonSerializer);

            return(parsed);
        }
コード例 #22
0
        /// <summary>
        /// Default DScript implementation of <see cref="BuildXL.FrontEnd.Workspaces.IWorkspaceModuleResolver.TryParseAsync"/>.
        /// </summary>
        public virtual async Task <Possible <ISourceFile> > TryParseAsync(AbsolutePath pathToParse, AbsolutePath moduleOrConfigPathPromptingParse, ParsingOptions parsingOptions = null)
        {
            Contract.Requires(pathToParse.IsValid);

            var specPathString = pathToParse.ToString(Context.PathTable);

            // If the option to use the public facade of a spec is on, we try to honor it
            if (parsingOptions?.UseSpecPublicFacadeAndAstWhenAvailable == true)
            {
                var facadeWithAst = await FrontEndHost.FrontEndArtifactManager.TryGetPublicFacadeWithAstAsync(pathToParse);

                if (facadeWithAst != null)
                {
                    return(new Possible <ISourceFile>(
                               ParseSourceFileContent(
                                   parsingOptions,
                                   specPathString,
                                   facadeWithAst.PublicFacadeContent,
                                   () =>
                    {
                        using (FrontEndStatistics.CounterWithRootCause.Start())
                        {
                            return CreateTextSource(facadeWithAst.PublicFacadeContent);
                        }
                    },
                                   FrontEndStatistics,
                                   facadeWithAst.SerializedAst)));
                }
            }

            var maybeContent = await Engine.GetFileContentAsync(pathToParse);

            if (!maybeContent.Succeeded)
            {
                return(HandleIoError(pathToParse, moduleOrConfigPathPromptingParse, maybeContent.Failure.Exception));
            }

            if (!maybeContent.Result.IsValid)
            {
                return(HandleContentIsInvalid(pathToParse, moduleOrConfigPathPromptingParse));
            }

            var sourceFile = ParseSourceFileContent(
                parsingOptions,
                specPathString,
                maybeContent.Result,
                () =>
            {
                using (FrontEndStatistics.CounterWithRootCause.Start())
                {
                    // Need to reparse the file content in the error case.
                    return(CreateTextSource(Engine.GetFileContentAsync(pathToParse).GetAwaiter().GetResult().Result));
                }
            },
                FrontEndStatistics,
                serializedAst: ByteContent.Invalid);

            return(new Possible <ISourceFile>(sourceFile));
        }
コード例 #23
0
        /// <summary>
        /// Parsing the specific page content and/or summary, gets HTML and more information. (MediaWiki 1.12)
        /// </summary>
        /// <param name="site">The MediaWiki site to execute the request on.</param>
        /// <param name="content">The content to parse.</param>
        /// <param name="summary">The summary to parse. Can be <c>null</c>.</param>
        /// <param name="title">Act like the wikitext is on this page.
        ///     This only really matters when parsing links to the page itself or subpages,
        ///     or when using magic words like <c>{{PAGENAME}}</c>.
        ///     If <c>null</c> is given, the default value <c>"API"</c> will be used.</param>
        /// <param name="contentModel">The content model name of the text specified in <paramref name="content"/>. <c>null</c> makes the server to infer content model from <paramref name="title"/>.</param>
        /// <param name="lang">The language (variant) used to render the content. E.g. <c>"zh-cn"</c>, <c>"zh-tw"</c>. specify <c>content</c> to use this wiki's content language.</param>
        /// <param name="options">Options for parsing.</param>
        /// <param name="cancellationToken">The cancellation token that will be checked prior to completing the returned task.</param>
        /// <remarks>If both <paramref name="title"/> and <paramref name="contentModel"/> is <c>null</c>, the content model will be assumed as wikitext.</remarks>
        /// <exception cref="ArgumentException">Both <paramref name="content"/> and <paramref name="summary"/> is <c>null</c>.</exception>
        public static async Task <ParsedContentInfo> ParseContentAsync(this WikiSite site, string content, string summary, string title,
                                                                       string contentModel, string lang, ParsingOptions options, CancellationToken cancellationToken)
        {
            if (content == null && summary == null)
            {
                throw new ArgumentException(nameof(content));
            }
            var p = BuildParsingParams(site, options);

            p["text"]    = content;
            p["summary"] = summary;
            p["title"]   = title;
            p["uselang"] = lang;
            var jobj = await site.InvokeMediaWikiApiAsync(new MediaWikiFormRequestMessage(p), cancellationToken);

            var parsed = ((JObject)jobj["parse"]).ToObject <ParsedContentInfo>(Utility.WikiJsonSerializer);

            return(parsed);
        }
コード例 #24
0
 /// <inheritdoc />
 protected override IParsingProduct TryParseInternal(IParsingContextStream ctx, ParsingOptions options)
 {
     return(ctx.MoveNext() && ctx.Current.IsAny(_range)
                         ? ctx.Accept().CreateTermForAcceptedFragment(FXB.ExpressionTypes.CharTerm)
                         : null);
 }
コード例 #25
0
        /// <summary>
        /// Parsing the specific page, gets HTML and more information. (MediaWiki 1.12)
        /// </summary>
        /// <param name="site">The MediaWiki site to execute the request on.</param>
        /// <param name="title">Title of the page to be parsed.</param>
        /// <param name="lang">The language (variant) used to render the content. E.g. <c>"zh-cn"</c>, <c>"zh-tw"</c>. specify <c>content</c> to use this wiki's content language.</param>
        /// <param name="options">Options for parsing.</param>
        /// <param name="cancellationToken">The cancellation token that will be checked prior to completing the returned task.</param>
        /// <exception cref="ArgumentNullException"><paramref name="title"/> is <c>null</c>.</exception>
        public static async Task <ParsedContentInfo> ParsePageAsync(this WikiSite site, string title, string lang, ParsingOptions options, CancellationToken cancellationToken)
        {
            if (site == null)
            {
                throw new ArgumentNullException(nameof(site));
            }
            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException(nameof(title));
            }
            var p = BuildParsingParams(site, options);

            p["page"]    = title;
            p["uselang"] = lang;
            var jobj = await site.InvokeMediaWikiApiAsync(new MediaWikiFormRequestMessage(p), cancellationToken);

            var parsed = ((JObject)jobj["parse"]).ToObject <ParsedContentInfo>(Utility.WikiJsonSerializer);

            return(parsed);
        }
コード例 #26
0
 public IEnumerable <string> ApplyFilter(IEnumerable <string> data, ParsingOptions parsingOptions)
 {
     return(data.Where(link => parsingOptions.ExcludeWords.All(word => !link.Contains(word))));
 }
コード例 #27
0
        public static PdfDocument Open(byte[] fileBytes, ParsingOptions options = null)
        {
            var inputBytes = new ByteArrayInputBytes(fileBytes);

            return(Open(inputBytes, options));
        }
コード例 #28
0
        private void Load()
        {
            SetState(AccessorState.Loading);
            //Open the decompressed files

            //load index
            byte[]        bytes;
            string        line;
            int           currentIndex = -1, count = 0;
            TVRequestInfo currentRequestInfo;

            _requestInfos   = new SortedDictionary <int, TVRequestInfo>();
            _rawTrafficFile = File.Open(_tempFileFolder + "\\" + RAW_TRAFFIC_FILE_NAME, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

            XmlDocument customDataFile = new XmlDocument();

            customDataFile.XmlResolver = null;
            if (File.Exists(_tempFileFolder + "\\" + CUSTOM_DATA_FILE_NAME))
            {
                customDataFile.Load(_tempFileFolder + "\\" + CUSTOM_DATA_FILE_NAME);
            }

            Profile = new ParsingOptions();

            //Load the parsing options that were used to create this file
            if (File.Exists(_tempFileFolder + "\\" + OPTIONS_FILE_NAME))
            {
                Profile.Load(_tempFileFolder + "\\" + OPTIONS_FILE_NAME);
            }


            _firstIndex = -1;
            FileStream indexFile = File.Open(_tempFileFolder + "\\" + INDEX_FILE_NAME, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            while ((bytes = Utils.ReadLine(indexFile, ESTIMATED_LINE_SIZE)) != null)
            {
                try
                {
                    line = Utils.ByteToString(bytes);

                    currentRequestInfo = new TVRequestInfo();

                    currentRequestInfo.ReadValues(line);

                    currentIndex = currentRequestInfo.Id;

                    AddRequestInfo(currentRequestInfo);

                    //load the data for the first requests in the buffer
                    if (!RequestDataCache.Instance.MaxSizeReached)
                    {
                        this.LoadRequestData(currentIndex);
                        this.LoadResponseData(currentIndex);
                    }

                    //load custom fields
                    XmlNodeList customFields = customDataFile.SelectNodes(
                        String.Format("/Requests/Request[@id='{0}']/Field", currentIndex));
                    if (customFields.Count > 0)
                    {
                        currentRequestInfo.CustomFields = new Dictionary <string, string>();
                        foreach (XmlNode node in customFields)
                        {
                            currentRequestInfo.CustomFields.Add(node.Attributes["name"].Value, node.InnerText);
                        }
                    }


                    count++;
                }
                catch (Exception ex)
                {
                    SdkSettings.Instance.Logger.Log(TraceLevel.Error, "Error loading request from index: {0}", ex.Message);
                }
            }
            //set the position of the rawdatafile to the end
            _rawTrafficFile.Position = _rawTrafficFile.Length;

            //close the other files
            indexFile.Close();

            //set the keep on close flag to false
            _keepOnClose = false;
            SetState(AccessorState.Idle);
        }
コード例 #29
0
ファイル: ParsingOptions.cs プロジェクト: NickAcPT/NAsm
 public static bool HasNotFlagFast(this ParsingOptions value, ParsingOptions flag)
 {
     return((value & flag) == 0);
 }
コード例 #30
0
 /// <summary>
 /// Starts parsing operation
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="currentFile"></param>
 /// <param name="options"></param>
 public void Parse(object sender, ITrafficDataAccessor currentFile, ParsingOptions options)
 {
     throw new NotImplementedException("Not available for this import type");
 }
コード例 #31
0
        /// <summary>
        /// Constructs a instance of Uglify JS-minifier
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JavaScript engine</param>
        /// <param name="uglifyConfig">Configuration settings of Uglify Minifier</param>
        public UglifyJsMinifier(Func<IJsEngine> createJsEngineInstance, UglifySettings uglifyConfig)
        {
            JsMinifierSettings jsMinifierConfig = uglifyConfig.Js;
            ParsingSettings parsingConfig = jsMinifierConfig.Parsing;
            CompressionSettings compressionConfig = jsMinifierConfig.Compression;
            ManglingSettings manglingConfig = jsMinifierConfig.Mangling;
            CodeGenerationSettings codeGenerationConfig = jsMinifierConfig.CodeGeneration;

            ParsingOptions = new ParsingOptions
            {
                Strict = parsingConfig.Strict,
                BareReturns = parsingConfig.BareReturns
            };

            CompressionOptions = new CompressionOptions
            {
                Compress = compressionConfig.Compress,
                Sequences = compressionConfig.Sequences,
                PropertiesDotNotation = compressionConfig.PropertiesDotNotation,
                DeadCode = compressionConfig.DeadCode,
                DropDebugger = compressionConfig.DropDebugger,
                Unsafe = compressionConfig.Unsafe,
                Conditionals = compressionConfig.Conditionals,
                Comparisons = compressionConfig.Comparisons,
                Evaluate = compressionConfig.Evaluate,
                Booleans = compressionConfig.Booleans,
                Loops = compressionConfig.Loops,
                Unused = compressionConfig.Unused,
                HoistFunctions = compressionConfig.HoistFunctions,
                KeepFunctionArgs = compressionConfig.KeepFunctionArgs,
                HoistVars = compressionConfig.HoistVars,
                IfReturn = compressionConfig.IfReturn,
                JoinVars = compressionConfig.JoinVars,
                Cascade = compressionConfig.Cascade,
                GlobalDefinitions = compressionConfig.GlobalDefinitions,
                PureGetters = compressionConfig.PureGetters,
                PureFunctions = compressionConfig.PureFunctions,
                DropConsole = compressionConfig.DropConsole,
                Angular = compressionConfig.Angular
            };

            ManglingOptions = new ManglingOptions
            {
                Mangle = manglingConfig.Mangle,
                Except = manglingConfig.Except,
                Eval = manglingConfig.Eval,
                Sort = manglingConfig.Sort,
                TopLevel = manglingConfig.TopLevel,
            };

            CodeGenerationOptions = new CodeGenerationOptions
            {
                Beautify = codeGenerationConfig.Beautify,
                IndentLevel = codeGenerationConfig.IndentLevel,
                IndentStart = codeGenerationConfig.IndentStart,
                QuoteKeys = codeGenerationConfig.QuoteKeys,
                SpaceColon = codeGenerationConfig.SpaceColon,
                AsciiOnly = codeGenerationConfig.AsciiOnly,
                InlineScript = codeGenerationConfig.InlineScript,
                Width = codeGenerationConfig.Width,
                MaxLineLength = codeGenerationConfig.MaxLineLength,
                Bracketize = codeGenerationConfig.Bracketize,
                Semicolons = codeGenerationConfig.Semicolons,
                Comments = codeGenerationConfig.Comments,
                PreserveLine = codeGenerationConfig.PreserveLine,
                UnescapeRegexps = codeGenerationConfig.UnescapeRegexps,
                QuoteStyle = codeGenerationConfig.QuoteStyle
            };

            ScrewIe8 = jsMinifierConfig.ScrewIe8;
            KeepFunctionNames = jsMinifierConfig.KeepFunctionNames;
            Severity = jsMinifierConfig.Severity;

            if (createJsEngineInstance == null)
            {
                string jsEngineName = uglifyConfig.JsEngine.Name;
                if (string.IsNullOrWhiteSpace(jsEngineName))
                {
                    throw new ConfigurationErrorsException(
                        string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
                            "uglify",
                            @"
              * JavaScriptEngineSwitcher.Msie
              * JavaScriptEngineSwitcher.V8",
                            "MsieJsEngine")
                    );
                }

                createJsEngineInstance = (() =>
                    JsEngineSwitcher.Current.CreateJsEngineInstance(jsEngineName));
            }
            _createJsEngineInstance = createJsEngineInstance;
        }
コード例 #32
0
        public static List <Diagnostic> ParseAndCheck(TestFile tsInputFile, ParsingOptions parsingOptions = null)
        {
            var diagnostics = GetSemanticDiagnostics(tsInputFiles: tsInputFile, parsingOptions: parsingOptions);

            return(diagnostics);
        }