示例#1
0
 internal ScriptSource(ScriptEngine engine, SourceUnit sourceUnit)
 {
     Assert.NotNull(engine, sourceUnit);
     _unit   = sourceUnit;
     _engine = engine;
 }
示例#2
0
 public virtual void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity)
 {
     CountError(severity);
 }
示例#3
0
 public SourceLocation MapLine(SourceLocation location)
 {
     return(SourceUnit.MakeLocation(location));
 }
示例#4
0
        private CompiledCode CompileInternal(CompilerOptions compilerOptions, ErrorListener errorListener)
        {
            ErrorSink  errorSink = new ErrorListenerProxySink(this, errorListener);
            ScriptCode code      = compilerOptions != null?SourceUnit.Compile(compilerOptions, errorSink) : SourceUnit.Compile(errorSink);

            return((code != null) ? new CompiledCode(Engine, code) : null);
        }
示例#5
0
 /// <summary>
 /// Comvenience hosting API.
 /// </summary>
 public ICompiledCode CompileStatements(string statement, IScriptModule module)
 {
     Contract.RequiresNotNull(statement, "statement");
     return(CompileSourceUnit(SourceUnit.CreateSnippet(this, statement, SourceCodeKind.Statements), module));
 }
示例#6
0
 /// <summary>
 /// Executes the source code. The execution is not bound to any particular scope.
 /// </summary>
 public dynamic Execute()
 {
     // The host doesn't need the scope so do not create it here.
     // The language can treat the code as not bound to a DLR scope and change global lookup semantics accordingly.
     return(SourceUnit.Execute());
 }
示例#7
0
 public string GetCodeLine(int line)
 {
     return(SourceUnit.GetCodeLine(line));
 }
示例#8
0
 public void ExecuteSourceUnit(SourceUnit sourceUnit, IScriptModule module)
 {
     Contract.RequiresNotNull(sourceUnit, "sourceUnit");
     CompileSourceUnit(sourceUnit, module).Execute(module);
 }
示例#9
0
 /// <summary>
 /// Detects the encoding of the content.
 /// </summary>
 /// <returns>
 /// An encoding that is used by the reader of the script source to transcode its content to Unicode text.
 /// <c>Null</c> if the content is already textual and no transcoding is performed.
 /// </returns>
 /// <remarks>
 /// Note that the default encoding specified when the script source is created could be overridden by
 /// an encoding that is found in the content preamble (Unicode BOM or a language specific encoding preamble).
 /// In that case the preamble encoding is returned. Otherwise, the default encoding is returned.
 /// </remarks>
 /// <exception cref="IOException">An I/O error occurs.</exception>
 public Encoding DetectEncoding()
 {
     using (var reader = SourceUnit.GetReader()) {
         return(reader.Encoding);
     }
 }
示例#10
0
 /// <summary>
 /// Reads specified range of lines (or less) from the source unit.
 /// </summary>
 /// <param name="start">1-based number of the first line to fetch.</param>
 /// <param name="count">The number of lines to fetch.</param>
 /// <remarks>
 /// Which character sequences are considered line separators is language specific.
 /// If language doesn't specify otherwise "\r", "\n", "\r\n" are recognized line separators.
 /// </remarks>
 /// <exception cref="IOException">An I/O error occurs.</exception>
 public string[] GetCodeLines(int start, int count)
 {
     return(SourceUnit.GetCodeLines(start, count));
 }
示例#11
0
 public SourceCodeReader GetReader()
 {
     return(SourceUnit.GetReader());
 }
示例#12
0
 public ScriptCodeParseResult GetCodeProperties(CompilerOptions options)
 {
     return(SourceUnit.GetCodeProperties(options));
 }
示例#13
0
 public ScriptCodeParseResult GetCodeProperties()
 {
     return(SourceUnit.GetCodeProperties());
 }
示例#14
0
 public object EvaluateSourceUnit(SourceUnit sourceUnit, IScriptModule module)
 {
     Contract.RequiresNotNull(sourceUnit, "sourceUnit");
     return(CompileSourceUnit(sourceUnit, module).Evaluate(module));
 }
示例#15
0
 public string GetCode()
 {
     return(SourceUnit.GetCode());
 }
示例#16
0
 /// <summary>
 /// Execute a snippet of code within the scope of the specified module. Convenience API.
 /// </summary>
 public void Execute(string code, IScriptModule module)
 {
     Contract.RequiresNotNull(code, "code");
     ExecuteSourceUnit(SourceUnit.CreateSnippet(this, code), module);
 }
示例#17
0
        // TODO: can this be removed? no one uses it
        #region line number mapping

        public int MapLine(int line)
        {
            return(SourceUnit.MapLine(line));
        }
示例#18
0
 public ICompiledCode CompileSourceUnit(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
 {
     Contract.RequiresNotNull(sourceUnit, "sourceUnit");
     return(new CompiledCode(_languageContext.CompileSourceCode(sourceUnit, options, errorSink)));
 }
示例#19
0
 public SourceSpan MapLine(SourceSpan span)
 {
     return(new SourceSpan(SourceUnit.MakeLocation(span.Start), SourceUnit.MakeLocation(span.End)));
 }
示例#20
0
 public ICompiledCode CompileInteractiveCode(string code, IScriptModule module)
 {
     Contract.RequiresNotNull(code, "code");
     return(CompileSourceUnit(SourceUnit.CreateSnippet(this, code, SourceCodeKind.InteractiveCode), module));
 }
示例#21
0
        /// <summary>
        /// Executes the code in the specified scope.
        /// Returns an object that is the resulting value of running the code.
        ///
        /// When the ScriptSource is a file or statement, the engine decides what is
        /// an appropriate value to return.  Some languages return the value produced
        /// by the last expression or statement, but languages that are not expression
        /// based may return null.
        /// </summary>
        /// <exception cref="SyntaxErrorException">Code cannot be compiled.</exception>
        public dynamic Execute(ScriptScope scope)
        {
            ContractUtils.RequiresNotNull(scope, nameof(scope));

            return(SourceUnit.Execute(scope.Scope));
        }