Exemplo n.º 1
0
        public override ToolStripMenuItem[] CreateMenus(IIde ide)
        {
            var menuItems = new List <Tuple <ToolStripMenuItem, Func <bool> > >();

            var ret = Ut.NewArray <ToolStripMenuItem>(
                new ToolStripMenuItem("&Insert", null,
                                      new ToolStripMenuItem("&Word from index", null, (_, __) =>
            {
                var input = InputBox.GetLine("Index to look up?", caption: "Runic");
                if (input == null || !int.TryParse(input, out var ix))
                {
                    return;
                }
                var word = WordDictionary.GetWord(ix);
                if (word == null)
                {
                    DlgMessage.Show($"The specified index is out of range. Valid range is 0–{WordDictionary.List.Length - 1}.", "Runic", DlgType.Error);
                }
                else
                {
                    ide.InsertText(word);
                }
            }),
                                      new ToolStripMenuItem("&Index from word", null, (_, __) =>
            {
                var input = InputBox.GetLine("Word to look up?", caption: "Runic");
                if (input == null)
                {
                    return;
                }
                var index = WordDictionary.GetIndex(input.ToLowerInvariant().Trim());
                if (index == -1)
                {
                    DlgMessage.Show("The specified word is not in the dictionary.", "Runic", DlgType.Error);
                }
                else
                {
                    ide.InsertText(index.ToString());
                }
            })
                                      )
                );

            return(ret);
        }
Exemplo n.º 2
0
        private void insertInteger(IIde ide)
        {
            string @default, selected = ide.GetSelectedText();

            try
            {
                if (selected.Length == 1 && selected[0] >= 0xbc00 && selected[0] <= 0xd7a3)
                {
                    @default = (0xbbff - selected[0]).ToString();
                }
                else
                {
                    @default = new BigInteger(new byte[] { 0 }.Concat(ScliptingUtil.DecodeByteArray(selected)).Reverse().ToArray()).ToString();
                }
            }
            catch { @default = "0"; }
            var line = InputBox.GetLine("Type an integer to insert (must be greater than −7077):", @default, "Esoteric IDE", "&OK", "&Cancel");

            if (line != null)
            {
                BigInteger i;
                if (BigInteger.TryParse(line, out i) && (i >= -7076))
                {
                    if (i < 0)
                    {
                        ide.InsertText(((char)(0xbbff - i)).ToString());
                    }
                    else
                    {
                        ide.InsertText(ScliptingUtil.EncodeByteArray(i.ToByteArray().Reverse().SkipWhile(b => b == 0).DefaultIfEmpty().ToArray()));
                    }
                }
                else
                {
                    DlgMessage.Show("The integer you typed is not a valid literal integer for Sclipting. Literal integers must be greater than −7077.", "Esoteric IDE", DlgType.Error, "&OK");
                }
            }
        }
Exemplo n.º 3
0
        private void insertByteArray(IIde ide)
        {
            string @default, selected = ide.GetSelectedText();

            try { @default = ScliptingUtil.DecodeByteArray(selected).ToHex(); }
            catch { @default = ""; }
            var line = InputBox.GetLine("Type a byte array to insert (in hexdump format; two hexadecimal digits per byte):", @default, "Esoteric IDE", "&OK", "&Cancel");

            if (line != null)
            {
                try { ide.InsertText(ScliptingUtil.EncodeByteArray(line.FromHex())); }
                catch { DlgMessage.Show("The text you entered is not valid hexadecimal. Please ensure that you enter an even number of characters 0-9/a-f.", "Esoteric IDE", DlgType.Error, "&OK"); }
            }
        }
Exemplo n.º 4
0
        private void insertString(IIde ide)
        {
            string @default, selected = ide.GetSelectedText();

            try
            {
                if (selected.Length == 1 && selected[0] >= 0xbc00 && selected[0] <= 0xd7a3)
                {
                    @default = (0xbbff - selected[0]).ToString();
                }
                else
                {
                    @default = ScliptingUtil.DecodeByteArray(selected).FromUtf8().CLiteralEscape();
                }
            }
            catch { @default = "\\n"; }
            var line = InputBox.GetLine("Type a string to insert (in C-escaped format; backslashes must be escaped):", @default, "Esoteric IDE", "&OK", "&Cancel");

            if (line != null)
            {
                try { ide.InsertText(ScliptingUtil.EncodeByteArray(line.CLiteralUnescape().ToUtf8())); }
                catch { DlgMessage.Show("The string you typed is not a valid C-escaped string. Please ensure that your backslashes are escaped.", "Esoteric IDE", DlgType.Error, "&OK"); }
            }
        }
Exemplo n.º 5
0
 private static ToolStripItem stackOrRegexMenuItem(char ch, int num, IIde ide)
 {
     return(new ToolStripMenuItem("{0} — &{1}".Fmt(ch, num), null, (_, __) => { ide.InsertText(ch.ToString()); }));
 }
Exemplo n.º 6
0
 public static ToolStripItem[] GetMenuItems(IIde ide)
 {
     return typeof(ListStringInstruction).GetFields(BindingFlags.Static | BindingFlags.Public)
         .Select((field, fi) =>
         {
             var item = new ToolStripMenuItem(field.GetCustomAttributes<ListStringInstructionAttribute>().First().MenuLabel);
             item.DropDownItems.AddRange(Enumerable.Range(0, 20)
                 .Select(i => new { Ch = Characters[fi * 20 + i], Engrish = Engrish[fi * 20 + i] })
                 .Select(inf => new ToolStripMenuItem("{0} &{1} — {2}".Fmt(inf.Ch, inf.Engrish, new ListStringElementNode(inf.Ch, 0).Explain()), null, (_, __) => { ide.InsertText(inf.Ch.ToString()); }))
                 .ToArray());
             return item;
         })
         .ToArray();
 }
Exemplo n.º 7
0
        public override ToolStripMenuItem[] CreateMenus(IIde ide)
        {
            var mnuInsert      = new ToolStripMenuItem("&Insert");
            var groupMenuItems = typeof(InstructionGroup).GetFields(BindingFlags.Public | BindingFlags.Static)
                                 .ToDictionary(f => (InstructionGroup)f.GetValue(null), f => new ToolStripMenuItem(f.GetCustomAttributes <InstructionGroupAttribute>().First().Label));

            // Stack manipulation instructions
            var miInsertStackInstructionCopyFromBottom = new ToolStripMenuItem("&Copy from bottom");
            var miInsertStackInstructionMoveFromBottom = new ToolStripMenuItem("&Move from bottom");
            var miInsertStackInstructionSwapFromBottom = new ToolStripMenuItem("&Swap from bottom");
            var miInsertStackInstructionCopyFromTop    = new ToolStripMenuItem("C&opy from top");
            var miInsertStackInstructionMoveFromTop    = new ToolStripMenuItem("Mo&ve from top");
            var miInsertRegexGroupInstruction          = new ToolStripMenuItem("Rege&x captured group");

            var miInsertInteger   = new ToolStripMenuItem("&Integer...");
            var miInsertString    = new ToolStripMenuItem("&String...");
            var miInsertByteArray = new ToolStripMenuItem("Byte &array...");

            miInsertInteger.Click   += (_, __) => { insertInteger(ide); };
            miInsertString.Click    += (_, __) => { insertString(ide); };
            miInsertByteArray.Click += (_, __) => { insertByteArray(ide); };

            mnuInsert.DropDownItems.AddRange(groupMenuItems.Values.ToArray());
            mnuInsert.DropDownItems.AddRange(new ToolStripItem[] { miInsertInteger, miInsertString, miInsertByteArray });

            foreach (var instr in typeof(Instruction).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                var attr = instr.GetCustomAttributes <InstructionAttribute>().First();
                var ch   = attr.Character;
                groupMenuItems[attr.Group].DropDownItems.Add(new ToolStripMenuItem(
                                                                 "{0} &{1} — {2}{3}".Fmt(ch, attr.Engrish, attr.Description, attr.Type == NodeType.BlockHead ? " █" : ""),
                                                                 null, (_, __) => { ide.InsertText(ch.ToString()); }
                                                                 ));
            }

            groupMenuItems[InstructionGroup.StackManipulation].DropDownItems.Add("-");
            groupMenuItems[InstructionGroup.StackManipulation].DropDownItems.AddRange(Ut.NewArray <ToolStripItem>(
                                                                                          miInsertStackInstructionCopyFromBottom, miInsertStackInstructionMoveFromBottom, miInsertStackInstructionSwapFromBottom,
                                                                                          miInsertStackInstructionCopyFromTop, miInsertStackInstructionMoveFromTop));

            groupMenuItems[InstructionGroup.ListStringManipulation].DropDownItems.Add("-");
            groupMenuItems[InstructionGroup.ListStringManipulation].DropDownItems.AddRange(ListStringElementNode.GetMenuItems(ide));

            for (var ch = '①'; ch <= '⑳'; ch++)
            {
                miInsertStackInstructionCopyFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '①' + 1, ide));
            }
            for (var ch = '㉑'; ch <= '㉟'; ch++)
            {
                miInsertStackInstructionCopyFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '㉑' + 21, ide));
            }
            for (var ch = '㊱'; ch <= '㊿'; ch++)
            {
                miInsertStackInstructionCopyFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '㊱' + 36, ide));
            }
            for (var ch = '⓵'; ch <= '⓾'; ch++)
            {
                miInsertStackInstructionMoveFromTop.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '⓵' + 1, ide));
            }
            for (var ch = '❶'; ch <= '❿'; ch++)
            {
                miInsertStackInstructionCopyFromTop.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '❶' + 1, ide));
            }
            for (var ch = '⓫'; ch <= '⓴'; ch++)
            {
                miInsertStackInstructionCopyFromTop.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '⓫' + 11, ide));
            }
            for (var ch = '⑴'; ch <= '⒇'; ch++)
            {
                miInsertStackInstructionMoveFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '⑴' + 1, ide));
            }
            for (var ch = '⒈'; ch <= '⒛'; ch++)
            {
                miInsertStackInstructionSwapFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '⒈' + 1, ide));
            }

            groupMenuItems[InstructionGroup.StringManipulation].DropDownItems.Add("-");
            groupMenuItems[InstructionGroup.StringManipulation].DropDownItems.Add(miInsertRegexGroupInstruction);
            for (var ch = 'Ⓐ'; ch <= 'Ⓩ'; ch++)
            {
                miInsertRegexGroupInstruction.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - 'Ⓐ' + 1, ide));
            }

            return(Ut.NewArray <ToolStripMenuItem>(mnuInsert));
        }
Exemplo n.º 8
0
        public override ToolStripMenuItem[] CreateMenus(IIde ide)
        {
            var mnuInsert = new ToolStripMenuItem("&Insert");
            var groupMenuItems = typeof(InstructionGroup).GetFields(BindingFlags.Public | BindingFlags.Static)
                .ToDictionary(f => (InstructionGroup) f.GetValue(null), f => new ToolStripMenuItem(f.GetCustomAttributes<InstructionGroupAttribute>().First().Label));

            // Stack manipulation instructions
            var miInsertStackInstructionCopyFromBottom = new ToolStripMenuItem("&Copy from bottom");
            var miInsertStackInstructionMoveFromBottom = new ToolStripMenuItem("&Move from bottom");
            var miInsertStackInstructionSwapFromBottom = new ToolStripMenuItem("&Swap from bottom");
            var miInsertStackInstructionCopyFromTop = new ToolStripMenuItem("C&opy from top");
            var miInsertStackInstructionMoveFromTop = new ToolStripMenuItem("Mo&ve from top");
            var miInsertRegexGroupInstruction = new ToolStripMenuItem("Rege&x captured group");

            var miInsertInteger = new ToolStripMenuItem("&Integer...");
            var miInsertString = new ToolStripMenuItem("&String...");
            var miInsertByteArray = new ToolStripMenuItem("Byte &array...");

            miInsertInteger.Click += (_, __) => { insertInteger(ide); };
            miInsertString.Click += (_, __) => { insertString(ide); };
            miInsertByteArray.Click += (_, __) => { insertByteArray(ide); };

            mnuInsert.DropDownItems.AddRange(groupMenuItems.Values.ToArray());
            mnuInsert.DropDownItems.AddRange(new ToolStripItem[] { miInsertInteger, miInsertString, miInsertByteArray });

            foreach (var instr in typeof(Instruction).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                var attr = instr.GetCustomAttributes<InstructionAttribute>().First();
                var ch = attr.Character;
                groupMenuItems[attr.Group].DropDownItems.Add(new ToolStripMenuItem(
                    "{0} &{1} — {2}{3}".Fmt(ch, attr.Engrish, attr.Description, attr.Type == NodeType.BlockHead ? " █" : ""),
                    null, (_, __) => { ide.InsertText(ch.ToString()); }
                ));
            }

            groupMenuItems[InstructionGroup.StackManipulation].DropDownItems.Add("-");
            groupMenuItems[InstructionGroup.StackManipulation].DropDownItems.AddRange(Ut.NewArray<ToolStripItem>(
                miInsertStackInstructionCopyFromBottom, miInsertStackInstructionMoveFromBottom, miInsertStackInstructionSwapFromBottom,
                miInsertStackInstructionCopyFromTop, miInsertStackInstructionMoveFromTop));

            groupMenuItems[InstructionGroup.ListStringManipulation].DropDownItems.Add("-");
            groupMenuItems[InstructionGroup.ListStringManipulation].DropDownItems.AddRange(ListStringElementNode.GetMenuItems(ide));

            for (var ch = '①'; ch <= '⑳'; ch++)
                miInsertStackInstructionCopyFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '①' + 1, ide));
            for (var ch = '㉑'; ch <= '㉟'; ch++)
                miInsertStackInstructionCopyFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '㉑' + 21, ide));
            for (var ch = '㊱'; ch <= '㊿'; ch++)
                miInsertStackInstructionCopyFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '㊱' + 36, ide));
            for (var ch = '⓵'; ch <= '⓾'; ch++)
                miInsertStackInstructionMoveFromTop.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '⓵' + 1, ide));
            for (var ch = '❶'; ch <= '❿'; ch++)
                miInsertStackInstructionCopyFromTop.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '❶' + 1, ide));
            for (var ch = '⓫'; ch <= '⓴'; ch++)
                miInsertStackInstructionCopyFromTop.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '⓫' + 11, ide));
            for (var ch = '⑴'; ch <= '⒇'; ch++)
                miInsertStackInstructionMoveFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '⑴' + 1, ide));
            for (var ch = '⒈'; ch <= '⒛'; ch++)
                miInsertStackInstructionSwapFromBottom.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - '⒈' + 1, ide));

            groupMenuItems[InstructionGroup.StringManipulation].DropDownItems.Add("-");
            groupMenuItems[InstructionGroup.StringManipulation].DropDownItems.Add(miInsertRegexGroupInstruction);
            for (var ch = 'Ⓐ'; ch <= 'Ⓩ'; ch++)
                miInsertRegexGroupInstruction.DropDownItems.Add(stackOrRegexMenuItem(ch, ch - 'Ⓐ' + 1, ide));

            return Ut.NewArray<ToolStripMenuItem>(mnuInsert);
        }
Exemplo n.º 9
0
 private void insertString(IIde ide)
 {
     string @default, selected = ide.GetSelectedText();
     try
     {
         if (selected.Length == 1 && selected[0] >= 0xbc00 && selected[0] <= 0xd7a3)
             @default = (0xbbff - selected[0]).ToString();
         else
             @default = ScliptingUtil.DecodeByteArray(selected).FromUtf8().CLiteralEscape();
     }
     catch { @default = "\\n"; }
     var line = InputBox.GetLine("Type a string to insert (in C-escaped format; backslashes must be escaped):", @default, "Esoteric IDE", "&OK", "&Cancel");
     if (line != null)
         try { ide.InsertText(ScliptingUtil.EncodeByteArray(line.CLiteralUnescape().ToUtf8())); }
         catch { DlgMessage.Show("The string you typed is not a valid C-escaped string. Please ensure that your backslashes are escaped.", "Esoteric IDE", DlgType.Error, "&OK"); }
 }
Exemplo n.º 10
0
 private void insertInteger(IIde ide)
 {
     string @default, selected = ide.GetSelectedText();
     try
     {
         if (selected.Length == 1 && selected[0] >= 0xbc00 && selected[0] <= 0xd7a3)
             @default = (0xbbff - selected[0]).ToString();
         else
             @default = new BigInteger(new byte[] { 0 }.Concat(ScliptingUtil.DecodeByteArray(selected)).Reverse().ToArray()).ToString();
     }
     catch { @default = "0"; }
     var line = InputBox.GetLine("Type an integer to insert (must be greater than −7077):", @default, "Esoteric IDE", "&OK", "&Cancel");
     if (line != null)
     {
         BigInteger i;
         if (BigInteger.TryParse(line, out i) && (i >= -7076))
         {
             if (i < 0)
                 ide.InsertText(((char) (0xbbff - i)).ToString());
             else
                 ide.InsertText(ScliptingUtil.EncodeByteArray(i.ToByteArray().Reverse().SkipWhile(b => b == 0).DefaultIfEmpty().ToArray()));
         }
         else
             DlgMessage.Show("The integer you typed is not a valid literal integer for Sclipting. Literal integers must be greater than −7077.", "Esoteric IDE", DlgType.Error, "&OK");
     }
 }
Exemplo n.º 11
0
 private void insertByteArray(IIde ide)
 {
     string @default, selected = ide.GetSelectedText();
     try { @default = ScliptingUtil.DecodeByteArray(selected).ToHex(); }
     catch { @default = ""; }
     var line = InputBox.GetLine("Type a byte array to insert (in hexdump format; two hexadecimal digits per byte):", @default, "Esoteric IDE", "&OK", "&Cancel");
     if (line != null)
         try { ide.InsertText(ScliptingUtil.EncodeByteArray(line.FromHex())); }
         catch { DlgMessage.Show("The text you entered is not valid hexadecimal. Please ensure that you enter an even number of characters 0-9/a-f.", "Esoteric IDE", DlgType.Error, "&OK"); }
 }
Exemplo n.º 12
0
 private static ToolStripItem stackOrRegexMenuItem(char ch, int num, IIde ide)
 {
     return new ToolStripMenuItem("{0} — &{1}".Fmt(ch, num), null, (_, __) => { ide.InsertText(ch.ToString()); });
 }