コード例 #1
0
ファイル: TestHelper.cs プロジェクト: Blecki/EtcScript
        public static Object CallTestFunction(
			String script,
			Action<EtcScriptLib.Environment> AdditionalSetup = null)
        {
            EtcScriptLib.Compile.Debug = true;
            EtcScriptLib.Compile._DebugWrite = Console.Write;

            Console.WriteLine("Test script: " + script);
            var environment = new EtcScriptLib.Environment();
            environment.AddSystemMacro("fail", (c, a) => { Assert.IsTrue(false); return null; });
            if (AdditionalSetup != null) AdditionalSetup(environment);
            var testFunctions = environment.Build(script, s => { Console.WriteLine(s); return EtcScriptLib.ErrorStrategy.Abort; });
            Assert.IsTrue(testFunctions.Count > 0);
            var context = environment.CreateExecutionContext(EtcScriptLib.VirtualMachine.ExecutionLocation.Empty);
            var func = testFunctions[0].MakeInvokableFunction();
            var argList = new List<Object>();
            argList.Add(func);
            func.Invoke(context, argList);
            EtcScriptLib.VirtualMachine.VirtualMachine.ExecuteUntilFinished(context);
            if (context.ExecutionState == EtcScriptLib.VirtualMachine.ExecutionState.Error)
            {
                Console.WriteLine("Error:" + context.ErrorObject.ToString());
                Assert.IsTrue(false);
            }

            if (context.R == null) Console.WriteLine("NULL");
            else Console.WriteLine(context.R.ToString());
            return context.R;
        }
コード例 #2
0
ファイル: Driver.cs プロジェクト: Blecki/EtcScript
        public void PrepareEnvironment()
        {
            ScriptEnvironment = new EtcScriptLib.Environment();

            ScriptEnvironment.AddSystemMacro("target main", (context, arguments) => { CurrentTarget = WriteTarget.Main; return null; });
            ScriptEnvironment.AddSystemMacro("target bottom", (context, arguments) => { CurrentTarget = WriteTarget.CommandList; return null; });
            ScriptEnvironment.AddSystemMacro("clear", (context, arguments) => { Clear(CurrentTarget); return null; });
            ScriptEnvironment.AddSystemMacro("write (s:string)", (context, arguments) => { Output(arguments[0].ToString(), CurrentTarget); return null; });
        }
コード例 #3
0
ファイル: TestHelper.cs プロジェクト: Blecki/EtcScript
        public static void CompileTestAssertNoErrors(String script)
        {
            EtcScriptLib.Compile.Debug = true;
            EtcScriptLib.Compile._DebugWrite = Console.Write;

            var environment = new EtcScriptLib.Environment();
            Console.WriteLine("Test script: " + script);
            bool wasError = false;
            environment.Build(script,
                (s) => { Console.WriteLine(s); wasError = true; return EtcScriptLib.ErrorStrategy.Continue; });
            Assert.False(wasError);
        }
コード例 #4
0
ファイル: ErrorReport.cs プロジェクト: Blecki/EtcScript
        public static void throws_error(String script)
        {
            bool errorCaught = false;

            Console.WriteLine("Script: " + script);
            var environment = new EtcScriptLib.Environment();
            environment.Build(script, (s) =>
            {
                Console.WriteLine("Error: " + s);
                errorCaught = true;
                return EtcScriptLib.ErrorStrategy.Abort;
            });

            if (!errorCaught)
            {
                Console.WriteLine("No errors.");
                Assert.Fail();
            }
        }
コード例 #5
0
ファイル: PatternMatching.cs プロジェクト: Blecki/EtcScript
 private static List<EtcScriptLib.Ast.Node> ParseInvokation(String script)
 {
     var environment = new EtcScriptLib.Environment();
     var tokenIterator = new EtcScriptLib.TokenStream(new EtcScriptLib.StringIterator(script), environment.Context);
     return EtcScriptLib.Parse.ParseStaticInvokationStatement(tokenIterator, environment.Context);
 }
コード例 #6
0
ファイル: Main.cs プロジェクト: Blecki/EtcScript
        public Main()
        {
            InitializeComponent();

            try
            {
                Settings = Newtonsoft.Json.JsonConvert.DeserializeObject<Settings>(
                    System.IO.File.ReadAllText("default-settings.txt"));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Settings = new EtcScriptEmu.Settings();
            }

            //scintilla1.Styles[0].ForeColor = Color.Black;
            //scintilla1.Styles[1].ForeColor = Color.Red;
            //scintilla1.Styles[2].ForeColor = Color.Green;
            //scintilla1.Styles[3].ForeColor = Color.Blue;
            //scintilla1.Styles[4].ForeColor = Color.Orange;

            StyleMap = new Dictionary<EtcScriptLib.SyntaxLex.TokenStyle, int>();
            StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Basic, 0);
            StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Clause, 4);
            StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.ComplexStringPart, 2);
            StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Error, 1);
            StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Keyword, 3);
            StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Number, 2);
            StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Operator, 4);
            StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.String, 2);

            ScriptEnvironment = new EtcScriptLib.Environment();
            SyntaxLex = new EtcScriptLib.SyntaxLex(ScriptEnvironment.Context, (token, style, fold) =>
                {
                    if (StyleMap.ContainsKey(style))
                        StyleToken(token, StyleMap[style], fold);
                    else
                        StyleToken(token, 0, fold);

                },
                (token) =>
                {
                    var range = new ScintillaNET.Range(token.Location.Index, token.Location.EndIndex, scintilla1);
                    range.StartingLine.IsFoldPoint = true;
                });

            runButton.Enabled = false;

            var defaultHost = Settings.Hosts.Where(hs => hs.DisplayName == Settings.DefaultHost).FirstOrDefault();
            if (defaultHost != null) PrepareHost(System.IO.Path.GetFullPath(defaultHost.Path));

            if (Settings.OpenFiles.Count == 0) OpenNewFile();
            else foreach (var filename in Settings.OpenFiles)
                Open(filename);

            foreach (var host in Settings.Hosts)
            {
                var lCopy = host;
                var button = defaultHosts.DropDownItems.Add(host.DisplayName);
                button.Click += (sender, args) => { PrepareHost(System.IO.Path.GetFullPath(lCopy.Path)); };
            }
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: Blecki/EtcScript
        private void hOSTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            var hadError = false;

            if (ExternalHost == null)
            {
                ScriptEnvironment = new EtcScriptLib.Environment();
                ScriptEnvironment.Build(scintilla1.Text, (error) =>
                {
                    textBox1.Text += error + "\r\n";
                    hadError = true;
                    return EtcScriptLib.ErrorStrategy.Abort;
                });
            }
            else
            {
                if (HostForm != null)
                {
                    HostForm.Dispose();
                    HostForm = null;
                }

                if (CurrentFile.UnsavedNewFile) sAVEASToolStripMenuItem_Click(null, null);
                if (CurrentFile.Changes) sAVEToolStripMenuItem_Click(null, null);

                var hostControl = ExternalHost.Host(ExternalHostFilename, CurrentFile.Filename, (error) =>
                {
                    if (textBox1.InvokeRequired) textBox1.Invoke(
                        new Action(() => { textBox1.Text += error + "\r\n"; }));
                    else
                        textBox1.Text += error + "\r\n";

                    hadError = true;
                },
                    (environment) =>
                    {
                        ScriptEnvironment = environment;
                        if (hadError) this.Invoke(new Action(() => treeView1.Nodes.Clear()));
                        else this.Invoke(new Action(() => BuildCompileTree()));
                    });

                HostForm = new Form();
                hostControl.Dock = DockStyle.Fill;
                HostForm.Controls.Add(hostControl);
                HostForm.ClientSize = ExternalHost.PreferredSize();
                HostForm.Show();
            }
        }