Esempio n. 1
0
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity) {
     _source = source;
     _message = message;
     _span = span;
     _errorCode = errorCode;
     //  _severity = severity;
 }
        private ScriptCodeParseResult GetCommandPropertiesAndParse(string code, out ScriptSource source)
        {
            ScriptCodeParseResult result = ScriptCodeParseResult.IncompleteStatement;
            try
            {
                ScriptSource command = this.Engine.CreateScriptSourceFromString(code, SourceCodeKind.InteractiveCode);
                result = command.GetCodeProperties(this.Engine.GetCompilerOptions(this.ScriptScope));
                source = command;

            }
            catch (ParseException error)
            {
                if (error.CanContinue)
                {
                    result = ScriptCodeParseResult.IncompleteStatement;
                }
                else
                {
                    result = ScriptCodeParseResult.Invalid;
                    Console.ErrorOutput.WriteLine("//[parse]: {0}", error.Message);
                }

                source = null;
            }
            //catch (Exception e)
            //{
            //    source = null;
            //    Console.ErrorOutput.WriteLine("**->{0}", e);
            //}


            return result;
        }
 public void ExecutePythonCode(string code)
 {
     pySource = pyEngine.CreateScriptSourceFromString(code,SourceCodeKind.InteractiveCode);
     object output = pySource.Execute(pyScope);
     if (output != null) Console.Echo(pyEngine.Operations.Format(output));
     ShowResults();
 }
Esempio n. 4
0
 public void Init(string player)
 {
     m_scope = m_engine.CreateScope();
     m_scope.SetVariable("player", player);
     m_scope.SetVariable("ClearBox", BoxState.Clear);
     m_scope.SetVariable("XBox", BoxState.X);
     m_scope.SetVariable("OBox", BoxState.O);
     source = m_engine.CreateScriptSourceFromString(System.IO.File.ReadAllText("AI.py"), SourceCodeKind.AutoDetect);
 }
Esempio n. 5
0
        static ShaderCompiler()
        {
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GreenBox3D.ContentPipeline.Graphics.ShaderCompiler.rb");
            StreamReader reader = new StreamReader(stream);

            HelperSource = ScriptManager.Engine.CreateScriptSourceFromString(reader.ReadToEnd(), SourceCodeKind.File);

            reader.Close();
        }
Esempio n. 6
0
 public override void ErrorReported(
     ScriptSource source, string message,
     SourceSpan span, int errorCode,
     Severity severity)
 {
     _writer.WriteLine("Error starting at line {0} column {1}",
                        span.Start.Line, span.Start.Column);
     _writer.WriteLine(message);
 }
Esempio n. 7
0
        public PythonLoader(string code, string className = "PyClass")
        {
            //creating engine and stuff
            engine = Python.CreateEngine();
            scope = engine.CreateScope();

            //loading and compiling code
            source = engine.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements);
            compiled = source.Compile();
        }
Esempio n. 8
0
 /// <summary>
 /// Stores the reported error.
 /// </summary>
 /// <param name="source">The source in which the error occurred.</param>
 /// <param name="message">The error message.</param>
 /// <param name="span">The location of the error in the script file.</param>
 /// <param name="errorCode">The error code.</param>
 /// <param name="severity">The severity of the error.</param>
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity)
 {
     var error = new ScriptErrorInformation
         {
             Line = span.Start.Line,
             Column = span.Start.Column,
             Message = message,
             Severity = Translate(severity),
         };
     m_Errors.Add(error);
 }
Esempio n. 9
0
        public void CompileCodeFromClass(string code, string className)
        {
            //loading and compiling code
            Source = Engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
            _compiled = Source.Compile();

            //now executing this code (the code should contain a class)
            _compiled.Execute(Scope);

            //now creating an object that could be used to access the stuff inside a python script
            _pythonClass = Engine.Operations.Invoke(Scope.GetVariable(className));
        }
Esempio n. 10
0
        public void ProcessCode(string code)
        {
            // check if we're in the revit context
            // if so, add relevant assemblies

            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
            if ( assemblies.Any(x => x.FullName.Contains("RevitAPI")) && assemblies.Any(x => x.FullName.Contains("RevitAPIUI")) )
            {
                code = "import clr\nclr.AddReference('RevitAPI')\nclr.AddReference('RevitAPIUI')\nfrom Autodesk.Revit.DB import *\nimport Autodesk\n" + code;
            }

            this.source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
        }
Esempio n. 11
0
 public clsPyInterface(string codePreRun = "")
 {
     this.pythonVars = new Dictionary<string,object>();
     this.pyEngine = Python.CreateEngine(
     #if DEBUG
         //new Dictionary<string, object>() { {"Debug", true} }
     #endif
     );
     this.pyScope = this.pyEngine.CreateScope();
     this.pySource = this.pyEngine.CreateScriptSourceFromString("raise BaseException('" + pyDefaultError + "')");
     this.pyCodePreRun = codePreRun + "\n";
     this.lastError = "";
 }
Esempio n. 12
0
 public pyDissector(string fileName)
 {
     engine = Python.CreateEngine();
     scope = engine.CreateScope();
     var runtime = engine.Runtime;
     runtime.LoadAssembly(typeof(PacketDotNet.Packet).Assembly);
     runtime.LoadAssembly(typeof(pyDissector).Assembly);
     src = engine.CreateScriptSourceFromFile(fileName);
     program = src.Compile();
     var result = program.Execute(scope);
     var filterString = scope.GetVariable<string>("nativeFilterString");
     myFilter = filterGen.genFilter(filterString);
     parseFunc = scope.GetVariable<Func<Packet, HLPacket>>("parsePacket");
 }
Esempio n. 13
0
        public ReplayReader()
        {
            // Lib should be in SearchPath, but we need to add our own python files as well
            ICollection<string> paths = m_engine.GetSearchPaths();
            paths.Add(m_blizzScriptPath);
            m_engine.SetSearchPaths(paths);

            // create global scope, we only need 1 of those
            m_scope = m_engine.CreateScope();

            // load our API file we're going to communicate with
            m_source = m_engine.CreateScriptSourceFromFile(m_blizzScriptPath + m_replayLibPyFile);
            m_source.Execute(m_scope);
        }
Esempio n. 14
0
        public override void Setup()
        {
            runtime_ = new JavaScriptRuntime(new JavaScriptRuntimeSettings());
            engine_ = runtime_.CreateEngine();

            var baseline = new ScriptSource("test://init.js", @"(function(global) {
            global.buffer = new ArrayBuffer(1024);
            global.typedArray = new Uint8ClampedArray(buffer);
            global.dataView = new DataView(buffer, 1);
            })(this);");
            engine_.Execute(baseline);
            buffer_ = (JavaScriptArrayBuffer)engine_.GetGlobalVariable("buffer");
            typedArray_ = (JavaScriptTypedArray)engine_.GetGlobalVariable("typedArray");
            dataView_ = (JavaScriptDataView)engine_.GetGlobalVariable("dataView");
        }
Esempio n. 15
0
        public void InformationalDisplayOfAllSymbolProperties()
        {
            engine_.RuntimeExceptionRaised += Engine__RuntimeExceptionRaised;
            engine_.SetGlobalFunction("echo", (eng, ctor, thisObj, args) =>
            {
                // Log.Message(string.Format(args.First().ToString(), (object[])args.Skip(1).ToArray()));
                Assert.AreEqual(args.First().ToString(), "length, prototype, name, iterator, species, unscopables, for, keyFor, caller, arguments");
                return eng.UndefinedValue;
            });

            var src = new ScriptSource("[eval code]", @"(function() {
    var x = Object.getOwnPropertyNames(Symbol).join(', ');

    echo(x);
})();");
            engine_.Execute(src);
        }
Esempio n. 16
0
        private void Compile()
        {
            try
            {
                _source = _engine.CreateScriptSourceFromString("import clr" + Environment.NewLine + "clr.AddReference('mtrand')" + Environment.NewLine);
                _source.Execute(_scope);
                _source = _engine.CreateScriptSourceFromString(textBox_CodeIn.Text);

                dynamic res2 = _source.Execute(_scope);
                if (res2 != null)
                    textBox_CodeOut.Text += Environment.NewLine + ">>> " + _builtin.str(res2);
                textBox_CodeOut.SelectionStart = textBox_CodeOut.TextLength;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error compile");
            }
            toolStripStatusLabel.Text = "Compile done";
        }
Esempio n. 17
0
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity) {
     throw new SyntaxErrorException(message, HostingHelpers.GetSourceUnit(source), span, errorCode, severity);
 }
Esempio n. 18
0
        private void RunCommandLine(string []args)
        {
            Debug.Assert(_engine != null);
            string arglist="";
            string python_module="test";
            string python_class="exampleclass";
            for (int i=0;i+1<args.Length;i+=2) {
                if (IsSanitized(args[i+1])) {
                    if (args[i]=="PythonModule") {
                        python_module=args[i+1];
                    }else if (args[i]=="PythonClass") {
                        python_class=args[i+1];
                    }else {
                        _scope.SetVariable(args[i],args[i+1]);
                        if (arglist.Length!=0)
                            arglist+=",";
                        arglist+=args[i]+"="+args[i+1];
                    }
                }
            }
            ScriptSource initsource=_engine.CreateScriptSourceFromString("import sys;sys.path+=[\"../../liboh/scripts/ironpython\",\"../../../liboh/scripts/ironpython\",\"scripts/ironpython\",\"ironpython\",\"../../liboh/scripts/ironpython/site-packages\",\"../../../liboh/scripts/ironpython/site-packages\",\"scripts/ironpython/site-packages\",\"ironpython/site_packages\",\"../lib/scripts/ironpython\",\"../lib/scripts/ironpython/site-packages\"];print sys.path;from "+python_module+" import "+python_class,SourceCodeKind.Statements);

            initsource.Execute(_scope);
            initsource=_engine.CreateScriptSourceFromString(python_class+"("+arglist+")",SourceCodeKind.Expression);
            _pythonObject=initsource.Execute(_scope);
            _scope.SetVariable("retval",_pythonObject);
            _processMessageSource=_engine.CreateScriptSourceFromString("retval.processMessage(header,body)",SourceCodeKind.Expression);
            _processRPCSource=_engine.CreateScriptSourceFromString("retval.processRPC(header,name,args)",SourceCodeKind.Expression);
            _processTickSource=_engine.CreateScriptSourceFromString("retval.tick(curTime)",SourceCodeKind.Expression);
        }
Esempio n. 19
0
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity)
 {
     OnError.Invoke(source,message,span,errorCode,severity);
 }
 public ScriptCommandBase(ScriptSource scriptSource, ScriptScope scriptScope)
 {
     this.source = scriptSource;
     this.scope = scriptScope;
 }
 public ScriptCommand(ScriptSource scriptSource, ScriptScope scriptScope)
     : base(scriptSource, scriptScope)
 {
 }
Esempio n. 22
0
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity)
 {
     Errors.AppendLine(string.Format("{0}:{1} - {2} at Line {3}", new object[] { severity.ToString(), errorCode.ToString(), message, span.Start.Line.ToString() }));
 }
Esempio n. 23
0
 public void SetSource(string code)
 {
     this.pySource = this.pyEngine.CreateScriptSourceFromString(this.pyCodePreRun + code);
 }
Esempio n. 24
0
 public Parser(string Source, ErrorSink errorSink)
 {
     source = Ruby.CreateRuntime().GetEngine("rb").CreateScriptSourceFromString(Source);
     this.errorSink = errorSink;
 }
Esempio n. 25
0
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity)
 {
     Errors.Add(string.Format("{0} (line {1})", message, span.Start.Line));
 }
Esempio n. 26
0
 public void ProcessCode(string code)
 {
     _source = _engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
 }
Esempio n. 27
0
 void scriptSourceInit()
 {
     lock (_scriptLock)
     {
         if (_scriptSource == null)
         {
             _scriptSource = ScriptContext.Current.ScriptRuntime.GetEngine(LanguageId).CreateScriptSourceFromString(Code, SourceCodeKind);
         }
     }
 }
Esempio n. 28
0
 /// <summary>
 /// Adds error to the error list.
 /// </summary>
 /// <param name="_scrpsrcScriptSource">Script.</param>
 /// <param name="_sErrorMsg">Error message.</param>
 /// <param name="_srcspanSpanning">Span.</param>
 /// <param name="_iCode">Code.</param>
 /// <param name="sevSeverity">Severity.</param>
 public override void ErrorReported(ScriptSource _scrpsrcScriptSource, string _sErrorMsg, SourceSpan _srcspanSpanning, int _iCode, Severity sevSeverity)
 {
     Errorlist.Add(_sErrorMsg);
 }
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity)
 {
     if (severity==Severity.Warning)
         c.warnings.Add(new Errors.CommonWarning(message, c.compilerOptions.SourceFileName, span.Start.Line, span.Start.Column));
     else
         c.errorsList.Add(new Errors.CommonCompilerError(message, c.compilerOptions.SourceFileName, span.Start.Line, span.Start.Column));
 }
Esempio n. 30
0
 public void LoadCode(string code)
 {
     Source = Engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
     Source.Compile();
 }