Пример #1
0
        /// <summary>
        /// Instantiates a new <see cref="Highlighter" /> using the specified syntax id and formatter.
        /// </summary>
        /// <param name="syntaxIdOrAlias">A syntax id that can be resolved via the <see cref="SyntaxCatalog" />.</param>
        /// <param name="formatter">The <see cref="ICodeFormatter">formatter</see> to be used for output generation.</param>
        public Highlighter(string syntaxIdOrAlias, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNullOrEmpty(syntaxIdOrAlias, "syntaxIdOrAlias");
            ArgumentValidator.ThrowIfNull(formatter, "formatter");

            this.Init(SyntaxCatalog.GetSyntaxBy(syntaxIdOrAlias), formatter);
        }
Пример #2
0
        /// <summary>
        /// Instantiates a new <see cref="Highlighter" /> for the given <see cref="Syntax" /> using the specified formatter
        /// </summary>
        /// <param name="syntax">Any <see cref="Syntax" /> whose syntax definition file is present, regardless of whether it's in the <see cref="SyntaxCatalog" />.</param>
        /// <param name="formatter">The <see cref="ICodeFormatter">formatter</see> to be used for the output generation.</param>
        public Highlighter(Syntax syntax, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(syntax, "syntax");
            ArgumentValidator.ThrowIfNull(formatter, "formatter");

            this.Init(syntax, formatter);
        }
Пример #3
0
        public void Process()
        {
            String fcn = "ProcessProfile";

            //IEnumerable<string> y = Source.ListArtifactNames();
            //Resource x = Source.ResolveByUri("http://hl7.org/fhir/DataElement/Identifier");
            //x = Source.FindStructureDefinitionForCoreType("identifier");

            this.gen.ConversionInfo(this.GetType().Name, fcn, $"Converting {this.name} to {this.outputLanguage}");

            switch (this.outputLanguage)
            {
            case OutputLanguageType.CSharp:
                this.Code = new CSCodeFormatter(this.gen);
                break;

            default:
                throw new Exception($"Output language {this.outputLanguage} not found");
            }

            switch (this.profileType)
            {
            case "Extension":
                this.ProcessExtension();
                break;

            default:
                this.ProcessResourceConstraint();
                break;
            }
        }
Пример #4
0
        private void DoScan(SlidingWindowReader reader, ICodeFormatter formatter, bool writeAsynchronously)
        {
            ArgumentValidator.ThrowIfNull(formatter, "formatter");
            this.Reader = reader;

            if (this.m_isFirstRun)
            {
                this.m_scopeStack      = new List <Scope>(8);
                this.m_modes           = new List <KeyValuePair <int, HighlightMode> >(64);
                this.m_possibleKeyword = new StringBuilder(this.m_syntaxDefinition.MaxKeywordLength + 1);
                this.m_isFirstRun      = false;
            }
            else
            {
                this.m_scopeStack.Clear();
                this.m_modes.Clear();
                this.m_possibleKeyword.Length = 0;
            }

            this.m_pendingMatch = new MatchResult();
            this.m_pendingMatch.PosMatchStart = int.MaxValue;
            this.m_posDontMatchUntil          = -1;
            this.m_posAfterKeepend            = int.MaxValue;

            this.m_scopeStack.Add(Scope.BuildBackgroundScope(this.m_syntaxDefinition.MainContext.TopItems));
            this.BuildHighlightModes();

            this.m_outputWriter = new HighlightedOutputWriter(formatter, writeAsynchronously);
            this.LoadInputWindow(this.Reader.CurrentWindow);
            this.Vrooom();
        }
Пример #5
0
        /// <summary>
        /// Build and initialises GeneralCodeFormatter.
        /// </summary>
        public GeneralCodeFormatter()
        {
            _formatters = new CodeFormatterCollection();
            _formatters.Register(new CSharpCodeFormatter(), "cs");

            _default = new PlainTextCodeFormatter();

            return;
        }
        public void Init()
        {
            iOWrapper        = Substitute.For <IIOWrapper>();
            codeItemProvider = Substitute.For <ICodeItemProvider>();
            codeFormatter    = Substitute.For <ICodeFormatter>();
            messageManager   = Substitute.For <MessageManager>();

            codeProvider = new CSharpCodeProvider(codeItemProvider, codeFormatter, iOWrapper, messageManager);
        }
        public void OneTimeSetUp()
        {
            iOWrapper      = Substitute.For <IIOWrapper>();
            codeFormatter  = Substitute.For <ICodeFormatter>();
            messageManager = Substitute.For <MessageManager>();
            messageManager.GetMessage("CurrentProjectTypeIsNotSupported").Returns("CurrentProjectTypeIsNotSupported");

            codeProviderFactory = new CodeProviderFactory(codeFormatter, messageManager, iOWrapper);
        }
 internal HighlightedOutputWriter(ICodeFormatter codeFormatter, bool asynchrounous)
 {
     this.m_windows         = new Queue <InputWindow>(2);
     this.m_modesQueue      = new Queue <List <KeyValuePair <int, HighlightMode> > >(2);
     this.m_codeFormatter   = codeFormatter;
     this.m_posCurrent      = 0;
     this.m_drainModesQueue = this.DrainModesQueue;
     this.m_asynchrounous   = asynchrounous;
 }
        /// <summary>
        /// Build and initialises GeneralCodeFormatter.
        /// </summary>
        public GeneralCodeFormatter()
        {
            _formatters = new CodeFormatterCollection();
            _formatters.Register(new CSharpCodeFormatter(), "cs");

            _default = new PlainTextCodeFormatter();

            return;
        }
Пример #10
0
 internal HighlightedOutputWriter(ICodeFormatter codeFormatter, bool asynchrounous)
 {
     this.m_windows = new Queue<InputWindow>(2);
     this.m_modesQueue = new Queue<List<KeyValuePair<int, HighlightMode>>>(2);
     this.m_codeFormatter = codeFormatter;
     this.m_posCurrent = 0;
     this.m_drainModesQueue = this.DrainModesQueue;
     this.m_asynchrounous = asynchrounous;
 }
Пример #11
0
        public void Scan(TextReader textReader, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(textReader, "textReader");

            SlidingWindowReader reader = new SlidingWindowReader(textReader);

            reader.OnNewInputWindow += this.LoadInputWindow;

            this.DoScan(reader, formatter, true);
        }
        internal static void RunTestsFor(string syntaxId, ICodeFormatter formatter, XmlOutputVerifier verifier)
        {
            foreach (DirectoryInfo testCasesForOneSyntax in TestHelper.FileTestCasesDirectory.GetDirectories(syntaxId)) {
                if (testCasesForOneSyntax.Name == ".svn") {
                    continue;
                }

                TestCaseRunner r = new TestCaseRunner(testCasesForOneSyntax.Name, testCasesForOneSyntax, formatter, verifier);
                r.HighlightAndVerifyAllTestCases();
            }
        }
        public void SetUp()
        {
            _empty = new CodeFormatterCollection();

            _csFormatter      = new CSharpCodeFormatter();
            _defaultFormatter = new PlainTextCodeFormatter();
            _filled           = new CodeFormatterCollection();
            _filled.Register(_csFormatter, "cs");
            _filled.Register(_defaultFormatter, "txt");

            return;
        }
        public void SetUp()
        {
            _empty = new CodeFormatterCollection();

            _csFormatter = new CSharpCodeFormatter();
            _defaultFormatter = new PlainTextCodeFormatter();
            _filled = new CodeFormatterCollection();
            _filled.Register(_csFormatter, "cs");
            _filled.Register(_defaultFormatter, "txt");

            return;
        }
Пример #15
0
        private protected async Task TestAsync(string testCode, string expectedCode, ICodeFormatter formatter, IReadOnlyDictionary <string, string> editorConfig)
        {
            TestCode = testCode;

            var solution = GetSolution(TestState.Sources.ToArray(), TestState.AdditionalFiles.ToArray(), TestState.AdditionalReferences.ToArray());
            var document = solution.Projects.Single().Documents.Single();
            var options  = (OptionSet)await document.GetOptionsAsync();

            ICodingConventionsSnapshot codingConventions = new TestCodingConventionsSnapshot(editorConfig);

            options = OptionsApplier.ApplyConventions(options, codingConventions, Language);

            var filesToFormat = new[] { (document, options, codingConventions) }.ToImmutableArray();
Пример #16
0
        private async Task <string> Publish(string html)
        {
            _codeFormatter = Substitute.For <ICodeFormatter>();
            _codeFormatter.FormatAsync(Arg.Any <string>(), Arg.Any <string>()).Returns(x => Task.FromResult((string)x[1]));

            _imageProcessor = Substitute.For <IImageProcessor>();
            _imageProcessor.Minimize(Arg.Any <string>()).Returns("minImage");

            _processor = new HtmlProcessor(_codeFormatter, _imageProcessor);
            var renderer = new ImageRenderer("the-post");
            var result   = renderer.Render(html);

            return(await _processor.ProcessAsync(result.Html));
        }
Пример #17
0
        /// <summary>
        /// Registers an ICodeFormatter for the given language. The system
        /// is not case sensitive.
        /// </summary>
        /// <param name="formatter">
        /// A non null formatter.
        /// </param>
        /// <param name="language">
        /// A non null file language.
        /// The value must not be empty nor contain '.' and
        /// must not have been already registered.
        /// </param>
        public void Register(ICodeFormatter formatter, string extension)
        {
            UiExceptionHelper.CheckNotNull(formatter, "formatter");
            UiExceptionHelper.CheckNotNull(extension, "language");

            extension = extension.ToLower();

            UiExceptionHelper.CheckTrue(extension.Length > 0,
                                        "language cannot be empty", "language");
            UiExceptionHelper.CheckTrue(extension.LastIndexOf('.') == -1,
                                        "language cannot contain '.'", "language");
            UiExceptionHelper.CheckFalse(_toFormatter.ContainsKey(extension),
                                         "language '" + extension + "' has already an handler. Remove handler first.",
                                         "language");

            _toFormatter.Add(extension, formatter);

            return;
        }
Пример #18
0
        private protected async Task TestAsync(string testCode, string expectedCode, ICodeFormatter formatter, IReadOnlyDictionary <string, string> editorConfig)
        {
            TestCode = testCode;

            var solution = GetSolution(TestState.Sources.ToArray(), TestState.AdditionalFiles.ToArray(), TestState.AdditionalReferences.ToArray());
            var project  = solution.Projects.Single();
            var document = project.Documents.Single();
            var options  = (OptionSet)await document.GetOptionsAsync();

            var formatOptions = new FormatOptions(
                workspaceFilePath: project.FilePath,
                isSolution: false,
                logLevel: LogLevel.Trace,
                saveFormattedFiles: false,
                changesAreErrors: false,
                filesToFormat: ImmutableHashSet.Create <string>(document.FilePath));

            ICodingConventionsSnapshot codingConventions = new TestCodingConventionsSnapshot(editorConfig);

            options = OptionsApplier.ApplyConventions(options, codingConventions, Language);

            var filesToFormat = new[] { (document, options, codingConventions) }.ToImmutableArray();
Пример #19
0
        public void LoadFile(CFile file)
        {
            try {
                m_formatter =
                    CodeFormatterFactory.GetInstance().CreateCodeFormatter(Path.GetExtension(file.Name));
            } catch (Exception) {
                m_formatter = new JavaCodeFormatter();
            }

            CodeFormatterInit finit = new CodeFormatterInit();
            finit.KeywordColor = "#000088";
            finit.CommentColor = "#008800";

            new FileSystem(Globals.CurrentIdentity).LoadFileData(file);
            m_formatter.Init(finit);
            m_formatter.InitLineFormat(new String(file.Data));
            txtData.Text = new String(file.Data);

            LoadComments(file);

            ViewState["fileid"] = file.ID;
            BindData();
        }
Пример #20
0
        public void LoadFile(CFile file)
        {
            try {
                m_formatter =
                    CodeFormatterFactory.GetInstance().CreateCodeFormatter(Path.GetExtension(file.Name));
            } catch (Exception) {
                m_formatter = new JavaCodeFormatter();
            }

            CodeFormatterInit finit = new CodeFormatterInit();

            finit.KeywordColor = "#000088";
            finit.CommentColor = "#008800";

            new FileSystem(Globals.CurrentIdentity).LoadFileData(file);
            m_formatter.Init(finit);
            m_formatter.InitLineFormat(new String(file.Data));
            txtData.Text = new String(file.Data);

            LoadComments(file);

            ViewState["fileid"] = file.ID;
            BindData();
        }
Пример #21
0
        public void Scan(TextReader textReader, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(textReader, "textReader");

            SlidingWindowReader reader = new SlidingWindowReader(textReader);
            reader.OnNewInputWindow += this.LoadInputWindow;

            this.DoScan(reader, formatter, true);
        }
Пример #22
0
        public void Scan(string input, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(input, "input");

            this.DoScan(new SlidingWindowReader(input), formatter, false);
        }
 internal CodeFormatter(IList <string> mimeTypeChain, ICodeFormatter formatter)
 {
     this.mimeTypeChain = mimeTypeChain;
     this.formatter     = formatter;
 }
Пример #24
0
		internal CodeFormatter (IList<string> mimeTypeChain, ICodeFormatter formatter)
		{
			this.mimeTypeChain = mimeTypeChain;
			this.formatter = formatter;
		}
Пример #25
0
 private void Init(Syntax syntax, ICodeFormatter formatter)
 {
     this.m_syntax    = syntax;
     this.m_scanner   = this.m_syntax.BuildScanner();
     this.m_formatter = formatter;
 }
Пример #26
0
 public CodeProviderFactory(ICodeFormatter codeFormatter, MessageManager messageManager, IIOWrapper iOWrapper)
 {
     this.codeFormatter  = codeFormatter ?? throw new ArgumentNullException(nameof(codeFormatter));
     this.messageManager = messageManager ?? throw new ArgumentNullException(nameof(messageManager));
     this.iOWrapper      = iOWrapper ?? throw new ArgumentNullException(nameof(iOWrapper));
 }
 internal static void RunTestsForAllTestCaseDirectories(ICodeFormatter formatter, XmlOutputVerifier verifier)
 {
     RunTestsFor("*", formatter, verifier);
 }
Пример #28
0
        /// <summary>
        /// Instantiates a new <see cref="Highlighter" /> using the specified syntax id and formatter.
        /// </summary>
        /// <param name="syntaxIdOrAlias">A syntax id that can be resolved via the <see cref="SyntaxCatalog" />.</param>
        /// <param name="formatter">The <see cref="ICodeFormatter">formatter</see> to be used for output generation.</param>
        public Highlighter(string syntaxIdOrAlias, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNullOrEmpty(syntaxIdOrAlias, "syntaxIdOrAlias");
            ArgumentValidator.ThrowIfNull(formatter, "formatter");

            this.Init(SyntaxCatalog.GetSyntaxBy(syntaxIdOrAlias), formatter);
        }
Пример #29
0
        /// <summary>
        /// Instantiates a new <see cref="Highlighter" /> for the given <see cref="Syntax" /> using the specified formatter
        /// </summary>
        /// <param name="syntax">Any <see cref="Syntax" /> whose syntax definition file is present, regardless of whether it's in the <see cref="SyntaxCatalog" />.</param>
        /// <param name="formatter">The <see cref="ICodeFormatter">formatter</see> to be used for the output generation.</param>
        public Highlighter(Syntax syntax, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(syntax, "syntax");
            ArgumentValidator.ThrowIfNull(formatter, "formatter");

            this.Init(syntax, formatter);
        }
Пример #30
0
 private void Init(Syntax syntax, ICodeFormatter formatter)
 {
     this.m_syntax = syntax;
     this.m_scanner = this.m_syntax.BuildScanner();
     this.m_formatter = formatter;
 }
Пример #31
0
 public HtmlProcessor(ICodeFormatter codeFormatter, IImageProcessor imageProcessor)
 {
     _codeFormatter  = codeFormatter;
     _imageProcessor = imageProcessor;
 }
Пример #32
0
        public void Scan(string input, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(input, "input");

            this.DoScan(new SlidingWindowReader(input), formatter, false);
        }
        /// <summary>
        /// Registers an ICodeFormatter for the given language. The system
        /// is not case sensitive.
        /// </summary>
        /// <param name="formatter">
        /// A non null formatter.
        /// </param>
        /// <param name="language">
        /// A non null file language.
        /// The value must not be empty nor contain '.' and
        /// must not have been already registered.
        /// </param>
        public void Register(ICodeFormatter formatter, string extension)
        {
            UiExceptionHelper.CheckNotNull(formatter, "formatter");
            UiExceptionHelper.CheckNotNull(extension, "language");

            extension = extension.ToLower();

            UiExceptionHelper.CheckTrue(extension.Length > 0,
                "language cannot be empty", "language");
            UiExceptionHelper.CheckTrue(extension.LastIndexOf('.') == -1,
                "language cannot contain '.'", "language");
            UiExceptionHelper.CheckFalse(_toFormatter.ContainsKey(extension),
                "language '" + extension + "' has already an handler. Remove handler first.",
                "language");

            _toFormatter.Add(extension, formatter);

            return;
        }
Пример #34
0
        private void DoScan(SlidingWindowReader reader, ICodeFormatter formatter, bool writeAsynchronously)
        {
            ArgumentValidator.ThrowIfNull(formatter, "formatter");
            this.Reader = reader;

            if (this.m_isFirstRun) {
                this.m_scopeStack = new List<Scope>(8);
                this.m_modes = new List<KeyValuePair<int, HighlightMode>>(64);
                this.m_possibleKeyword = new StringBuilder(this.m_syntaxDefinition.MaxKeywordLength + 1);
                this.m_isFirstRun = false;
            } else {
                this.m_scopeStack.Clear();
                this.m_modes.Clear();
                this.m_possibleKeyword.Length = 0;
            }

            this.m_pendingMatch = new MatchResult();
            this.m_pendingMatch.PosMatchStart = int.MaxValue;
            this.m_posDontMatchUntil = -1;
            this.m_posAfterKeepend = int.MaxValue;

            this.m_scopeStack.Add(Scope.BuildBackgroundScope(this.m_syntaxDefinition.MainContext.TopItems));
            this.BuildHighlightModes();

            this.m_outputWriter = new HighlightedOutputWriter(formatter, writeAsynchronously);
            this.LoadInputWindow(this.Reader.CurrentWindow);
            this.Vrooom();
        }
 private ClassGenerator(ICodeFormatter codeFormatter)
 {
     Initialize();
     this.codeFormatter = codeFormatter;
 }