Esempio n. 1
0
 public void Initialize(KalkEngine engine)
 {
     if (engine == null)
     {
         throw new ArgumentNullException(nameof(engine));
     }
     _units = engine.Units;
 }
Esempio n. 2
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;
        }