Пример #1
0
        public void SetSymbolShortcut(KalkShortcut shortcut)
        {
            if (shortcut == null)
            {
                throw new ArgumentNullException(nameof(shortcut));
            }
            RemoveShortcut(shortcut.Name);
            Add(shortcut.Name, shortcut);

            foreach (KalkShortcutKeySequence shortcutKey in shortcut.Keys)
            {
                var            map        = ShortcutKeyMap;
                KalkConsoleKey consoleKey = default;
                for (int i = 0; i < shortcutKey.Keys.Count; i++)
                {
                    if (i > 0)
                    {
                        if (!map.TryGetShortcut(consoleKey, out var newMap) || !(newMap is KalkShortcutKeyMap))
                        {
                            newMap          = new KalkShortcutKeyMap();
                            map[consoleKey] = newMap;
                        }
                        map = (KalkShortcutKeyMap)newMap;
                    }
                    consoleKey = shortcutKey.Keys[i];
                }

                map[consoleKey] = shortcutKey.Expression;
            }
        }
Пример #2
0
        private void CleanupMap(KalkShortcutKeyMap map)
        {
            var keyParis = map.ToList();

            foreach (var keyPair in keyParis)
            {
                if (keyPair.Value is KalkShortcutKeyMap nestedMap)
                {
                    CleanupMap(nestedMap);
                    if (nestedMap.Count == 0)
                    {
                        map.Remove(keyPair.Key);
                    }
                }
            }
        }
Пример #3
0
        public KalkEngine() : base(new KalkObjectWithAlias())
        {
            KalkSettings.Initialize();
            KalkEngineFolder = AppContext.BaseDirectory;

            // Enforce UTF8 encoding
            Console.OutputEncoding = Encoding.UTF8;
            EnableEngineOutput     = true;
            EchoEnabled            = true;
            DisplayVersion         = true;
            CurrentDisplay         = KalkDisplayMode.Standard;
            KalkUserFolder         = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify), ".kalk");

            HighlightOutput             = new ConsoleText();
            InputReader                 = Console.In;
            OutputWriter                = Console.Out;
            ErrorWriter                 = Console.Error;
            IsOutputSupportHighlighting = ConsoleHelper.SupportEscapeSequences;

            // Fetch version
            var assemblyInfoVersion = (AssemblyInformationalVersionAttribute)typeof(KalkEngine).Assembly.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute));

            Version = assemblyInfoVersion.InformationalVersion;

            Builtins = BuiltinObject;
            ((KalkObjectWithAlias)Builtins).Engine = this;

            Units     = new KalkUnits(this);
            Shortcuts = new KalkShortcuts();
            Aliases   = new KalkAliases();
            _currentShortcutKeyMap  = Shortcuts.ShortcutKeyMap;
            _completionMatchingList = new List <string>();
            Config      = new KalkConfig();
            Variables   = new ScriptVariables(this);
            Descriptors = new Dictionary <string, KalkDescriptor>();
            EnableRelaxedMemberAccess = false;
            _modules      = new Dictionary <Type, KalkModule>();
            TryConverters = new List <TryToObjectDelegate>();
            ErrorForStatementFunctionAsExpression = true;
            StrictVariables = true;
            UseScientific   = true;
            LoopLimit       = int.MaxValue; // no limits for loops
            RecursiveLimit  = int.MaxValue; // no limits (still guarded by Scriban)

            // Setup default clipboard methods
            _localClipboard  = string.Empty;
            GetClipboardText = GetClipboardTextImpl;
            SetClipboardText = SetClipboardTextImpl;

            _cancellationTokenSource = new CancellationTokenSource();

            PushGlobal(Units);
            PushGlobal(Variables);

            _parserOptions = new ParserOptions();

            _lexerOptions = new LexerOptions()
            {
                KeepTrivia = true,
                Mode       = ScriptMode.ScriptOnly,
                Lang       = ScriptLang.Scientific
            };
            _lexerInterpolatedOptions = new LexerOptions()
            {
                KeepTrivia = true,
                Mode       = ScriptMode.Default,
                Lang       = ScriptLang.Scientific
            };
            _tempOutputHighlight = new ConsoleText();

            // Init last result with 0
            _lastResult = 0;

            HistoryList = new List <string>();

            _isInitializing = true;
            RegisterFunctions();
            _isInitializing = false;
        }
Пример #4
0
 public KalkShortcuts()
 {
     ShortcutKeyMap = new KalkShortcutKeyMap();
 }