Exemplo n.º 1
0
        private Dictionary <string, string> prefixNamespaces  = new Dictionary <string, string>(); // prefix to namespace URI

        public ObjectTree(ParserLanguage language, ITextSnapshot snapshot)
        {
            this.language = language;
            this.snapshot = snapshot;

            this.BuildObjectTree();
        }
        public void Execute()
        {
            string newText = syntaxEditor.Text;
            // Determine language by file extension.
            string ext = Path.GetExtension(syntaxEditor.Options.DocumentSaveOptions.CurrentFileName);

            ParserLanguageID lang_ID = ParserLanguage.FromFileExtension(ext);

            if (ext.ToLower() == ".lua")
            {
                lang_ID = ParserLanguageID.Basic;
            }
            else
            // Do not parse HTML or XML.
            if (lang_ID == ParserLanguageID.Html ||
                lang_ID == ParserLanguageID.Xml ||
                lang_ID == ParserLanguageID.None)
            {
                return;
            }
            // Use DevExpress.CodeParser to parse text into tokens.
            ITokenCategoryHelper tokenHelper = TokenCategoryHelperFactory.CreateHelper(lang_ID);
            TokenCollection      highlightTokens;

            highlightTokens = tokenHelper.GetTokens(newText);
            HighlightSyntax(highlightTokens);
        }
        public void Execute()
        {
            string newText = syntaxEditor.Text;
            // Determine the language by file extension.
            string           ext     = System.IO.Path.GetExtension(syntaxEditor.Options.DocumentSaveOptions.CurrentFileName);
            ParserLanguageID lang_ID = ParserLanguage.FromFileExtension(ext);

            // Do not parse HTML or XML.
            if (lang_ID == ParserLanguageID.Html ||
                lang_ID == ParserLanguageID.Xml ||
                lang_ID == ParserLanguageID.None)
            {
                return;
            }
            // Use DevExpress.CodeParser to parse text into tokens.
            ITokenCategoryHelper tokenHelper = TokenCategoryHelperFactory.CreateHelper(lang_ID);

            if (tokenHelper != null)
            {
                TokenCollection highlightTokens = tokenHelper.GetTokens(newText);
                if (highlightTokens != null && highlightTokens.Count > 0)
                {
                    HighlightSyntax(highlightTokens);
                }
            }
        }
Exemplo n.º 4
0
        public void Execute()
        {
            string newText = syntaxEditor.Text;
            // Determine language by file extension.
            ParserLanguageID lang_ID;

            //string ext = System.IO.Path.GetExtension(syntaxEditor.Options.DocumentSaveOptions.CurrentFileName);
            if (_CurrentScript.Language == ScriptLanguage.CSharp)
            {
                lang_ID = ParserLanguage.FromFileExtension(".cs");
            }
            else
            {
                lang_ID = ParserLanguage.FromFileExtension(".vb");
            }

            // Do not parse HTML or XML.
            if (lang_ID == ParserLanguageID.Html ||
                lang_ID == ParserLanguageID.Xml ||
                lang_ID == ParserLanguageID.None)
            {
                return;
            }
            // Use DevExpress.CodeParser to parse text into tokens.
            ITokenCategoryHelper tokenHelper = TokenCategoryHelperFactory.CreateHelper(lang_ID);
            TokenCollection      highlightTokens;

            highlightTokens = tokenHelper.GetTokens(newText);
            HighlightSyntax(highlightTokens);
        }
Exemplo n.º 5
0
        public CompletionSource(CompletionSourceProvider sourceProvider, ITextBuffer textBuffer)
        {
            this.sourceProvider = sourceProvider;
            this.textBuffer     = textBuffer;

            // Determine the file language (rtype or xml)...
            this.language        = textBuffer.ContentType.GetParserLanguage();
            this.prefixSeparator = this.language == ParserLanguage.Xml ? ":" : ".";

            // TODO: can the type-cache be shared (put into the CompletionSourceProvider, perhaps?)
            this.typeCache = new ObjectInstanceTypeCache();
            this.typeCache.AddAssembly(typeof(ParserTokenType).Assembly);
            this.typeCache.PreloadCache();
        }
Exemplo n.º 6
0
        internal Classifier(IClassificationTypeRegistryService registry, ITextBuffer textBuffer)
        {
            this.language = textBuffer.ContentType.GetParserLanguage();

            this.whitespaceType       = registry.GetClassificationType(PredefinedClassificationTypeNames.WhiteSpace);
            this.commentType          = registry.GetClassificationType(TypeConstants.SwixComment);
            this.keywordType          = registry.GetClassificationType(TypeConstants.SwixKeyword);
            this.objectType           = registry.GetClassificationType(TypeConstants.SwixObject);
            this.propertyType         = registry.GetClassificationType(TypeConstants.SwixProperty);
            this.valueType            = registry.GetClassificationType(TypeConstants.SwixValue);
            this.attachableObjectType = registry.GetClassificationType(TypeConstants.SwixAttachableObject);
            this.namespacePrefixType  = registry.GetClassificationType(TypeConstants.SwixNamespacePrefix);
            this.assignmentType       = registry.GetClassificationType(TypeConstants.SwixEquals);
            this.delimiterType        = registry.GetClassificationType(TypeConstants.SwixDelimiter);
        }
 public DiscordMessageOutput(string language = "en-us", int timeZoneOffset = 0)
 {
     Language   = new ParserLanguage(language);
     TimeOffset = timeZoneOffset;
     CultureInfo.CurrentCulture = Language.GetCultureInfo();
 }
        public async Task HandleCommand(SocketMessage pMsg)
        {
            try
            {
                if (pMsg.Source == MessageSource.System && pMsg.Author.Id == bot.CurrentUser.Id)
                {//this is the annoying "x pinned a message to this channel" system message.
                    await pMsg.Channel.DeleteMessagesAsync(new IMessage[] { pMsg });

                    return;
                }
                var message = pMsg as SocketUserMessage;

                if (message == null || message.Author == null || message.Author.IsBot)
                {
                    return;
                }

                if (message.Channel is SocketDMChannel)
                {
                    var lang = new ParserLanguage(Config.DefaultLanguage);

                    if (message.Content == lang.Strings["stop"])
                    {
                        await DirectMessageUser(new DiscordChatUser(message.Author), lang.Strings["dmStart"]);

                        Config.NoDMUsers.Add(message.Author.Id);
                        Config.Save();
                    }
                    else if (message.Content == lang.Strings["start"])
                    {
                        Config.NoDMUsers.RemoveAll(x => x == message.Author.Id);
                        Config.Save();
                        await DirectMessageUser(new DiscordChatUser(message.Author), lang.Strings["dmReStart"]);
                    }
                    else
                    {
                        await DirectMessageUser(new DiscordChatUser(message.Author), lang.Strings["dmResp"] + lang.Strings["dmStop"]);
                    }

                    return;
                }
                if (message.Channel is SocketGuildChannel)
                {
                    var channel = (SocketGuildChannel)message.Channel;
                    var guild   = channel.Guild;


                    var guildConfig = Config.GetServerConfig(guild.Id, ChatTypes.Discord);

                    ISocketMessageChannel outputchannel = null;

                    //get output channel
                    if (guildConfig.OutputChannelId.HasValue)
                    {
                        outputchannel = (ISocketMessageChannel)guild.Channels.FirstOrDefault(x => x.Id == guildConfig.OutputChannelId.Value);
                    }
                    else
                    {
                        outputchannel = (ISocketMessageChannel)guild.Channels.FirstOrDefault(x => x.Name == Config.OutputChannel);
                        if (outputchannel != null)
                        {
                            guildConfig.OutputChannelId = outputchannel.Id;
                            Config.Save();
                        }
                    }

                    var context = new SocketCommandContext(bot, message);

                    //get configured guild language or default "en-us"
                    var lang = guildConfig.Language ?? Config.DefaultLanguage ?? "en-us";
                    //timezone of the bot machine
                    //get configured timezone

                    var parser = GetParser(guildConfig);

                    var doPost = (outputchannel != null ||
                                  guildConfig.PinChannels.Contains(message.Channel.Id)) &&
                                 !guildConfig.MuteChannels.Contains(message.Channel.Id);

                    var argPos = 0;

                    //begin parsing/execution
                    //Someone is issuing a command, respond in their channel
                    if (message.HasStringPrefix(Config.Prefix, ref argPos))
                    {
                        await DoCommand(new DiscordChatMessage(message), parser);
                    }
                    //try to see if a raid was posted
                    else if (doPost)
                    {
                        var post = parser.ParsePost(new DiscordChatMessage(message));
                        await DoPost(post, new DiscordChatMessage(message), parser, outputchannel == null?null : new DiscordChatChannel(outputchannel));
                    }


                    await dbContext.AddOrUpdateGuild(guild, guildConfig.City);

                    await dbContext.AddOrUpdateChannel(channel, guildConfig.ChannelCities.ContainsKey(channel.Id)?guildConfig.ChannelCities[channel.Id] : null);
                }
            }
            catch (Exception e)
            {
                DoError(e);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Parses an xlsx file into a list of key-text tuples. Parses strictly, all conventions have to be kept.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="formatFile">The format file.</param>
        /// <returns></returns>
        public List <Tuple <string, string> > LoadXlsFile(string file, string formatFile, ParserLanguage language)
        {
            var result = new List <Tuple <string, string> >();

            try
            {
                var workbook        = new XLWorkbook(file);
                var formatWorksheet = formatFile != null ? new XLWorkbook(formatFile).Worksheets.Worksheet(1) : null;

                var worksheet = workbook.Worksheets.Worksheet(1);

                foreach (var row in worksheet.Rows().Skip(2)) //Skip license and header
                {
                    var key   = row.Cell(1).GetValue <string>();
                    var value = row.Cell((int)language).GetValue <string>(); //Go to right language column

                    var formatKeyCell = formatWorksheet?.Column(1).CellsUsed(cell => cell.GetValue <string>() == key).FirstOrDefault();
                    if (formatKeyCell != null)
                    {
                        var formatValueCell = formatKeyCell.WorksheetRow().Cell(2);
                        var maxLength       = !string.IsNullOrWhiteSpace(formatValueCell.GetValue <string>()) ? formatValueCell.GetValue <int>() : int.MaxValue;
                        value = value.Length <= maxLength ? value : value.Substring(0, maxLength);
                    }

                    result.Add(new Tuple <string, string>(key, value));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(result);
        }