/// <summary> /// Colorizes source code using the specified language, formatter, and style sheet. /// </summary> /// <param name="sourceCode">The source code to colorize.</param> /// <param name="language">The language to use to colorize the source code.</param> /// <param name="formatter">The formatter to use to colorize the source code.</param> /// <param name="styleSheet">The style sheet to use to colorize the source code.</param> public void Colorize(string sourceCode, ILanguage language, IFormatter formatter, IStyleSheet styleSheet) { Guard.ArgNotNull(language, "language"); Guard.ArgNotNull(formatter, "formatter"); Guard.ArgNotNull(styleSheet, "styleSheet"); languageParser.Parse(sourceCode, language, (parsedSourceCode, captures) => formatter.Write(parsedSourceCode, captures, styleSheet)); }
/// <summary> /// Manually add a combat log message by string. /// </summary> /// <param name="msg">Combat log message to parse and add.</param> public void AddMessage(string m) { ChatMessage msg = ChatMessage.Parse(m); // Is it even a chat message? if (msg != null) { // If so, which one is it? msg = parser.Parse(msg); Helper.RaiseEventOnUIThread(OnChatMessage, new object[] { this, msg }); HandleMeters(msg); chatlog.Add(msg); } }
public void Configure() { model.AddLanguages(parser.Parse(_xmlString)); }
public override Language?Detect(string sourceCode, Language[] languages = null) { List <Language> langs = (languages ?? LanguageExt.Languages).ToList(); // Any PHP file contains start tag. if (!sourceCode.Contains("<?")) { langs.Remove(Language.Php); } // Aspx and html code contains at least one tag. if (!openTagRegex.IsMatch(sourceCode) || !closeTagRegex.IsMatch(sourceCode)) { langs.Remove(Language.Aspx); langs.Remove(Language.Html); } var sourceCodeFile = new SourceCodeFile("Temp Source Code") { Code = sourceCode }; var parseUnits = new Queue <Tuple <Language, ParserUnit> >(langs.Count); langs = langs .GroupBy(l => ParserConverterBuilder.GetParserConverterSet(l).Parser.Language) .Select(l => l.First()) .ToList(); if (langs.Count == 1) { return(langs[0]); } foreach (var language in langs) { var logger = new LoggerMessageCounter(); ILanguageParser languageParser = ParserConverterBuilder.GetParserConverterSet(language).Parser; var task = Task.Factory.StartNew(() => { languageParser.Logger = logger; languageParser.Parse(sourceCodeFile); }); parseUnits.Enqueue(Tuple.Create(language, new ParserUnit(languageParser, logger, task))); } int minErrorCount = int.MaxValue; Language?resultWithMinErrors = null; // Check every parseUnit completion every 50 ms. while (parseUnits.Count > 0) { var pair = parseUnits.Dequeue(); if (!pair.Item2.Task.IsCompleted) { parseUnits.Enqueue(pair); Thread.Sleep(50); continue; } if (pair.Item2.Logger.ErrorCount == 0 && pair.Item1 != Language.Aspx) { return(pair.Item1); } var errorCount = pair.Item2.ParseErrorCount; if (errorCount < minErrorCount) { minErrorCount = errorCount; resultWithMinErrors = pair.Item1; } } return(resultWithMinErrors); }
public void Parse(CodeFile codeFile) { ParseTree = parser.Parse(codeFile); }