private static bool TryDocument(string path, out RuleDocument document)
        {
            var reader = new MarkdownReader(yamlHeaderOnly: false);
            var stream = reader.Read(File.ReadAllText(path), path);
            var lexer  = new RuleLexer();

            document = lexer.Process(stream);
            return(document != null);
        }
Ejemplo n.º 2
0
        public void LexerExtractsNameTokens()
        {
            //Arrange
            var output = new Output();

            //Act
            var results = TestStrings
                          .Select(s => new { String = s, Result = RuleLexer.Analyse(s).ToList() })
                          .ToList();

            //Assert
            var report = results.AsReport(rep => rep
                                          .AddColumn(r => r.String, cc => cc.Heading("Input"))
                                          .AddChild(r => r.Result, res => res
                                                    .AddColumn(r => r.TokenType, cc => {})
                                                    .AddColumn(r => r.Text, cc => {})));

            output.FormatTable(report);
            output.Report.Verify();
        }
Ejemplo n.º 3
0
        private RuleHelpInfo GetHelpInfo(PipelineContext context, string name)
        {
            if (string.IsNullOrEmpty(context.Source.File.HelpPath))
            {
                return(null);
            }

            var culture = context.Culture;

            for (var i = 0; i < culture.Length; i++)
            {
                var path = Path.Combine(context.Source.File.HelpPath, string.Concat(culture[i], "/", name, ".md"));

                if (!File.Exists(path))
                {
                    continue;
                }

                var reader   = new MarkdownReader(yamlHeaderOnly: false);
                var stream   = reader.Read(markdown: File.ReadAllText(path: path), path: path);
                var lexer    = new RuleLexer();
                var document = lexer.Process(stream: stream);

                if (document != null)
                {
                    return(new RuleHelpInfo(name: name, displayName: document.Name ?? name, moduleName: context.Source.File.ModuleName)
                    {
                        Synopsis = document.Synopsis?.Text,
                        Description = document.Description?.Text,
                        Recommendation = document.Recommendation?.Text ?? document.Synopsis?.Text,
                        Notes = document.Notes?.Text,
                        Annotations = document.Annotations?.ToHashtable()
                    });
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        private RuleDocument GetDocument(TokenStream stream)
        {
            var lexer = new RuleLexer();

            return(lexer.Process(stream: stream));
        }